From 30b54552d77fcdfe5e98c0c52283a6c1dea3c73c Mon Sep 17 00:00:00 2001 From: Shweta Date: Tue, 6 Jun 2023 16:07:04 +0000 Subject: [PATCH] reverting the changes to SDK --- embedded/Makefile | 55 +- embedded/README.md | 8 +- embedded/client/source/nearby_fp_client.c | 417 ++---- embedded/client/source/nearby_fp_client.h | 14 +- embedded/client/tests/gLinux/audio.cc | 1 - embedded/client/tests/gLinux/battery.cc | 71 +- embedded/client/tests/gLinux/ble.cc | 48 - embedded/client/tests/gLinux/fakes.h | 41 +- embedded/client/tests/gLinux/os.cc | 133 +- embedded/client/tests/gLinux/persistence.cc | 11 - embedded/client/tests/gLinux/se.cc | 27 +- embedded/client/tests/smoke_test.cc | 671 +-------- embedded/client/tests/spot_test.cc | 1311 ----------------- embedded/common/source/mbedtls/mbedtls.c | 20 - embedded/common/source/micro-ecc/Makefile | 6 - embedded/common/source/micro-ecc/micro-ecc.c | 69 - embedded/common/source/nearby_config.h | 64 +- embedded/common/source/nearby_event.h | 30 - embedded/common/source/nearby_fp_library.c | 30 +- embedded/common/source/nearby_fp_library.h | 4 +- embedded/common/source/nearby_utils.c | 10 +- embedded/common/source/nearby_utils.h | 7 +- embedded/common/target/nearby.h | 2 +- .../common/target/nearby_platform_battery.h | 37 +- embedded/common/target/nearby_platform_ble.h | 30 +- embedded/common/target/nearby_platform_os.h | 84 +- .../target/nearby_platform_persistence.h | 10 +- embedded/common/target/nearby_platform_se.h | 23 - embedded/release_notes.md | 26 +- embedded/target/gLinux/config.mk | 40 +- embedded/target/gLinux/rules.mk | 28 - 31 files changed, 206 insertions(+), 3122 deletions(-) delete mode 100644 embedded/client/tests/spot_test.cc delete mode 100644 embedded/common/source/micro-ecc/Makefile delete mode 100644 embedded/common/source/micro-ecc/micro-ecc.c diff --git a/embedded/Makefile b/embedded/Makefile index b79f1710..4f25308d 100644 --- a/embedded/Makefile +++ b/embedded/Makefile @@ -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) diff --git a/embedded/README.md b/embedded/README.md index 682a6790..55c7ec2f 100644 --- a/embedded/README.md +++ b/embedded/README.md @@ -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. \ No newline at end of file diff --git a/embedded/client/source/nearby_fp_client.c b/embedded/client/source/nearby_fp_client.c index 29628285..0ee80dbb 100644 --- a/embedded/client/source/nearby_fp_client.c +++ b/embedded/client/source/nearby_fp_client.c @@ -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; } diff --git a/embedded/client/source/nearby_fp_client.h b/embedded/client/source/nearby_fp_client.h index 36ffc683..a51fd7b2 100644 --- a/embedded/client/source/nearby_fp_client.h +++ b/embedded/client/source/nearby_fp_client.h @@ -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); diff --git a/embedded/client/tests/gLinux/audio.cc b/embedded/client/tests/gLinux/audio.cc index 10e58ef3..947d5a08 100644 --- a/embedded/client/tests/gLinux/audio.cc +++ b/embedded/client/tests/gLinux/audio.cc @@ -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 diff --git a/embedded/client/tests/gLinux/battery.cc b/embedded/client/tests/gLinux/battery.cc index 3991f7db..685c8cd9 100644 --- a/embedded/client/tests/gLinux/battery.cc +++ b/embedded/client/tests/gLinux/battery.cc @@ -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; diff --git a/embedded/client/tests/gLinux/ble.cc b/embedded/client/tests/gLinux/ble.cc index 4a38575e..68e0eef6 100644 --- a/embedded/client/tests/gLinux/ble.cc +++ b/embedded/client/tests/gLinux/ble.cc @@ -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> notifications; static std::vector advertisement; static nearby_fp_AvertisementInterval interval; -static std::vector 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(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& nearby_test_fakes_GetAdvertisement() { return advertisement; } -std::vector& 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); diff --git a/embedded/client/tests/gLinux/fakes.h b/embedded/client/tests/gLinux/fakes.h index 9675f0bc..3d1a15b0 100644 --- a/embedded/client/tests/gLinux/fakes.h +++ b/embedded/client/tests/gLinux/fakes.h @@ -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& value); std::vector 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& nearby_test_fakes_GetAdvertisement(); -std::vector& nearby_test_fakes_GetSpotAdvertisement(); -uint64_t nearby_test_fakes_GetSpotAddress(); std::map>& 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 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& 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 */ diff --git a/embedded/client/tests/gLinux/os.cc b/embedded/client/tests/gLinux/os.cc index 98d7b68f..40d21899 100644 --- a/embedded/client/tests/gLinux/os.cc +++ b/embedded/client/tests/gLinux/os.cc @@ -12,40 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include #include -#include -#include -#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 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(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(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::max(); - std::for_each( - timers.begin(), timers.end(), - [&timer_trigger_time](std::pair 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::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 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; -} \ No newline at end of file diff --git a/embedded/client/tests/gLinux/persistence.cc b/embedded/client/tests/gLinux/persistence.cc index a16da309..6dccc62c 100644 --- a/embedded/client/tests/gLinux/persistence.cc +++ b/embedded/client/tests/gLinux/persistence.cc @@ -17,7 +17,6 @@ #include #include "fakes.h" -#include "nearby.h" #include "nearby_platform_persistence.h" static std::map> 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; diff --git a/embedded/client/tests/gLinux/se.cc b/embedded/client/tests/gLinux/se.cc index 67c536cd..a10d66b0 100644 --- a/embedded/client/tests/gLinux/se.cc +++ b/embedded/client/tests/gLinux/se.cc @@ -26,11 +26,7 @@ #include #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(); return kNearbyStatusOK; -} \ No newline at end of file +} diff --git a/embedded/client/tests/smoke_test.cc b/embedded/client/tests/smoke_test.cc index 1c135351..7fccda72 100644 --- a/embedded/client/tests/smoke_test.cc +++ b/embedded/client/tests/smoke_test.cc @@ -29,9 +29,7 @@ #include "nearby_fp_library.h" #include "nearby_platform_audio.h" #include "nearby_platform_ble.h" -#include "nearby_platform_bt.h" #include "nearby_platform_persistence.h" -#include "nearby_spot.h" #include "nearby_utils.h" #pragma GCC diagnostic push @@ -478,7 +476,7 @@ TEST(NearbyFpClient, AdvertisementNondiscoverable_oneKey_twoByteSalt) { ASSERT_THAT(std::vector(buffer, buffer + kBufferSize), ElementsAreArray(kExpectedResult)); } -#endif /* (NEARBY_FP_SALT_SIZE == 2) */ +#endif TEST(NearbyFpClient, AdvertisementNondiscoverable_twoKeys) { uint8_t salt = 0xC7; @@ -669,9 +667,7 @@ TEST(NearbyFpClient, ASSERT_THAT(nearby_test_fakes_GetAdvertisement(), ElementsAreArray(kExpectedResult, kBufferSize)); } -#endif /* NEARBY_FP_ENABLE_BATTERY_NOTIFICATION */ -#if NEARBY_FP_ENABLE_BATTERY_NOTIFICATION TEST( NearbyFpClient, SetAdvertisementWithBatteryNotification_AdvertisementNoPairingUIWithBatteryUI) { @@ -702,30 +698,11 @@ TEST( ASSERT_THAT(nearby_test_fakes_GetAdvertisement(), ElementsAreArray(kExpectedResult, kBufferSize)); } -#endif /* NEARBY_FP_ENABLE_BATTERY_NOTIFICATION */ -#if NEARBY_FP_ENABLE_BATTERY_NOTIFICATION TEST( NearbyFpClient, SetAdvertisementWithBatteryNotification_Charging_AdvertisementContainsBatteryInfo) { uint8_t salt = 0xC7; - uint8_t account_key1[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, - 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}; - uint8_t account_key2[] = {0x11, 0x11, 0x22, 0x22, 0x33, 0x33, 0x44, 0x44, - 0x55, 0x55, 0x66, 0x66, 0x77, 0x77, 0x88, 0x88}; - uint8_t account_key3[] = {0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73, - 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3}; - uint8_t account_key4[] = {0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74, - 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4}; - uint8_t account_key5[] = {0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75, - 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5}; - std::vector account_keys{ - AccountKeyPair(kRemoteDevice, account_key1), - AccountKeyPair(kRemoteDevice, account_key2), - AccountKeyPair(kRemoteDevice, account_key3), - AccountKeyPair(kRemoteDevice, account_key4), - AccountKeyPair(kRemoteDevice, account_key5), - }; const uint8_t kExpectedResult1[] = {0x14, 0x16, 0x2c, 0xfe, 0x00, 0x90, 0x30, 0xa6, 0x17, 0x10, 0x0c, 0x6c, 0xa9, 0xea, 0xf7, 0x11, salt, 0x33, @@ -740,7 +717,7 @@ TEST( : sizeof(kExpectedResult2); nearby_fp_client_Init(NULL); nearby_test_fakes_SetAntiSpoofingKey(kBobPrivateKey, kBobPublicKey); - nearby_test_fakes_SetAccountKeys(account_keys); + Set5AccountKeys(); nearby_test_fakes_SetRandomNumber(salt); nearby_fp_LoadAccountKeys(); nearby_test_fakes_SetIsCharging(true); @@ -754,30 +731,11 @@ TEST( ASSERT_THAT(nearby_test_fakes_GetAdvertisement(), ElementsAreArray(kExpectedResult, kBufferSize)); } -#endif /* NEARBY_FP_ENABLE_BATTERY_NOTIFICATION */ -#if NEARBY_FP_ENABLE_BATTERY_NOTIFICATION TEST( NearbyFpClient, SetAdvertisementWithBatteryNotification_NotCharging_AdvertisementContainsBatteryInfo) { uint8_t salt = 0xC7; - uint8_t account_key1[] = {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, - 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}; - uint8_t account_key2[] = {0x11, 0x11, 0x22, 0x22, 0x33, 0x33, 0x44, 0x44, - 0x55, 0x55, 0x66, 0x66, 0x77, 0x77, 0x88, 0x88}; - uint8_t account_key3[] = {0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73, - 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3}; - uint8_t account_key4[] = {0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74, - 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4}; - uint8_t account_key5[] = {0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75, - 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5}; - std::vector account_keys{ - AccountKeyPair(kRemoteDevice, account_key1), - AccountKeyPair(kRemoteDevice, account_key2), - AccountKeyPair(kRemoteDevice, account_key3), - AccountKeyPair(kRemoteDevice, account_key4), - AccountKeyPair(kRemoteDevice, account_key5), - }; const uint8_t kExpectedResult1[] = {0x14, 0x16, 0x2c, 0xfe, 0x00, 0x90, 0x46, 0x84, 0x1e, 0x84, 0x2e, 0x27, 0x05, 0x92, 0xcc, 0x11, salt, 0x33, @@ -792,7 +750,7 @@ TEST( : sizeof(kExpectedResult2); nearby_fp_client_Init(NULL); nearby_test_fakes_SetAntiSpoofingKey(kBobPrivateKey, kBobPublicKey); - nearby_test_fakes_SetAccountKeys(account_keys); + Set5AccountKeys(); nearby_test_fakes_SetRandomNumber(salt); nearby_fp_LoadAccountKeys(); nearby_test_fakes_SetIsCharging(false); @@ -806,9 +764,7 @@ TEST( ASSERT_THAT(nearby_test_fakes_GetAdvertisement(), ElementsAreArray(kExpectedResult, kBufferSize)); } -#endif /* NEARBY_FP_ENABLE_BATTERY_NOTIFICATION */ -#if NEARBY_FP_ENABLE_BATTERY_NOTIFICATION TEST( NearbyFpClient, SetAdvertisementWithBatteryNotification_GetBatteryInfoFails_AdvertismentIsValid) { @@ -839,9 +795,7 @@ TEST( ASSERT_THAT(nearby_test_fakes_GetAdvertisement(), ElementsAreArray(kExpectedResult, kBufferSize)); } -#endif /* NEARBY_FP_ENABLE_BATTERY_NOTIFICATION */ -#if NEARBY_FP_ENABLE_BATTERY_NOTIFICATION #if NEARBY_FP_MESSAGE_STREAM TEST(NearbyFpClient, RfcommConnected_HasBatteryInfo_SendsModelIdBleAddressAndBatteryInfo) { @@ -851,26 +805,18 @@ TEST(NearbyFpClient, 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ // Battery level - 3, 3, 0, 3, 0xd5, 0xd0, 0xda -#if NEARBY_BATTERY_REMAINING_TIME + 3, 3, 0, 3, 0xd5, 0xd0, 0xda, // Battery remaining time - ,3, 4, 0, 1, 100 -#endif /* NEARBY_BATTERY_REMAINING_TIME */ - // Firmware Revision - ,3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', - }; + 3, 4, 0, 1, 100}; nearby_fp_client_Init(&kClientCallbacks); Pair(0x40); message_stream_events.clear(); -#if NEARBY_BATTERY_REMAINING_TIME nearby_test_fakes_BatteryTime(100); -#endif /* NEARBY_BATTERY_REMAINING_TIME */ nearby_test_fakes_GetRfcommOutput(kPeerAddress).clear(); + nearby_test_fakes_SetIsCharging(true); nearby_test_fakes_SetGetBatteryInfoResult(kNearbyStatusOK); nearby_test_fakes_MessageStreamConnected(kPeerAddress); @@ -882,11 +828,7 @@ TEST(NearbyFpClient, kExpectedRfcommOutput, ElementsAreArray(nearby_test_fakes_GetRfcommOutput(kPeerAddress))); } -#endif /* NEARBY_FP_MESSAGE_STREAM */ -#endif /* NEARBY_FP_ENABLE_BATTERY_NOTIFICATION */ -#if NEARBY_FP_ENABLE_BATTERY_NOTIFICATION -#if NEARBY_FP_MESSAGE_STREAM TEST(NearbyFpClient, EnableSilenceMode_RfcommConnected) { constexpr uint64_t kPeerAddress = 0x123456; constexpr uint8_t kExpectedRfcommOutput[] = { @@ -894,26 +836,18 @@ TEST(NearbyFpClient, EnableSilenceMode_RfcommConnected) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ // Battery level 3, 3, 0, 3, 0xd5, 0xd0, 0xda, -#if NEARBY_BATTERY_REMAINING_TIME // Battery remaining time 3, 4, 0, 1, 100, -#endif /* NEARBY_BATTERY_REMAINING_TIME */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Enable silence mode 1, 1, 0, 0}; nearby_fp_client_Init(&kClientCallbacks); Pair(0x40); message_stream_events.clear(); -#if NEARBY_BATTERY_REMAINING_TIME nearby_test_fakes_BatteryTime(100); -#endif /* NEARBY_BATTERY_REMAINING_TIME */ nearby_test_fakes_GetRfcommOutput(kPeerAddress).clear(); nearby_test_fakes_MessageStreamConnected(kPeerAddress); @@ -923,11 +857,7 @@ TEST(NearbyFpClient, EnableSilenceMode_RfcommConnected) { kExpectedRfcommOutput, ElementsAreArray(nearby_test_fakes_GetRfcommOutput(kPeerAddress))); } -#endif /* NEARBY_FP_MESSAGE_STREAM */ -#endif /* NEARBY_FP_ENABLE_BATTERY_NOTIFICATION */ -#if NEARBY_FP_ENABLE_BATTERY_NOTIFICATION -#if NEARBY_FP_MESSAGE_STREAM TEST(NearbyFpClient, DisableSilenceMode_RfcommConnected) { constexpr uint64_t kPeerAddress = 0x123456; constexpr uint8_t kExpectedRfcommOutput[] = { @@ -935,26 +865,18 @@ TEST(NearbyFpClient, DisableSilenceMode_RfcommConnected) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ // Battery level 3, 3, 0, 3, 0xd5, 0xd0, 0xda, -#if NEARBY_BATTERY_REMAINING_TIME // Battery remaining time 3, 4, 0, 1, 100, -#endif /* NEARBY_BATTERY_REMAINING_TIME */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Disable silence mode 1, 2, 0, 0}; nearby_fp_client_Init(&kClientCallbacks); Pair(0x40); message_stream_events.clear(); -#if NEARBY_BATTERY_REMAINING_TIME nearby_test_fakes_BatteryTime(100); -#endif /* NEARBY_BATTERY_REMAINING_TIME */ nearby_test_fakes_GetRfcommOutput(kPeerAddress).clear(); nearby_test_fakes_MessageStreamConnected(kPeerAddress); @@ -964,11 +886,7 @@ TEST(NearbyFpClient, DisableSilenceMode_RfcommConnected) { kExpectedRfcommOutput, ElementsAreArray(nearby_test_fakes_GetRfcommOutput(kPeerAddress))); } -#endif /* NEARBY_FP_MESSAGE_STREAM */ -#endif /* NEARBY_FP_ENABLE_BATTERY_NOTIFICATION */ -#if NEARBY_FP_ENABLE_BATTERY_NOTIFICATION -#if NEARBY_FP_MESSAGE_STREAM TEST(NearbyFpClient, BatteryLevelLongForm_RfcommConnected) { constexpr uint64_t kPeerAddress = 0x123456; constexpr uint8_t kExpectedRfcommOutput[] = { @@ -976,26 +894,18 @@ TEST(NearbyFpClient, BatteryLevelLongForm_RfcommConnected) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ // Battery level 3, 3, 0, 3, 0xd5, 0xd0, 0xda, -#if NEARBY_BATTERY_REMAINING_TIME // Battery remaining time (256) 3, 4, 0, 2, 1, 0, -#endif - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Disable silence mode 1, 2, 0, 0}; nearby_fp_client_Init(&kClientCallbacks); Pair(0x40); message_stream_events.clear(); -#if NEARBY_BATTERY_REMAINING_TIME nearby_test_fakes_BatteryTime(0x100); -#endif /* NEARBY_BATTERY_REMAINING_TIME */ nearby_test_fakes_GetRfcommOutput(kPeerAddress).clear(); nearby_test_fakes_MessageStreamConnected(kPeerAddress); @@ -1030,26 +940,18 @@ TEST(NearbyFpClient, SignalLogBufferFull_RfcommConnected) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ // Battery level 3, 3, 0, 3, 0xd5, 0xd0, 0xda, -#if NEARBY_BATTERY_REMAINING_TIME // Battery remaining time 3, 4, 0, 1, 100, -#endif /* NEARBY_BATTERY_REMAINING_TIME */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Signal log buffer full 2, 1, 0, 0}; nearby_fp_client_Init(&kClientCallbacks); Pair(0x40); message_stream_events.clear(); -#if NEARBY_BATTERY_REMAINING_TIME nearby_test_fakes_BatteryTime(100); -#endif /* NEARBY_BATTERY_REMAINING_TIME */ nearby_test_fakes_GetRfcommOutput(kPeerAddress).clear(); nearby_test_fakes_MessageStreamConnected(kPeerAddress); @@ -1059,11 +961,7 @@ TEST(NearbyFpClient, SignalLogBufferFull_RfcommConnected) { kExpectedRfcommOutput, ElementsAreArray(nearby_test_fakes_GetRfcommOutput(kPeerAddress))); } -#endif /* NEARBY_FP_MESSAGE_STREAM */ -#endif /* NEARBY_FP_ENABLE_BATTERY_NOTIFICATION */ -#if NEARBY_FP_ENABLE_BATTERY_NOTIFICATION -#if NEARBY_FP_MESSAGE_STREAM TEST(NearbyFpClient, ReceiveActiveComponentsRequest_SendsActiveComponentResponse) { constexpr uint64_t kPeerAddress = 0x123456; @@ -1080,26 +978,18 @@ TEST(NearbyFpClient, 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ // Battery level 3, 3, 0, 3, 0xd5, 0xd0, 0xda, -#if NEARBY_BATTERY_REMAINING_TIME // Battery remaining time 3, 4, 0, 1, 100, -#endif /* NEARBY_BATTERY_REMAINING_TIME */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Active component response 3, 6, 0, 1, 0x00}; nearby_fp_client_Init(&kClientCallbacks); Pair(0x40); message_stream_events.clear(); -#if NEARBY_BATTERY_REMAINING_TIME nearby_test_fakes_BatteryTime(100); -#endif /* NEARBY_BATTERY_REMAINING_TIME */ nearby_test_fakes_GetRfcommOutput(kPeerAddress).clear(); nearby_test_fakes_MessageStreamConnected(kPeerAddress); @@ -1207,42 +1097,6 @@ TEST(NearbyFpClient, ReceiveRingRequest) { } #endif /* NEARBY_FP_MESSAGE_STREAM */ -#if NEARBY_FP_MESSAGE_STREAM -#if NEARBY_FP_ENABLE_SPOT -TEST(NearbyFpClient, EddystoneCapabilitySync) { - constexpr uint8_t kPeerMessage[4] = {0x06, 0x01, 0x00, 0x00}; - constexpr uint64_t kPeerAddress = 0x123456; - const nearby_event_MessageStreamReceived kExpectedMessage = { - .peer_address = kPeerAddress, - .message_group = kPeerMessage[0], - .message_code = kPeerMessage[1], - .length = kPeerMessage[2] * 256 + kPeerMessage[3], - .data = NULL}; - constexpr uint8_t kExpectedRfcommOutput[] = {0x06, 0x03, 0x00, 0x07, - // provisioning state - 0x00, - // ble address - 0x6B, 0xAB, 0xAB, 0xAB, 0xAB, - 0xAB}; - - nearby_fp_client_Init(&kClientCallbacks); - Pair(0x40); - message_stream_events.clear(); - - nearby_test_fakes_MessageStreamConnected(kPeerAddress); - - nearby_test_fakes_GetRfcommOutput(kPeerAddress).clear(); - nearby_test_fakes_MessageStreamReceived(kPeerAddress, kPeerMessage, 4); - - ASSERT_EQ(MessageStreamReceivedEvent(&kExpectedMessage), - *message_stream_events[1]); - - ASSERT_THAT(kExpectedRfcommOutput, - ElementsAreArray(nearby_test_fakes_GetRfcommOutput(kPeerAddress))); -} -#endif /* NEARBY_FP_ENABLE_SPOT*/ -#endif /* NEARBY_FP_MESSAGE_STREAM */ - TEST(NearbyFpClient, Pairing_ProviderInitiated) { uint8_t salt = 0xAB; @@ -1942,7 +1796,6 @@ TEST(NearbyFpClient, HkdfExpandSha256NoInfo) { ASSERT_THAT(okm, ElementsAreArray(kExpectedOkm)); } -#if NEARBY_FP_ENABLE_ADDITIONAL_DATA TEST(NearbyFpClient, HmacSha256) { const uint8_t kData[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xEE, 0x4A, 0x24, 0x83, 0x73, 0x80, 0x52, 0xE4, 0x4E, 0x9B, @@ -1961,9 +1814,7 @@ TEST(NearbyFpClient, HmacSha256) { ASSERT_THAT(result, ElementsAreArray(kExpectedResult)); } -#endif /* NEARBY_FP_ENABLE_ADDITIONAL_DATA */ -#if NEARBY_FP_ENABLE_ADDITIONAL_DATA TEST(NearbyFpClient, AesCtr) { uint8_t message[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xEE, 0x4A, 0x24, 0x83, 0x73, 0x80, 0x52, 0xE4, 0x4E, 0x9B, @@ -1980,7 +1831,6 @@ TEST(NearbyFpClient, AesCtr) { ASSERT_THAT(message, ElementsAreArray(kExpectedResult)); } -#endif /* NEARBY_FP_ENABLE_ADDITIONAL_DATA */ #if NEARBY_FP_ENABLE_ADDITIONAL_DATA TEST(NearbyFpClient, DecodeAdditionalData) { @@ -2002,9 +1852,7 @@ TEST(NearbyFpClient, DecodeAdditionalData) { ASSERT_THAT(message, ElementsAreArray(kExpectedResult)); } -#endif /* NEARBY_FP_ENABLE_ADDITIONAL_DATA */ -#if NEARBY_FP_ENABLE_ADDITIONAL_DATA TEST(NearbyFpClient, EncodeAdditionalData) { uint8_t message[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x53, 0x6F, @@ -2026,9 +1874,7 @@ TEST(NearbyFpClient, EncodeAdditionalData) { ASSERT_THAT(message, ElementsAreArray(kExpectedResult)); } -#endif /* NEARBY_FP_ENABLE_ADDITIONAL_DATA */ -#if NEARBY_FP_ENABLE_ADDITIONAL_DATA TEST(NearbyFpClient, PairAndGetPersonalizedName) { uint8_t name[] = {0x53, 0x6F, 0x6D, 0x65, 0x6F, 0x6E, 0x65, 0x27, 0x73, 0x20, 0x47, 0x6F, 0x6F, 0x67, 0x6C, 0x65, 0x20, 0x48, @@ -2050,9 +1896,7 @@ TEST(NearbyFpClient, PairAndGetPersonalizedName) { additional_data.end()), ElementsAreArray(name)); } -#endif /* NEARBY_FP_ENABLE_ADDITIONAL_DATA */ -#if NEARBY_FP_ENABLE_ADDITIONAL_DATA TEST(NearbyFpClient, PairAndSetPersonalizedName) { uint8_t name[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x53, 0x6F, @@ -2108,14 +1952,8 @@ TEST(NearbyFpClient, RfcommConnected_NoBatteryInfo_SendsModelIdAndBleAddress) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce - 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0' - }; - + 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt}; nearby_fp_client_Init(&kClientCallbacks); Pair(0x40); message_stream_events.clear(); @@ -2130,10 +1968,8 @@ TEST(NearbyFpClient, RfcommConnected_NoBatteryInfo_SendsModelIdAndBleAddress) { kExpectedRfcommOutput, ElementsAreArray(nearby_test_fakes_GetRfcommOutput(kPeerAddress))); } -#endif /* NEARBY_FP_MESSAGE_STREAM */ #if NEARBY_FP_RETROACTIVE_PAIRING -#if NEARBY_FP_MESSAGE_STREAM TEST(NearbyFpClient, RetroactivePair) { nearby_fp_client_Init(NULL); constexpr uint64_t kPeerAddress = 0xB0B1B2B3B4B5; @@ -2193,11 +2029,7 @@ TEST(NearbyFpClient, RetroactivePair) { kSeekerAccountKey + sizeof(kExpectedAesKey)), keys.GetKey(0)); } -#endif /* NEARBY_FP_MESSAGE_STREAM */ -#endif /* NEARBY_FP_RETROACTIVE_PAIRING */ -#if NEARBY_FP_RETROACTIVE_PAIRING -#if NEARBY_FP_MESSAGE_STREAM TEST(NearbyFpClient, RetroactivePairAfterInitialPair) { constexpr uint64_t kPeerAddress = 0xB0B1B2B3B4B5; uint8_t salt = 0xAB; @@ -2339,11 +2171,7 @@ TEST(NearbyFpClient, RetroactivePairAfterInitialPair) { kSeekerAccountKey + sizeof(kExpectedAesKey)), keys.GetKey(0)); } -#endif /* NEARBY_FP_MESSAGE_STREAM */ -#endif /* NEARBY_FP_RETROACTIVE_PAIRING */ -#if NEARBY_FP_RETROACTIVE_PAIRING -#if NEARBY_FP_MESSAGE_STREAM TEST(NearbyFpClient, RetroactivePairTwice) { nearby_fp_client_Init(NULL); constexpr uint64_t kPeerAddress = 0xB0B1B2B3B4B5; @@ -2443,11 +2271,7 @@ TEST(NearbyFpClient, RetroactivePairTwice) { kSeekerAccountKey + sizeof(kExpectedAesKey)), keys.GetKey(0)); } -#endif /* NEARBY_FP_MESSAGE_STREAM */ -#endif /* NEARBY_FP_RETROACTIVE_PAIRING */ -#if NEARBY_FP_RETROACTIVE_PAIRING -#if NEARBY_FP_MESSAGE_STREAM TEST(NearbyFpClient, RetroactivePairWrongBtAddress) { nearby_fp_client_Init(NULL); constexpr uint64_t kPeerAddress = 0xB0B1B2B3B4B5; @@ -2502,10 +2326,8 @@ TEST(NearbyFpClient, RetroactivePairWrongBtAddress) { auto keys = nearby_test_fakes_GetAccountKeys(); ASSERT_EQ(0, keys.size()); } -#endif /* NEARBY_FP_MESSAGE_STREAM */ #endif /* NEARBY_FP_RETROACTIVE_PAIRING */ -#if NEARBY_FP_MESSAGE_STREAM TEST(NearbyFpClient, RfcommConnected_ClientDisconnects_EmitsDisconnectEvent) { constexpr uint64_t kPeerAddress = 0x123456; nearby_fp_client_Init(&kClientCallbacks); @@ -2522,9 +2344,7 @@ TEST(NearbyFpClient, RfcommConnected_ClientDisconnects_EmitsDisconnectEvent) { ASSERT_EQ(MessageStreamDisconnectedEvent(kPeerAddress), *message_stream_events[1]); } -#endif /* NEARBY_FP_MESSAGE_STREAM */ -#if NEARBY_FP_MESSAGE_STREAM TEST(NearbyFpClient, RfcommConnected_PeerSendsMessage_PassMessageToClientApp) { constexpr uint64_t kPeerAddress = 0x123456; constexpr uint8_t kPeerMessage[] = {101, 102, 0, 4, 81, 82, 83, 84}; @@ -2550,9 +2370,7 @@ TEST(NearbyFpClient, RfcommConnected_PeerSendsMessage_PassMessageToClientApp) { ASSERT_EQ(MessageStreamReceivedEvent(&kExpectedMessage), *message_stream_events[1]); } -#endif /* NEARBY_FP_MESSAGE_STREAM */ -#if NEARBY_FP_MESSAGE_STREAM TEST(NearbyFpClient, RfcommConnected_ConnectAndDisconnect_CanHandleManySessions) { constexpr uint64_t kPeerAddress = 0x123456; @@ -2583,9 +2401,7 @@ TEST(NearbyFpClient, ASSERT_EQ(MessageStreamReceivedEvent(&kExpectedMessage), *message_stream_events[events - 1]); } -#endif /* NEARBY_FP_MESSAGE_STREAM */ -#if NEARBY_FP_MESSAGE_STREAM #if NEARBY_MAX_RFCOMM_CONNECTIONS > 1 TEST(NearbyFpClient, RfcommConnected_TwoInterleavedConnections_ParsesMessages) { constexpr uint64_t kPeerAddress1 = 0x123456; @@ -2638,9 +2454,7 @@ TEST(NearbyFpClient, RfcommConnected_TwoInterleavedConnections_ParsesMessages) { *message_stream_events[3]); } #endif /* NEARBY_MAX_RFCOMM_CONNECTIONS > 1 */ -#endif /* NEARBY_FP_MESSAGE_STREAM */ -#if NEARBY_FP_MESSAGE_STREAM TEST(NearbyFpClient, SendMessageStreamMessage) { constexpr uint64_t kPeerAddress = 0x123456; constexpr nearby_message_stream_Message kMessage{ @@ -2656,9 +2470,7 @@ TEST(NearbyFpClient, SendMessageStreamMessage) { kExpectedRfcommOutput, ElementsAreArray(nearby_test_fakes_GetRfcommOutput(kPeerAddress))); } -#endif /* NEARBY_FP_MESSAGE_STREAM */ -#if NEARBY_FP_MESSAGE_STREAM TEST(NearbyFpClient, SendAck) { constexpr uint64_t kPeerAddress = 0x123456; constexpr nearby_event_MessageStreamReceived kMessage{ @@ -2675,9 +2487,7 @@ TEST(NearbyFpClient, SendAck) { kExpectedRfcommOutput, ElementsAreArray(nearby_test_fakes_GetRfcommOutput(kPeerAddress))); } -#endif /* NEARBY_FP_MESSAGE_STREAM */ -#if NEARBY_FP_MESSAGE_STREAM TEST(NearbyFpClient, SendNack) { constexpr uint64_t kPeerAddress = 0x123456; constexpr uint8_t kFailReason = 30; @@ -2696,6 +2506,7 @@ TEST(NearbyFpClient, SendNack) { kExpectedRfcommOutput, ElementsAreArray(nearby_test_fakes_GetRfcommOutput(kPeerAddress))); } + #endif /* NEARBY_FP_MESSAGE_STREAM */ TEST(NearbyFpClient, TimerTriggered_RotatesBleAddress) { @@ -2793,242 +2604,6 @@ TEST(NearbyFpClient, ChangeAdvertisementFlags_DoesntRotateBleAddress) { ASSERT_EQ(firstAddress, nearby_platform_GetBleAddress()); } -#if NEARBY_FP_ENABLE_SPOT -TEST(NearbyFpClient, Init_DeviceNotPaired_NoSpotAdvertisement) { - nearby_fp_client_Init(&kClientCallbacks); - - ASSERT_TRUE(nearby_test_fakes_GetSpotAdvertisement().empty()); -} -#endif /* NEARBY_FP_ENABLE_SPOT */ - -#if NEARBY_FP_ENABLE_SPOT -TEST(NearbyFpClient, Init_DevicePaired_HasOwnerKey) { - uint8_t result[sizeof(kSeekerAccountKey)]; - size_t length = sizeof(result); - nearby_fp_client_Init(&kClientCallbacks); - - Pair(0x40); - - ASSERT_EQ(kNearbyStatusOK, - nearby_platform_LoadValue(kStoredKeyOwnerKey, result, &length)); - ASSERT_THAT(result, - ElementsAreArray(kSeekerAccountKey, - kSeekerAccountKey + sizeof(kSeekerAccountKey))); -} -#endif /* NEARBY_FP_ENABLE_SPOT */ - -#if NEARBY_FP_ENABLE_SPOT -TEST(NearbyFpClient, ReadBeaconAction) { - uint8_t result[9]; - size_t length = sizeof(result); - nearby_fp_client_Init(&kClientCallbacks); - Pair(0x40); - - ASSERT_EQ(kNearbyStatusOK, - nearby_test_fakes_GattRead(kBeaconActions, result, &length)); - - ASSERT_EQ(sizeof(result), length); -} -#endif /* NEARBY_FP_ENABLE_SPOT */ - -#if NEARBY_FP_ENABLE_SPOT -TEST(NearbyFpClient, WriteBeaconAction) { - // This request is invalid. That's OK. We are testing only if the request was - // passed through to SPOT handler - uint8_t request[9] = {0}; - nearby_fp_client_Init(&kClientCallbacks); - Pair(0x40); - - ASSERT_EQ(0x80, nearby_test_fakes_GattWrite(kBeaconActions, request, - sizeof(request))); -} -#endif /* NEARBY_FP_ENABLE_SPOT */ - -#if NEARBY_FP_ENABLE_SPOT -TEST(NearbyFpClient, - SetSpotAdvertisement_DevicePairedHasEik_SetsSpotAdvertisement) { - // computed with kSeekerKey and 8 * [0xAB] nonce - constexpr uint8_t kSetEikRequest[] = { - 0x02, 40, 0x27, 0x45, 0xdb, 0x83, 0x04, 0xc1, 0x1d, 0xc0, 0x3a, - 0x7c, 0x70, 0x23, 0x9a, 0x52, 0xdc, 0x99, 0x86, 0x11, 0x7c, 0xa8, - 0x62, 0xd8, 0x92, 0x04, 0x3a, 0x7c, 0x70, 0x23, 0x9a, 0x52, 0xdc, - 0x99, 0x86, 0x11, 0x7c, 0xa8, 0x62, 0xd8, 0x92, 0x04}; - constexpr uint8_t kSpotAdvertisement[] = { - 0x02, 0x01, 0x06, 0x18, 0x16, 0xaa, 0xfe, 0x40, 0xd8, 0xa0, - 0x1e, 0x3a, 0xb9, 0x73, 0x4a, 0x1c, 0x22, 0xea, 0x1e, 0xac, - 0x5c, 0x48, 0xfc, 0x7c, 0x6e, 0xf9, 0xd6, 0x3f}; - uint8_t BeaconAction[9]; - size_t length = sizeof(BeaconAction); - nearby_fp_client_Init(&kClientCallbacks); - nearby_test_fakes_SetGetBatteryInfoResult(kNearbyStatusUnimplemented); - - Pair(0x40); - - ASSERT_EQ(kNearbyStatusOK, - nearby_test_fakes_GattRead(kBeaconActions, BeaconAction, &length)); - ASSERT_EQ(kNearbyStatusOK, - nearby_test_fakes_GattWrite(kBeaconActions, kSetEikRequest, - sizeof(kSetEikRequest))); - ASSERT_EQ(kNearbyStatusOK, - nearby_fp_client_SetAdvertisement(NEARBY_FP_ADVERTISEMENT_SPOT)); - - ASSERT_THAT(kSpotAdvertisement, - ElementsAreArray(nearby_test_fakes_GetSpotAdvertisement())); -} -#endif /* NEARBY_FP_ENABLE_SPOT */ - -#if NEARBY_FP_ENABLE_SPOT -TEST(NearbyFpClient, ClearSpotAdvertisement) { - // computed with kSeekerKey and 8 * [0xAB] nonce - constexpr uint8_t kSetEikRequest[] = { - 0x02, 40, 0x27, 0x45, 0xdb, 0x83, 0x04, 0xc1, 0x1d, 0xc0, 0x3a, - 0x7c, 0x70, 0x23, 0x9a, 0x52, 0xdc, 0x99, 0x86, 0x11, 0x7c, 0xa8, - 0x62, 0xd8, 0x92, 0x04, 0x3a, 0x7c, 0x70, 0x23, 0x9a, 0x52, 0xdc, - 0x99, 0x86, 0x11, 0x7c, 0xa8, 0x62, 0xd8, 0x92, 0x04}; - uint8_t BeaconAction[9]; - size_t length = sizeof(BeaconAction); - nearby_fp_client_Init(&kClientCallbacks); - Pair(0x40); - nearby_test_fakes_GattRead(kBeaconActions, BeaconAction, &length); - nearby_test_fakes_GattWrite(kBeaconActions, kSetEikRequest, - sizeof(kSetEikRequest)); - nearby_fp_client_SetAdvertisement(NEARBY_FP_ADVERTISEMENT_SPOT); - ASSERT_NE(0, nearby_test_fakes_GetSpotAdvertisement().size()); - - ASSERT_EQ(kNearbyStatusOK, - nearby_fp_client_SetAdvertisement(NEARBY_FP_ADVERTISEMENT_NONE)); - - ASSERT_EQ(0, nearby_test_fakes_GetSpotAdvertisement().size()); -} -#endif /* NEARBY_FP_ENABLE_SPOT */ - -#if NEARBY_FP_ENABLE_SPOT -TEST(NearbyFpClient, SetSpotAdvertisementFailsWhenNotProvisioned) { - nearby_fp_client_Init(&kClientCallbacks); - Pair(0x40); - - ASSERT_NE(kNearbyStatusOK, - nearby_fp_client_SetAdvertisement(NEARBY_FP_ADVERTISEMENT_SPOT)); -} -#endif /* NEARBY_FP_ENABLE_SPOT */ - -#if NEARBY_FP_ENABLE_SPOT -TEST(NearbyFpClient, - SetSpotAndFastAdvertisementWhenNotProvisionedStartsFastPairOnly) { - nearby_fp_client_Init(&kClientCallbacks); - Pair(0x40); - - ASSERT_EQ(kNearbyStatusOK, nearby_fp_client_SetAdvertisement( - NEARBY_FP_ADVERTISEMENT_SPOT | - NEARBY_FP_ADVERTISEMENT_DISCOVERABLE)); - - ASSERT_THAT(nearby_test_fakes_GetAdvertisement(), - ElementsAreArray(kDiscoverableAdvertisement)); -} -#endif /* NEARBY_FP_ENABLE_SPOT */ - -#if NEARBY_FP_ENABLE_SPOT -TEST(NearbyFpClient, SetSpotAndFastAdvertisementThenProvisionAdvertisesBoth) { - // computed with kSeekerKey and 8 * [0xAB] nonce - constexpr uint8_t kSetEikRequest[] = { - 0x02, 40, 0x27, 0x45, 0xdb, 0x83, 0x04, 0xc1, 0x1d, 0xc0, 0x3a, - 0x7c, 0x70, 0x23, 0x9a, 0x52, 0xdc, 0x99, 0x86, 0x11, 0x7c, 0xa8, - 0x62, 0xd8, 0x92, 0x04, 0x3a, 0x7c, 0x70, 0x23, 0x9a, 0x52, 0xdc, - 0x99, 0x86, 0x11, 0x7c, 0xa8, 0x62, 0xd8, 0x92, 0x04}; - constexpr uint8_t kSpotAdvertisement[] = { - 0x02, 0x01, 0x06, 0x18, 0x16, 0xaa, 0xfe, 0x40, 0xd8, 0xa0, - 0x1e, 0x3a, 0xb9, 0x73, 0x4a, 0x1c, 0x22, 0xea, 0x1e, 0xac, - 0x5c, 0x48, 0xfc, 0x7c, 0x6e, 0xf9, 0xd6, 0x3f}; - uint8_t BeaconAction[9]; - size_t length = sizeof(BeaconAction); - nearby_fp_client_Init(&kClientCallbacks); - nearby_test_fakes_SetGetBatteryInfoResult(kNearbyStatusUnimplemented); - Pair(0x40); - ASSERT_EQ(kNearbyStatusOK, nearby_fp_client_SetAdvertisement( - NEARBY_FP_ADVERTISEMENT_SPOT | - NEARBY_FP_ADVERTISEMENT_DISCOVERABLE)); - - // Provision SPOT - ASSERT_EQ(kNearbyStatusOK, - nearby_test_fakes_GattRead(kBeaconActions, BeaconAction, &length)); - ASSERT_EQ(kNearbyStatusOK, - nearby_test_fakes_GattWrite(kBeaconActions, kSetEikRequest, - sizeof(kSetEikRequest))); - - ASSERT_THAT(kSpotAdvertisement, - ElementsAreArray(nearby_test_fakes_GetSpotAdvertisement())); -} -#endif /* NEARBY_FP_ENABLE_SPOT */ - -#if NEARBY_FP_ENABLE_SPOT -#if NEARBY_FP_MESSAGE_STREAM -TEST( - NearbyFpClient, - RfcommConnected_SendsModelIdBleAddressAndBatteryInfoWithCurrentEddystoneId) { - constexpr uint64_t kPeerAddress = 0x123456; - constexpr uint8_t kExpectedRfcommOutput[] = { - // Model Id - 3, 1, 0, 3, 0x10, 0x11, 0x12, - // Ble Address - 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS - // Session nonce - 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ -#if NEARBY_FP_ENABLE_BATTERY_NOTIFICATION - // Battery level - 3, 3, 0, 3, 0xd5, 0xd0, 0xda, -#if NEARBY_BATTERY_REMAINING_TIME - // Battery remaining time - 3, 4, 0, 1, 100, -#endif /* NEARBY_BATTERY_REMAINING_TIME */ -#endif /* NEARBY_FP_ENABLE_BATTERY_NOTIFICATION*/ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', - // Current EID - 3, 0x0b, 0x00, 0x18, 0x00, 0x00, 0xc3, 0x50, 0xd8, 0xa0, 0x1e, 0x3a, 0xb9, - 0x73, 0x4a, 0x1c, 0x22, 0xea, 0x1e, 0xac, 0x5c, 0x48, 0xfc, 0x7c, 0x6e, - 0xf9, 0xd6, 0x3f}; - // computed with kSeekerKey and 8 * [0xAB] nonce - constexpr uint8_t kSetEikRequest[] = { - 0x02, 40, 0x27, 0x45, 0xdb, 0x83, 0x04, 0xc1, 0x1d, 0xc0, 0x3a, - 0x7c, 0x70, 0x23, 0x9a, 0x52, 0xdc, 0x99, 0x86, 0x11, 0x7c, 0xa8, - 0x62, 0xd8, 0x92, 0x04, 0x3a, 0x7c, 0x70, 0x23, 0x9a, 0x52, 0xdc, - 0x99, 0x86, 0x11, 0x7c, 0xa8, 0x62, 0xd8, 0x92, 0x04}; - uint8_t BeaconAction[9]; - size_t length = sizeof(BeaconAction); - nearby_test_fakes_SetGetBatteryInfoResult(kNearbyStatusUnimplemented); - nearby_fp_client_Init(&kClientCallbacks); - Pair(0x40); - ASSERT_EQ(kNearbyStatusOK, nearby_fp_client_SetAdvertisement( - NEARBY_FP_ADVERTISEMENT_SPOT | - NEARBY_FP_ADVERTISEMENT_DISCOVERABLE)); - - // Provision SPOT - ASSERT_EQ(kNearbyStatusOK, - nearby_test_fakes_GattRead(kBeaconActions, BeaconAction, &length)); - ASSERT_EQ(kNearbyStatusOK, - nearby_test_fakes_GattWrite(kBeaconActions, kSetEikRequest, - sizeof(kSetEikRequest))); - message_stream_events.clear(); -#if NEARBY_BATTERY_REMAINING_TIME - nearby_test_fakes_BatteryTime(100); -#endif /* NEARBY_BATTERY_REMAINING_TIME */ - nearby_test_fakes_GetRfcommOutput(kPeerAddress).clear(); - nearby_test_fakes_SetIsCharging(true); - - nearby_test_fakes_SetGetBatteryInfoResult(kNearbyStatusOK); - nearby_test_fakes_MessageStreamConnected(kPeerAddress); - - ASSERT_EQ(1, message_stream_events.size()); - ASSERT_EQ(MessageStreamConnectedEvent(kPeerAddress), - *message_stream_events[0]); - ASSERT_THAT(kExpectedRfcommOutput, - ElementsAreArray(nearby_test_fakes_GetRfcommOutput(kPeerAddress))); -} -#endif /* NEARBY_FP_MESSAGE_STREAM */ -#endif /* NEARBY_FP_ENABLE_SPOT */ - TEST(NearbyFpClient, GenerateSassAdvertisement) { constexpr size_t kBufferSize = 4; uint8_t buffer[kBufferSize]; @@ -3154,66 +2729,7 @@ TEST(NearbyFpClient, EncryptRrf) { ASSERT_THAT(buffer, ElementsAreArray(kExpectedResult)); } -#if NEARBY_FP_MESSAGE_STREAM -#if NEARBY_FP_RESET_PAIRING_STATE_ON_DISCONNECT -TEST(NearbyFpClient, PairingDisconnectAndReAdvertise) { - nearby_fp_client_Init(NULL); - nearby_test_fakes_SetAntiSpoofingKey(kBobPrivateKey, kBobPublicKey); - nearby_test_fakes_SetRandomNumber(kSalt); - nearby_fp_client_SetAdvertisement(NEARBY_FP_ADVERTISEMENT_DISCOVERABLE); - - uint8_t request[16]; - request[0] = 0x00; // key-based pairing request - request[1] = 0x40; - // Provider's public address - request[2] = 0xA0; - request[3] = 0xA1; - request[4] = 0xA2; - request[5] = 0xA3; - request[6] = 0xA4; - request[7] = 0xA5; - // Seeker's address - request[8] = 0xB0; - request[9] = 0xB1; - request[10] = 0xB2; - request[11] = 0xB3; - request[12] = 0xB4; - request[13] = 0xB5; - // salt - request[14] = 0xCD; - request[15] = 0xEF; - uint8_t encrypted[16 + 64]; - nearby_test_fakes_Aes128Encrypt(request, encrypted, kExpectedAesKey); - memcpy(encrypted + 16, kAlicePublicKey, 64); - // Seeker responds - ASSERT_EQ(kNearbyStatusOK, nearby_fp_fakes_ReceiveKeyBasedPairingRequest( - encrypted, sizeof(encrypted))); - // BT negotatiates passkey 123456 (0x01E240) - uint8_t raw_passkey_block[16] = {0x02, 0x01, 0xE2, 0x40}; - uint8_t encrypted_passkey_block[16]; - nearby_test_fakes_Aes128Encrypt(raw_passkey_block, encrypted_passkey_block, - kExpectedAesKey); - - // Before the Pairing flow is finished, - // call nearby_fp_client_SetAdvertisement(), with NONE, and DISCOVERABLE - constexpr uint64_t kPeerAddress = 0xb0b1b2b3b4b5; - nearby_test_fakes_MessageStreamConnected(kPeerAddress); - nearby_test_fakes_MessageStreamDisconnected(kPeerAddress); - - ASSERT_EQ(kNearbyStatusOK, nearby_fp_client_SetAdvertisement( - NEARBY_FP_ADVERTISEMENT_NONE)); - ASSERT_EQ(kNearbyStatusOK, nearby_fp_client_SetAdvertisement( - NEARBY_FP_ADVERTISEMENT_DISCOVERABLE)); - - // If NEARBY_FP_RESET_PAIRING_STATE_ON_DISCONNECT is enabled, the Discoverable - // advertisement should be read from nearby_test_fakes_GetAdvertisement() - ASSERT_THAT(nearby_test_fakes_GetAdvertisement(), - ElementsAreArray(kDiscoverableAdvertisement)); -} -#endif /* NEARBY_FP_RESET_PAIRING_STATE_ON_DISCONNECT */ -#endif /* NEARBY_FP_MESSAGE_STREAM*/ - -#if NEARBY_FP_ENABLE_SASS +#ifdef NEARBY_FP_ENABLE_SASS TEST(NearbyFpClient, SassConnected_ReceiveGetCapability_SendsCapabilityResponse) { constexpr uint64_t kPeerAddress = 0x123456; @@ -3230,28 +2746,18 @@ TEST(NearbyFpClient, 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ -#if NEARBY_FP_ENABLE_BATTERY_NOTIFICATION // Battery level 3, 3, 0, 3, 0xd5, 0xd0, 0xda, -#if NEARBY_BATTERY_REMAINING_TIME // Battery remaining time 3, 4, 0, 1, 100, -#endif /* NEARBY_BATTERY_REMAINING_TIME */ -#endif /* NEARBY_FP_ENABLE_BATTERY_NOTIFICATION*/ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Capability response 7, 0x11, 0, 4, 1, 1, 208, 0}; nearby_fp_client_Init(&kClientCallbacks); Pair(0x40); message_stream_events.clear(); -#if NEARBY_BATTERY_REMAINING_TIME nearby_test_fakes_BatteryTime(100); -#endif /* NEARBY_BATTERY_REMAINING_TIME */ nearby_test_fakes_GetRfcommOutput(kPeerAddress).clear(); nearby_test_fakes_MessageStreamConnected(kPeerAddress); @@ -3287,12 +2793,8 @@ TEST(NearbyFpClient, SassConnected_IndicateValidInUseKey_SendsAck) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // ACK 0xFF, 1, 0, 2, 0x07, 0x41}; @@ -3333,12 +2835,8 @@ TEST(NearbyFpClient, SassConnected_IndicateInvalidInUseKey_SendsNack) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // NACK 0xFF, 2, 0, 3, 0, 0x07, 0x41}; @@ -3378,12 +2876,8 @@ TEST(NearbyFpClient, SassConnected_SetMultipointState) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Indicate in-use key ACK 0xFF, 1, 0, 2, 0x07, 0x41, // ACK @@ -3429,12 +2923,8 @@ TEST(NearbyFpClient, SassConnected_SetSwitchingPreference) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Indicate in-use key ACK 0xFF, 1, 0, 2, 0x07, 0x41, // ACK @@ -3479,12 +2969,8 @@ TEST( 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Switching preference response 7, 0x22, 0, 2, 0, 0}; @@ -3526,12 +3012,8 @@ TEST(NearbyFpClient, SassConnected_SwitchActiveAudioSourceToThisPeer) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Indicate in-use key ACK 0xFF, 1, 0, 2, 0x07, 0x41, // ACK @@ -3577,12 +3059,8 @@ TEST(NearbyFpClient, 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Indicate in-use key ACK 0xFF, 1, 0, 2, 0x07, 0x41, // ACK @@ -3596,6 +3074,8 @@ TEST(NearbyFpClient, nearby_test_fakes_MessageStreamReceived(kPeerAddress, kInUseMessage, sizeof(kInUseMessage)); nearby_test_fakes_MessageStreamConnected(kPeerWithSameKey); + nearby_test_fakes_MessageStreamReceived(kPeerWithSameKey, kInUseMessage, + sizeof(kInUseMessage)); nearby_test_fakes_MessageStreamReceived(kPeerAddress, kPeerMessage, sizeof(kPeerMessage)); @@ -3624,12 +3104,8 @@ TEST(NearbyFpClient, 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Indicate in-use key ACK 0xFF, 1, 0, 2, 0x07, 0x41, // ACK @@ -3669,12 +3145,8 @@ TEST(NearbyFpClient, SassConnected_SwitchActiveAudioSourceToUnknownSource) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Indicate in-use key ACK 0xFF, 1, 0, 2, 0x07, 0x41, // ACK @@ -3719,12 +3191,8 @@ TEST(NearbyFpClient, SassConnected_SwitchBackToDisconnectedDevice) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Indicate in-use key ACK 0xFF, 1, 0, 2, 0x07, 0x41, // ACK @@ -3769,12 +3237,8 @@ TEST(NearbyFpClient, 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Indicate in-use key ACK 0xFF, 1, 0, 2, 0x07, 0x41, // Connection status response @@ -3820,12 +3284,8 @@ TEST( 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Indicate in-use key ACK 0xFF, 1, 0, 2, 0x07, 0x41, // Connection status response @@ -3873,12 +3333,8 @@ TEST(NearbyFpClient, SassConnected_NotifySassInitiatedConnection) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Indicate in-use key ACK 0xFF, 1, 0, 2, 0x07, 0x41, // ACK @@ -3927,12 +3383,8 @@ TEST(NearbyFpClient, SassConnected_SendCustomData) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Connection state 7, 0x34, 0, 12, 1, 0xaf, 0x75, 0x14, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, @@ -3951,12 +3403,8 @@ TEST(NearbyFpClient, SassConnected_SendCustomData) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Connection state 7, 0x34, 0, 12, 0, 0xaf, 0x75, 0x14, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, @@ -4014,12 +3462,8 @@ TEST(NearbyFpClient, SassConnected_SetDropConnectionTarget) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Indicate in-use key ACK 0xFF, 1, 0, 2, 0x07, 0x41, // ACK @@ -4121,7 +3565,6 @@ TEST(NearbyFpClient, CreateSassAdvertiment_NoSeeker_UsesLastUsedKey) { ElementsAreArray(expected_results[NEARBY_FP_SALT_SIZE])); } -#if NEARBY_FP_MESSAGE_STREAM TEST(NearbyFpClient, CreateSassAdvertiment_SeekerDisconnects_UsesLastUsedKey) { constexpr uint64_t kPeerAddress = 0x123456; std::map> expected_results = { @@ -4147,7 +3590,6 @@ TEST(NearbyFpClient, CreateSassAdvertiment_SeekerDisconnects_UsesLastUsedKey) { ASSERT_THAT(nearby_test_fakes_GetAdvertisement(), ElementsAreArray(expected_results[NEARBY_FP_SALT_SIZE])); } -#endif /* NEARBY_FP_MESSAGE_STREAM */ TEST(NearbyFpClient, MultipointSwitch_WithName_SendsNotificationToAllSeekers) { constexpr uint8_t kReason = 2; @@ -4159,12 +3601,8 @@ TEST(NearbyFpClient, MultipointSwitch_WithName_SendsNotificationToAllSeekers) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Indicate in-use key ACK 0xFF, 1, 0, 2, 0x07, 0x41, // Notify multipoint switch event @@ -4174,12 +3612,8 @@ TEST(NearbyFpClient, MultipointSwitch_WithName_SendsNotificationToAllSeekers) { 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Indicate in-use key ACK 0xFF, 1, 0, 2, 0x07, 0x41, // ACK @@ -4216,12 +3650,8 @@ TEST(NearbyFpClient, 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Indicate in-use key ACK 0xFF, 1, 0, 2, 0x07, 0x41, // Notify multipoint switch event @@ -4231,12 +3661,8 @@ TEST(NearbyFpClient, 3, 1, 0, 3, 0x10, 0x11, 0x12, // Ble Address 3, 2, 0, 6, 0x6b, 0xab, 0xab, 0xab, 0xab, 0xab, -#if NEARBY_FP_ENABLE_SASS // Session nonce 3, 10, 0, 8, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, kSalt, -#endif /* NEARBY_FP_ENABLE_SASS */ - // Firmware Revision - 3, 9, 0, 6, '1', '.', '0', '.', '0', '\0', // Indicate in-use key ACK 0xFF, 1, 0, 2, 0x07, 0x41, // ACK @@ -4262,81 +3688,6 @@ TEST(NearbyFpClient, kSecondPeerExpectedRfcommOutput, ElementsAreArray(nearby_test_fakes_GetRfcommOutput(kSecondPeerAddress))); } - - -TEST(NearbyFpClient, SassConnected_SendCustomDataPerSeeker) { - constexpr uint64_t kPeerAddress = 0x123456; - constexpr uint64_t kSecondPeerAddress = 0x89ABCD; - constexpr uint64_t kNonSeekerPeerAddress = 0x765432; - constexpr uint8_t kCustomData = 0xAB; - constexpr uint8_t kCustomData2 = 0xAA; - constexpr uint8_t kPeerMessage[] = { - 0x07, 0x42, 0, 17, kCustomData, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, - 0xC6, 0xC7, 0x30, 0x75, 0x28, 0xdd, 0x98, 0x27, 0x07, 0x95}; - constexpr uint8_t kPeerMessage2[] = { - 0x07, 0x42, 0, 17, kCustomData2, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, - 0xC6, 0xC7, 0x7a, 0x5d, 0xd0, 0x30, 0xa5, 0x40, 0x21, 0xd8}; - // Advertisement with custom data == 0 - constexpr uint8_t kDefaultAdvertisement[] = { - 0x11, 0x16, 0x2c, 0xfe, 0x10, 0x42, 0x1, 0x11, 0x90, 0x60, - 0x21, 0xab, 0xab, 0x46, 0xdf, 0xa3, 0x4b, 0xed, 0x2, 0xa, 0x21 - }; - // Advertisement with custom data == kCustomData - constexpr uint8_t kExpectedAdvertisement[] = { - 0x11, 0x16, 0x2c, 0xfe, 0x10, 0x42, 0x16, 0x3, 0x88, 0x2, - 0x21, 0xab, 0xab, 0x46, 0xdf, 0xa3, 0xe0, 0xed, 0x2, 0xa, 0x21, - }; - // Advertisement with custom data == kCustomData2 - constexpr uint8_t kExpectedSeeker2Advertisement[] = { - 0x11, 0x16, 0x2c, 0xfe, 0x10, 0x42, 0x44, 0x80, 0x18, 0x84, - 0x21, 0xab, 0xab, 0x46, 0xdf, 0xa3, 0xe1, 0xed, 0x2, 0xa, 0x21, - }; - // Advertisement using non Seeker - constexpr uint8_t kExpectedNonSeekerAdvertisement[] = { - 0x11, 0x16, 0x2c, 0xfe, 0x10, 0x42, 0x1, 0x11, 0x90, 0x60, - 0x21, 0xab, 0xab, 0x46, 0xdf, 0xa3, 0x4b, 0xed, 0x2, 0xa, 0x21, - }; - - nearby_fp_client_Init(&kClientCallbacks); - Pair(0x40); - nearby_test_fakes_SetActiveAudioSource(kPeerAddress); - nearby_test_fakes_SetGetBatteryInfoResult(kNearbyStatusUnsupported); - nearby_fp_client_SetAdvertisement(NEARBY_FP_ADVERTISEMENT_NON_DISCOVERABLE | - NEARBY_FP_ADVERTISEMENT_SASS); - message_stream_events.clear(); - nearby_test_fakes_MessageStreamConnected(kPeerAddress); - nearby_test_fakes_MessageStreamReceived(kPeerAddress, kInUseMessage, - sizeof(kInUseMessage)); - nearby_test_fakes_MessageStreamConnected(kSecondPeerAddress); - nearby_test_fakes_MessageStreamReceived(kSecondPeerAddress, kInUseMessage, - sizeof(kInUseMessage)); - - ASSERT_THAT(kDefaultAdvertisement, ElementsAreArray(nearby_test_fakes_GetAdvertisement())); - - nearby_test_fakes_MessageStreamReceived(kPeerAddress, kPeerMessage, - sizeof(kPeerMessage)); - ASSERT_THAT(kExpectedAdvertisement, ElementsAreArray(nearby_test_fakes_GetAdvertisement())); - - // Second Seeker changes the custom data - nearby_test_fakes_MessageStreamReceived(kSecondPeerAddress, kPeerMessage2, - sizeof(kPeerMessage)); - // Verify that the custom data in the advertisement does not change when a Seeker, - // who isn't the active audio source, changes their custom data. - ASSERT_THAT(kExpectedAdvertisement, ElementsAreArray(nearby_test_fakes_GetAdvertisement())); - - // Change active audio source to Seeker 2 - nearby_test_fakes_SetActiveAudioSource(kSecondPeerAddress); - - // Verify that when Seeker-2 is the active source, the advertisement - ASSERT_THAT(kExpectedSeeker2Advertisement, ElementsAreArray(nearby_test_fakes_GetAdvertisement())); - - // Change active audio source to Non seeker - nearby_test_fakes_SetActiveAudioSource(kNonSeekerPeerAddress); - - ASSERT_THAT(kExpectedNonSeekerAdvertisement, ElementsAreArray(nearby_test_fakes_GetAdvertisement())); -} - - #endif /* NEARBY_FP_ENABLE_SASS */ #pragma GCC diagnostic pop diff --git a/embedded/client/tests/spot_test.cc b/embedded/client/tests/spot_test.cc deleted file mode 100644 index 102fcae2..00000000 --- a/embedded/client/tests/spot_test.cc +++ /dev/null @@ -1,1311 +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 -#include -#include - -#include "fakes.h" -#include "gmock/gmock-matchers.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "nearby.h" -#include "nearby_fp_client.h" -#include "nearby_fp_library.h" -#include "nearby_platform_ble.h" -#include "nearby_platform_os.h" -#include "nearby_platform_persistence.h" -#include "nearby_platform_se.h" -#include "nearby_spot.h" - -using ::testing::ElementsAreArray; - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wunused-const-variable" - -#if NEARBY_FP_ENABLE_SPOT - -#define APPEND_ARRAY(vector, array) \ - vector.insert(vector.end(), array, array + sizeof(array)) - -static constexpr uint8_t kUnathenticated = 0x80; -static constexpr uint8_t kInvalidValue = 0x81; -static constexpr uint8_t kNoUserConsent = 0x82; - -static constexpr uint8_t kEphemeralKey[32] = { - 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x60, - 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x70, 0x71, - 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x80, 0x81}; - -static constexpr uint8_t kOtherEphemeralKey[32] = { - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x20, - 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30, 0x31, - 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40, 0x41}; - -static constexpr uint8_t kOwnerKey[16] = {0x04, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, - 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xB0, - 0xB1, 0xB2, 0xB3, 0xB4}; - -static nearby_platform_AccountKeyInfo account_key_info; - -static constexpr uint8_t kOtherAccountKey[] = { - 0x04, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, - 0x99, 0x00, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}; - -// computed manually from kEphemeralKay, rotation: 10 and clock: 50000 -static constexpr uint8_t kEid[20] = {0xe5, 0x12, 0x04, 0xe4, 0x39, 0xba, 0xda, - 0x54, 0x96, 0x4b, 0x06, 0xa5, 0x4f, 0x3a, - 0x0c, 0x05, 0x8e, 0x0a, 0x32, 0x4a}; - -// nonce is 8 * [kRandom] -static constexpr uint8_t kRandom = 0x45; - -static constexpr uint8_t kAdvertisement[28] = { - 2, 1, 6, 24, 0x16, 0xAA, 0xFE, 0x40, 0xe5, 0x12, - 0x04, 0xe4, 0x39, 0xba, 0xda, 0x54, 0x96, 0x4b, 0x06, 0xa5, - 0x4f, 0x3a, 0x0c, 0x05, 0x8e, 0x0a, 0x32, 0x4a}; - -// Advertisement computed from kOtherEphemeralKey -static constexpr uint8_t kOtherAdvertisement[28] = { - 2, 1, 6, 24, 0x16, 0xaa, 0xfe, 0x40, 0x0f, 0x2a, - 0x11, 0xc9, 0x08, 0x2c, 0x3a, 0x94, 0xdc, 0x33, 0x7f, 0x78, - 0x39, 0x50, 0x3f, 0xd1, 0x08, 0x94, 0xf5, 0xb4}; - -// kEphemeralKey encrypted with AES-ECB-128 using kOwnerKey -static constexpr uint8_t kEncryptedEik[32] = { - 0x89, 0x30, 0xb0, 0xed, 0x94, 0xb1, 0x3c, 0x30, 0x69, 0x2a, 0xcb, - 0xb1, 0x1c, 0xf5, 0x50, 0x3b, 0xeb, 0x7c, 0x56, 0x8c, 0x88, 0xfe, - 0x1b, 0x95, 0x08, 0x69, 0x77, 0xca, 0xed, 0x24, 0x58, 0x5b}; - -// kOtherEphemeralKey encrypted with AES-ECB-128 using kOwnerKey -static constexpr uint8_t kOtherEncryptedEik[32] = { - 0x58, 0xcf, 0x86, 0x87, 0xfb, 0xe8, 0xcd, 0x33, 0x75, 0x44, 0x56, - 0x6d, 0x16, 0xe2, 0x43, 0x55, 0xfa, 0xf6, 0x60, 0xad, 0x01, 0x8b, - 0x3e, 0x37, 0x7d, 0xb4, 0x79, 0xdf, 0xe5, 0xd4, 0x1f, 0x98}; - -static constexpr uint8_t kRecoveryKey[8] = {0xe9, 0x1a, 0x75, 0x5b, - 0x6d, 0x15, 0x44, 0xf1}; -static constexpr uint8_t kRingKey[8] = {0x02, 0x6d, 0xd8, 0xcc, - 0x60, 0xf2, 0x05, 0xb8}; -static constexpr uint8_t kUnwantedTrackingProtectionKey[8] = { - 0x5c, 0x39, 0x3a, 0xb6, 0xeb, 0x24, 0x63, 0xfb}; - -// First 8 bytes of sha256(kOwnerKey || nonce) -static constexpr uint8_t kSha256OwnerKeyNonce[8] = {0x9c, 0x6d, 0x32, 0xf8, - 0xc1, 0xe2, 0xe5, 0x9a}; - -// First 8 bytes of sha256(kOtherAccountKey || nonce) -static constexpr uint8_t kSha256OtherAccountHeyNonce[8] = { - 0x9c, 0x6d, 0x32, 0xf8, 0xc1, 0xe2, 0xe5, 0x9a}; - -// First 8 bytes of sha256(kEphemeralKey || nonce) -static constexpr uint8_t kSha256EikNonce[8] = {0x11, 0xb7, 0x0d, 0xf9, - 0x36, 0xa1, 0x1c, 0x69}; - -// First 8 bytes of hmac-sha256(kRecoveryKey || protocol version || nonce || 04 -// || 08 ) -static constexpr uint8_t kHmacSha256RecoveryKeyPayload[8] = { - 0x91, 0x3c, 0x77, 0xa7, 0xa7, 0x9e, 0x01, 0x3d}; -// First 8 bytes of hamc-sha256(kRingKey || protocol version || nonce || 05 || -// 12 || FF || 06 || 07 || 03) -static constexpr uint8_t kHmacSha256RingPayload[8] = {0x4c, 0x77, 0xa0, 0xae, - 0x32, 0x0a, 0x29, 0xe5}; - -class SpotTest : public ::testing::Test { - protected: - void SetUp() override; - void SetEphemeralKey() { - ASSERT_EQ(kNearbyStatusOK, - nearby_platform_SaveValue(kStoredKeyEphemeralKey, kEphemeralKey, - sizeof(kEphemeralKey))); - } - void SetOwnerKey() { - ASSERT_EQ(kNearbyStatusOK, - nearby_platform_SaveValue(kStoredKeyOwnerKey, kOwnerKey, - sizeof(kOwnerKey))); - } - - void SetAccountKeys() { - nearby_fp_LoadAccountKeys(); - memcpy(&(account_key_info.account_key), kOwnerKey, sizeof(kOwnerKey)); - nearby_fp_AddAccountKey(&account_key_info); - memcpy(&(account_key_info.account_key), kOtherAccountKey, - sizeof(kOtherAccountKey)); - nearby_fp_AddAccountKey(&account_key_info); - } - - void ReadNonce() { - uint8_t BeaconAction[9]; - size_t length = sizeof(BeaconAction); - - EXPECT_EQ(kNearbyStatusOK, nearby_test_fakes_GattRead( - kBeaconActions, BeaconAction, &length)); - // Check for SPOT beacon major protocol version to be 1 - EXPECT_EQ(SPOT_BEACON_PROTOCOL_MAJOR_VERSION, BeaconAction[0]); - memcpy(nonce_, &BeaconAction[1], sizeof(nonce_)); - EXPECT_EQ(length, (sizeof(nonce_) + 1)); - } - - bool HasSentNotification() { - return nearby_test_fakes_GetGattNotifications().end() != - nearby_test_fakes_GetGattNotifications().find(kBeaconActions); - } - uint8_t nonce_[8]; -}; - -static void OnRingStateChange() { nearby_spot_OnRingStateChange(); } -static constexpr nearby_platform_OsInterface kOsInterface = { - .on_ring_state_change = OnRingStateChange, -}; - -static nearby_platform_status OnGattWrite( - uint64_t peer_address, nearby_fp_Characteristic characteristic, - const uint8_t* request, size_t length) { - EXPECT_EQ(kBeaconActions, characteristic); - return nearby_spot_WriteBeaconAction(peer_address, request, length); -} -static nearby_platform_status OnGattRead( - uint64_t peer_address, nearby_fp_Characteristic characteristic, - uint8_t* output, size_t* length) { - EXPECT_EQ(kBeaconActions, characteristic); - return nearby_spot_ReadBeaconAction(peer_address, output, length); -} -static constexpr nearby_platform_BleInterface kBleInterface = { - .on_gatt_write = OnGattWrite, - .on_gatt_read = OnGattRead, -}; - -void SpotTest::SetUp() { - nearby_platform_PersistenceInit(); - nearby_platform_SecureElementInit(); - nearby_platform_OsInit(&kOsInterface); - nearby_platform_BleInit(&kBleInterface); - nearby_test_fakes_SetRandomNumber(kRandom); - SetAccountKeys(); -} - -TEST_F(SpotTest, Init) { ASSERT_EQ(kNearbyStatusOK, nearby_spot_Init()); } - -TEST_F(SpotTest, SetAdvertisement_NoEphemeralKey_Fails) { - nearby_spot_Init(); - - ASSERT_EQ(kNearbyStatusError, nearby_spot_SetAdvertisement(true)); -} - -TEST_F(SpotTest, SetAdvertisement_NoOwnerKey_Fails) { - SetEphemeralKey(); - nearby_spot_Init(); - - ASSERT_EQ(kNearbyStatusError, nearby_spot_SetAdvertisement(true)); -} - -TEST_F(SpotTest, SetAdvertisement) { - nearby_test_fakes_SetGetBatteryInfoResult(kNearbyStatusUnimplemented); - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - - ASSERT_EQ(kNearbyStatusOK, nearby_spot_SetAdvertisement(true)); - ASSERT_THAT(kAdvertisement, - ElementsAreArray(nearby_test_fakes_GetSpotAdvertisement())); -} - -TEST_F(SpotTest, SetBeaconAccountKey) { - constexpr uint8_t kAccountKey[16] = {0x04, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, - 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xD0, - 0xD1, 0xD2, 0xD3, 0xD4}; - uint8_t result[sizeof(kAccountKey)]; - size_t length = sizeof(result); - - ASSERT_EQ(kNearbyStatusOK, nearby_spot_SetBeaconAccountKey(kAccountKey)); - - ASSERT_EQ(kNearbyStatusOK, - nearby_platform_LoadValue(kStoredKeyOwnerKey, result, &length)); - ASSERT_THAT(result, - ElementsAreArray(kAccountKey, kAccountKey + sizeof(kAccountKey))); -} - -TEST_F(SpotTest, ReadBeaconAction) { - std::vector random_numbers = {0, 1, 2, 3, 4, 5, 6, 7}; - nearby_test_fakes_SetRandomNumberSequence(random_numbers); - - ReadNonce(); - - ASSERT_THAT(nonce_, ElementsAreArray(random_numbers)); -} - -TEST_F(SpotTest, ReadBeaconParameters_ValidAccountKey_SendsNotification) { - constexpr uint8_t kRequest[] = {0, 8, 0x83, 0x8b, 0x57, - 0x68, 0x30, 0xb8, 0x11, 0xcc}; - constexpr uint8_t kExpectedResponse[] = { - 0, 24, 0xae, 0xb6, 0x4a, 0x5d, 0xdd, 0x85, 0xec, - 0x37, 0xA8, 0x89, 0x32, 0xF1, 0x5C, 0x13, 0xDC, 0xBA, - 0xCF, 0x2C, 0x29, 0x4E, 0x0D, 0x08, 0x10, 0x83}; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kNearbyStatusOK, nearby_test_fakes_GattWrite( - kBeaconActions, kRequest, sizeof(kRequest))); - - ASSERT_TRUE(HasSentNotification()); - ASSERT_THAT(kExpectedResponse, - ElementsAreArray( - nearby_test_fakes_GetGattNotifications().at(kBeaconActions))); -} - -TEST_F(SpotTest, ReadBeaconParameters_InvalidAccountKey_RejectsRequest) { - constexpr uint8_t kRequest[] = {0, 8, 0xFF, 0x6d, 0x32, - 0xf8, 0xc1, 0xe2, 0xe5, 0x9a}; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kUnathenticated, nearby_test_fakes_GattWrite( - kBeaconActions, kRequest, sizeof(kRequest))); - - ASSERT_FALSE(HasSentNotification()); -} - -TEST_F(SpotTest, - ReadProvisioningState_OwnerKeyProvisionedDevice_SendsNotification) { - constexpr uint8_t kRequest[] = {1, 8, 0x3f, 0xcf, 0x0f, - 0x68, 0x1c, 0x54, 0xee, 0xee}; - std::vector expected_response = {1, 29, 0xa8, 0x51, 0x8b, 0x21, - 0xf3, 0x32, 0x40, 0x07, 0x03}; - APPEND_ARRAY(expected_response, kEid); - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kNearbyStatusOK, nearby_test_fakes_GattWrite( - kBeaconActions, kRequest, sizeof(kRequest))); - - ASSERT_TRUE(HasSentNotification()); - ASSERT_THAT(expected_response, - ElementsAreArray( - nearby_test_fakes_GetGattNotifications().at(kBeaconActions))); -} - -TEST_F( - SpotTest, - ReadProvisioningState_ValidNonOwnerKeyProvisionedDevice_SendsNotification) { - constexpr uint8_t kRequest[] = {1, 8, 0xff, 0xdb, 0x61, - 0x2f, 0x65, 0xdc, 0xfd, 0x0a}; - std::vector expected_response = {1, 29, 0x63, 0x09, 0xa7, 0x09, - 0x47, 0xd7, 0x05, 0x09, 0x01}; - APPEND_ARRAY(expected_response, kEid); - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kNearbyStatusOK, nearby_test_fakes_GattWrite( - kBeaconActions, kRequest, sizeof(kRequest))); - - ASSERT_TRUE(HasSentNotification()); - ASSERT_THAT(expected_response, - ElementsAreArray( - nearby_test_fakes_GetGattNotifications().at(kBeaconActions))); -} - -TEST_F(SpotTest, - ReadProvisioningState_OwnerKeyNotProvisionedDevice_SendsNotification) { - constexpr uint8_t kRequest[] = {1, 8, 0x3f, 0xcf, 0x0f, - 0x68, 0x1c, 0x54, 0xee, 0xee}; - std::vector expected_response = {1, 9, 0xae, 0xe3, 0x28, 0x42, - 0x58, 0xe7, 0xb1, 0xbf, 0x02}; - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kNearbyStatusOK, nearby_test_fakes_GattWrite( - kBeaconActions, kRequest, sizeof(kRequest))); - - ASSERT_TRUE(HasSentNotification()); - ASSERT_THAT(expected_response, - ElementsAreArray( - nearby_test_fakes_GetGattNotifications().at(kBeaconActions))); -} - -TEST_F(SpotTest, ReadProvisioningState_InvalidKey_RejectsRequest) { - constexpr uint8_t kRequest[] = {1, 8, 0xFF, 0x5a, 0x68, - 0x11, 0x14, 0xb1, 0x90, 0x63}; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kUnathenticated, nearby_test_fakes_GattWrite( - kBeaconActions, kRequest, sizeof(kRequest))); - - ASSERT_FALSE(HasSentNotification()); -} - -TEST_F(SpotTest, SetEid_OwnerKeyNotProvisionedDevice_StartsAdvertising) { - std::vector request = {2, 40, 0xcd, 0xbc, 0xc8, - 0xbc, 0x5b, 0xbd, 0x0d, 0x82}; - std::vector expected_response = {2, 8, 0xf0, 0x7b, 0x29, - 0x79, 0x3a, 0x8f, 0xb3, 0xae}; - APPEND_ARRAY(request, kEncryptedEik); - nearby_test_fakes_SetGetBatteryInfoResult(kNearbyStatusUnimplemented); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kNearbyStatusOK, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_TRUE(HasSentNotification()); - ASSERT_THAT(expected_response, - ElementsAreArray( - nearby_test_fakes_GetGattNotifications().at(kBeaconActions))); - - ASSERT_THAT(kAdvertisement, - ElementsAreArray(nearby_test_fakes_GetSpotAdvertisement())); -} - -TEST_F(SpotTest, ResetEid_ValidRequest_AdvertisesNewKey) { - std::vector request = {2, 48, 0x37, 0x40, 0x91, - 0xc9, 0x22, 0x49, 0x84, 0xf7}; - std::vector expected_response = {2, 8, 0xf0, 0x7b, 0x29, - 0x79, 0x3a, 0x8f, 0xb3, 0xae}; - APPEND_ARRAY(request, kOtherEncryptedEik); - APPEND_ARRAY(request, kSha256EikNonce); - nearby_test_fakes_SetGetBatteryInfoResult(kNearbyStatusUnimplemented); - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kNearbyStatusOK, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_TRUE(HasSentNotification()); - ASSERT_THAT(expected_response, - ElementsAreArray( - nearby_test_fakes_GetGattNotifications().at(kBeaconActions))); - - ASSERT_THAT(kOtherAdvertisement, - ElementsAreArray(nearby_test_fakes_GetSpotAdvertisement())); -} - -TEST_F(SpotTest, ResetEid_InvalidRequest_RejectsRequest) { - std::vector request = {2, 48, 0x37, 0x40, 0x91, - 0xc9, 0x22, 0x49, 0x84, 0xf7}; - constexpr uint8_t kInvalidSha256EikNonce[8] = {1, 2, 3, 4, 5, 6, 7, 8}; - APPEND_ARRAY(request, kOtherEncryptedEik); - APPEND_ARRAY(request, kInvalidSha256EikNonce); - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kUnathenticated, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); -} - -TEST_F(SpotTest, ResetEid_DeviceNotProvisioned_RejectsRequest) { - std::vector request = {2, 48, 0x37, 0x40, 0x91, - 0xc9, 0x22, 0x49, 0x84, 0xf7}; - APPEND_ARRAY(request, kOtherEncryptedEik); - APPEND_ARRAY(request, kSha256EikNonce); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_NE(kNearbyStatusOK, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_FALSE(HasSentNotification()); - ASSERT_EQ(0, nearby_test_fakes_GetSpotAdvertisement().size()); -} - -TEST_F(SpotTest, SetEid_OwnerKeyProvisionedDevice_RejectsRequest) { - std::vector request = {2, 40, 0xcd, 0xbc, 0xc8, - 0xbc, 0x5b, 0xbd, 0x0d, 0x82}; - APPEND_ARRAY(request, kEncryptedEik); - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kInvalidValue, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_FALSE(HasSentNotification()); - ASSERT_EQ(0, nearby_test_fakes_GetSpotAdvertisement().size()); -} - -TEST_F(SpotTest, SetEid_OtherkeyNotProvisionedDevice_RejectsRequest) { - std::vector request = {2, 40, 0xc9, 0x5a, 0x68, - 0x11, 0x14, 0xb1, 0x90, 0x63}; - APPEND_ARRAY(request, kEncryptedEik); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kUnathenticated, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_FALSE(HasSentNotification()); - ASSERT_EQ(0, nearby_test_fakes_GetSpotAdvertisement().size()); -} - -TEST_F(SpotTest, ClearEid_OwnerKeyValidRequest_StopsAdvertising) { - std::vector request = {3, 16, 0x51, 0x86, 0x16, - 0x90, 0x5d, 0x86, 0x43, 0xf6}; - std::vector expected_response = {3, 8, 0xa1, 0x49, 0x0c, - 0xe1, 0xde, 0xd4, 0xec, 0x89}; - APPEND_ARRAY(request, kSha256EikNonce); - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - ASSERT_EQ(kNearbyStatusOK, nearby_spot_SetAdvertisement(true)); - - ASSERT_THAT(kNearbyStatusOK, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_TRUE(HasSentNotification()); - ASSERT_THAT(expected_response, - ElementsAreArray( - nearby_test_fakes_GetGattNotifications().at(kBeaconActions))); - ASSERT_EQ(0, nearby_test_fakes_GetSpotAdvertisement().size()); -#if NEARBY_SPOT_FACTORY_RESET_DEVICE_ON_CLEARING_EIK - ASSERT_EQ(0, nearby_fp_GetAccountKeyCount()); -#endif - ASSERT_EQ(kNearbyStatusError, nearby_spot_SetAdvertisement(true)); -} - -TEST_F(SpotTest, ClearEid_OtherKeyValidRequest_RejectsRequest) { - std::vector request = {3, 16, 0xc9, 0x5a, 0x68, - 0x11, 0x14, 0xb1, 0x90, 0x63}; - APPEND_ARRAY(request, kSha256EikNonce); - nearby_test_fakes_SetGetBatteryInfoResult(kNearbyStatusUnimplemented); - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - ASSERT_EQ(kNearbyStatusOK, nearby_spot_SetAdvertisement(true)); - - ASSERT_THAT(kUnathenticated, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_FALSE(HasSentNotification()); - ASSERT_THAT(kAdvertisement, - ElementsAreArray(nearby_test_fakes_GetSpotAdvertisement())); -} - -TEST_F(SpotTest, ClearEid_OwnerKeyInvalidRequest_RejectsRequest) { - std::vector request = {3, 16, 0x51, 0x86, 0x16, 0x90, - 0x5d, 0x86, 0x43, 0xf6, 0, 1, - 2, 3, 4, 5, 6, 7}; - nearby_test_fakes_SetGetBatteryInfoResult(kNearbyStatusUnimplemented); - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - ASSERT_EQ(kNearbyStatusOK, nearby_spot_SetAdvertisement(true)); - - ASSERT_THAT(kUnathenticated, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_FALSE(HasSentNotification()); - ASSERT_THAT(kAdvertisement, - ElementsAreArray(nearby_test_fakes_GetSpotAdvertisement())); -} - -TEST_F(SpotTest, ReadEik_ValidRequestInPairingMode_SendsNotification) { - std::vector request = {4, 8}; - APPEND_ARRAY(request, kHmacSha256RecoveryKeyPayload); - std::vector expected_response = {4, 40, 0xec, 0x7e, 0xab, - 0xbd, 0x90, 0x03, 0x3b, 0xbf}; - APPEND_ARRAY(expected_response, kEncryptedEik); - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - nearby_test_fakes_SetInPairingMode(true); - nearby_test_fakes_SetHasUserContentForReadingEik(false); - - ASSERT_THAT(kNearbyStatusOK, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_TRUE(HasSentNotification()); - ASSERT_THAT(expected_response, - ElementsAreArray( - nearby_test_fakes_GetGattNotifications().at(kBeaconActions))); -} - -TEST_F(SpotTest, ReadEik_ValidRequestInEIKRecoveryMode_SendsNotification) { - std::vector request = {4, 8}; - APPEND_ARRAY(request, kHmacSha256RecoveryKeyPayload); - std::vector expected_response = {4, 40, 0xec, 0x7e, 0xab, - 0xbd, 0x90, 0x03, 0x3b, 0xbf}; - APPEND_ARRAY(expected_response, kEncryptedEik); - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - nearby_test_fakes_SetInPairingMode(false); - nearby_test_fakes_SetHasUserContentForReadingEik(true); - - ASSERT_THAT(kNearbyStatusOK, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_TRUE(HasSentNotification()); - ASSERT_THAT(expected_response, - ElementsAreArray( - nearby_test_fakes_GetGattNotifications().at(kBeaconActions))); -} - -TEST_F(SpotTest, ReadEik_ValidRequestNoConsent_RejectsRequest) { - std::vector request = {4, 8}; - APPEND_ARRAY(request, kHmacSha256RecoveryKeyPayload); - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - nearby_test_fakes_SetInPairingMode(false); - nearby_test_fakes_SetHasUserContentForReadingEik(false); - - ASSERT_THAT(kNoUserConsent, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_FALSE(HasSentNotification()); -} - -TEST_F(SpotTest, ReadEik_InvalidRequestHasUserConsent_RejectsRequest) { - std::vector request = {4, 8, 1, 2, 3, 4, 5, 6, 7, 8}; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - nearby_test_fakes_SetHasUserContentForReadingEik(true); - - ASSERT_THAT(kUnathenticated, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_FALSE(HasSentNotification()); -} - -TEST_F(SpotTest, Ring_StartRingingRequest_CallsHal) { - constexpr uint8_t kCommand = 0xFF; - constexpr uint8_t kTimeoutHigh = 6; - constexpr uint8_t kTimeoutLow = 7; - constexpr nearby_platform_RingingVolume kRingingVolume = kRingingVolumeHigh; - std::vector request = {5, 12, 0x97, 0xcb, 0x73, - 0x01, 0xca, 0x3b, 0x38, 0x8b}; - request.push_back(kCommand); - request.push_back(kTimeoutHigh); - request.push_back(kTimeoutLow); - request.push_back(kRingingVolume); - nearby_platform_RingingInfo ringing_info; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kNearbyStatusOK, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_FALSE(HasSentNotification()); - ASSERT_EQ(kNearbyStatusOK, nearby_platform_GetRingingInfo(&ringing_info)); - ASSERT_EQ(kCommand, ringing_info.components); - ASSERT_EQ(kTimeoutHigh * 256 + kTimeoutLow, ringing_info.timeout); - ASSERT_EQ(kRingingVolume, ringing_info.volume); -} - -TEST_F(SpotTest, Ring_DeviceNotProvisioned_RejectsRequest) { - constexpr uint8_t kCommand = 0xFF; - constexpr uint8_t kTimeoutHigh = 6; - constexpr uint8_t kTimeoutLow = 7; - constexpr nearby_platform_RingingVolume kRingingVolume = kRingingVolumeHigh; - std::vector request = {5, 12}; - APPEND_ARRAY(request, kHmacSha256RingPayload); - request.push_back(kCommand); - request.push_back(kTimeoutHigh); - request.push_back(kTimeoutLow); - request.push_back(kRingingVolume); - nearby_platform_RingingInfo ringing_info; - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kInvalidValue, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_FALSE(HasSentNotification()); - ASSERT_EQ(kNearbyStatusOK, nearby_platform_GetRingingInfo(&ringing_info)); - ASSERT_EQ(0, ringing_info.components); - ASSERT_EQ(0, ringing_info.timeout); - ASSERT_EQ(0, ringing_info.volume); -} - -TEST_F(SpotTest, Ring_InvalidRequest_RejectsRequest) { - std::vector request = {5, 12, 1, 2, 3, 4, 5, - 6, 7, 8, 0xFF, 9, 10, 05}; - nearby_platform_RingingInfo ringing_info; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kUnathenticated, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_FALSE(HasSentNotification()); - ASSERT_EQ(kNearbyStatusOK, nearby_platform_GetRingingInfo(&ringing_info)); - ASSERT_EQ(0, ringing_info.components); - ASSERT_EQ(0, ringing_info.timeout); -} - -TEST_F(SpotTest, Ring_StopRequest_CallsHal) { - constexpr uint8_t kCommand = 0x00; - std::vector request = {5, 9, 0xdf, 0xf9, 0x99, - 0xb0, 0x82, 0xfa, 0xb2, 0x90}; - request.push_back(kCommand); - nearby_platform_RingingInfo ringing_info; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kNearbyStatusOK, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_FALSE(HasSentNotification()); - ASSERT_EQ(kNearbyStatusOK, nearby_platform_GetRingingInfo(&ringing_info)); - ASSERT_EQ(kCommand, ringing_info.components); -} - -TEST_F(SpotTest, ReadRingingState_ValidRequest_SendsNotification) { - constexpr uint8_t kNumComponents = 3; - constexpr uint8_t kComponents = 0x02; - constexpr uint8_t kTimeoutHigh = 6; - constexpr uint8_t kTimeoutLow = 7; - constexpr nearby_platform_RingingVolume kRingingVolume = kRingingVolumeHigh; - - std::vector request = {6, 8, 0x97, 0xde, 0xff, - 0xec, 0x0f, 0xa7, 0x1c, 0xce}; - constexpr nearby_platform_RingingInfo kRingingInfo = { - .ring_state = kRingStateStarted, - .num_components = kNumComponents, - .components = kComponents, - .timeout = kTimeoutHigh * 256 + kTimeoutLow, - .volume = kRingingVolume}; - std::vector expected_response = { - 6, 11, 0x61, 0x4f, 0x2e, 0x92, 0x97, - 0xbb, 0xe6, 0x33, kComponents, kTimeoutHigh, kTimeoutLow}; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - nearby_test_fakes_SetRingingInfo(&kRingingInfo); - - ASSERT_THAT(kNearbyStatusOK, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_TRUE(HasSentNotification()); - ASSERT_THAT(expected_response, - ElementsAreArray( - nearby_test_fakes_GetGattNotifications().at(kBeaconActions))); -} - -TEST_F(SpotTest, ReadRingingState_InvalidRequest_RejectsRequest) { - std::vector request = {6, 8, 1, 2, 3, 4, 5, 6, 7, 8}; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kUnathenticated, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_FALSE(HasSentNotification()); -} - -TEST_F(SpotTest, OnRingStateChanged_SendsNotification) { - constexpr uint8_t kNumComponents = 0x03; - constexpr uint8_t kComponents = 0x02; - constexpr uint8_t kTimeoutHigh = 6; - constexpr uint8_t kTimeoutLow = 7; - constexpr nearby_platform_RingingVolume kRingingVolume = kRingingVolumeHigh; - - constexpr nearby_platform_RingingInfo kRingingInfo = { - .ring_state = kRingStateStarted, - .num_components = kNumComponents, - .components = kComponents, - .timeout = kTimeoutHigh * 256 + kTimeoutLow, - .volume = kRingingVolume}; - - std::vector expected_response = {5, - 12, - 0x24, - 0xe2, - 0x18, - 0xff, - 0xd0, - 0x16, - 0x23, - 0x43, - kRingStateStarted, - kComponents, - kTimeoutHigh, - kTimeoutLow}; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - nearby_test_fakes_SetRingingInfo(&kRingingInfo); - - nearby_test_fakes_NotifyRingStateChanged(); - - ASSERT_TRUE(HasSentNotification()); - ASSERT_THAT(expected_response, - ElementsAreArray( - nearby_test_fakes_GetGattNotifications().at(kBeaconActions))); -} - -TEST_F(SpotTest, ActivateUnwantedTrackingProtectionMode_InValidRequest) { - std::vector request = {7, 8, 1, 2, 3, 4, 5, 6, 7, 8}; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kUnathenticated, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_FALSE(nearby_spot_GetUnwantedTrackingProtectionModeState()); - ASSERT_FALSE(HasSentNotification()); -} - -TEST_F(SpotTest, ActivateUnwantedTrackingProtectionMode_ValidRequest) { - std::vector request = {7, 8, 0x23, 0x9f, 0x28, - 0xb8, 0xba, 0xd4, 0xf4, 0x11}; - std::vector expected_response = {7, 8, 0xc1, 0xfe, 0xe9, - 0x33, 0x9b, 0x90, 0x6d, 0x1f}; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kNearbyStatusOK, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_TRUE(HasSentNotification()); - ASSERT_TRUE(nearby_spot_GetUnwantedTrackingProtectionModeState()); - ASSERT_THAT(expected_response, - ElementsAreArray( - nearby_test_fakes_GetGattNotifications().at(kBeaconActions))); -} - -TEST_F(SpotTest, - ActivateUnwantedTrackingProtectionModeWithControlFlags_ValidRequest) { - std::vector request = {7, 9, 0x3b, 0xb4, 0x8e, 0x19, - 0x91, 0x39, 0xd2, 0x0e, 0x01}; - std::vector expected_response = {7, 8, 0xc1, 0xfe, 0xe9, - 0x33, 0x9b, 0x90, 0x6d, 0x1f}; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kNearbyStatusOK, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_TRUE(HasSentNotification()); - ASSERT_TRUE(nearby_spot_GetUnwantedTrackingProtectionModeState()); - // Check the skip ringing authentication flag is set - ASSERT_TRUE(nearby_spot_GetControlFlags() == 0x01); - ASSERT_THAT(expected_response, - ElementsAreArray( - nearby_test_fakes_GetGattNotifications().at(kBeaconActions))); -} - -TEST_F(SpotTest, Ring_StartRingingRequest_InvalidAuthenticationData) { - constexpr uint8_t kCommand = 0xFF; - constexpr uint8_t kTimeoutHigh = 6; - constexpr uint8_t kTimeoutLow = 7; - constexpr nearby_platform_RingingVolume kRingingVolume = kRingingVolumeHigh; - std::vector request = {5, 12, 0x12, 0x34, 0x56, - 0x78, 0x90, 0x11, 0x12, 0x34}; - request.push_back(kCommand); - request.push_back(kTimeoutHigh); - request.push_back(kTimeoutLow); - request.push_back(kRingingVolume); - nearby_platform_RingingInfo ringing_info; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - nearby_spot_SetUnwantedTrackingProtectionMode(true); - - ASSERT_THAT(kNearbyStatusOK, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_FALSE(HasSentNotification()); - // Check the skip ringing authentication flag is set - ASSERT_TRUE(nearby_spot_GetControlFlags() == 0x01); - ASSERT_EQ(kNearbyStatusOK, nearby_platform_GetRingingInfo(&ringing_info)); - ASSERT_EQ(kCommand, ringing_info.components); - ASSERT_EQ(kTimeoutHigh * 256 + kTimeoutLow, ringing_info.timeout); - ASSERT_EQ(kRingingVolume, ringing_info.volume); -} - -TEST_F(SpotTest, DeactivateUnwantedTrackingProtectionMode_InValidRequest) { - std::vector request = {8, 16, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 10, 11, 12, 13, 14, 15, 16}; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - nearby_spot_SetUnwantedTrackingProtectionMode(true); - - ASSERT_THAT(kUnathenticated, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_TRUE(nearby_spot_GetUnwantedTrackingProtectionModeState()); - ASSERT_FALSE(HasSentNotification()); -} - -TEST_F(SpotTest, DectivateUnwantedTrackingProtectionMode_ValidRequest) { - std::vector request = {8, 16, 0x7b, 0x87, 0xef, - 0x56, 0xb5, 0x13, 0x9c, 0xb8}; - std::vector expected_response = {8, 8, 0xc7, 0x7e, 0x53, - 0x7c, 0x38, 0x82, 0xf7, 0xc2}; - APPEND_ARRAY(request, kSha256EikNonce); - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kNearbyStatusOK, - nearby_test_fakes_GattWrite(kBeaconActions, request.data(), - request.size())); - - ASSERT_TRUE(HasSentNotification()); - // Check the skip ringing authentication flag is reset - ASSERT_FALSE(nearby_spot_GetControlFlags()); - ASSERT_FALSE(nearby_spot_GetUnwantedTrackingProtectionModeState()); - ASSERT_THAT(expected_response, - ElementsAreArray( - nearby_test_fakes_GetGattNotifications().at(kBeaconActions))); -} - -TEST_F(SpotTest, ReuseNonce_RejectsSecondRequest) { - constexpr uint8_t kRequest[] = {1, 8, 0x3f, 0xcf, 0x0f, - 0x68, 0x1c, 0x54, 0xee, 0xee}; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - ASSERT_THAT(kNearbyStatusOK, nearby_test_fakes_GattWrite( - kBeaconActions, kRequest, sizeof(kRequest))); - - ASSERT_THAT(kUnathenticated, nearby_test_fakes_GattWrite( - kBeaconActions, kRequest, sizeof(kRequest))); -} - -TEST_F(SpotTest, RejectEmptyRequest) { - constexpr uint8_t kRequest[] = {}; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - ReadNonce(); - - ASSERT_THAT(kInvalidValue, nearby_test_fakes_GattWrite( - kBeaconActions, kRequest, sizeof(kRequest))); -} - -TEST_F(SpotTest, GetSecp160r1PublicKey) { - constexpr uint8_t kInput[32] = { - 0x1B, 0xB4, 0xAE, 0x82, 0x37, 0x95, 0x62, 0x1B, 0xF7, 0x90, 0x4B, - 0x00, 0x13, 0x59, 0x43, 0xD0, 0x0E, 0x7D, 0x06, 0xC8, 0x72, 0x1C, - 0x75, 0x74, 0xF4, 0x6D, 0x0C, 0xF2, 0x33, 0x3A, 0x5F, 0x88}; - uint8_t output[20]; - uint8_t hashed_field = 0; - constexpr uint8_t kExpectedOutput[20] = { - 0xB6, 0x63, 0x51, 0x83, 0x89, 0xF7, 0xE1, 0x4C, 0xEB, 0x76, - 0x20, 0xB1, 0xFB, 0xB2, 0xB7, 0x1A, 0xDD, 0x0E, 0x10, 0xC4}; - - ASSERT_EQ(kNearbyStatusOK, nearby_platform_GetSecp160r1PublicKey( - kInput, output, &hashed_field)); - ASSERT_THAT(kExpectedOutput, - ElementsAreArray(output, output + sizeof(output))); -} - -TEST_F(SpotTest, GetSecp160r1HashedFlagMask) { - constexpr uint8_t kInput[32] = { - 0x97, 0x35, 0xDC, 0x6B, 0xAB, 0xFA, 0x21, 0x14, 0xA6, 0x7D, 0x7D, - 0x7B, 0x01, 0xE6, 0xBD, 0x44, 0xEF, 0xE5, 0x9B, 0x58, 0xBD, 0x65, - 0x24, 0x71, 0x38, 0xBD, 0x4A, 0xE7, 0x38, 0x33, 0x7A, 0x96}; - - uint8_t output[20]; - uint8_t hashed_field = 0; - constexpr uint8_t kExpectedHashed = 0x51; - - ASSERT_EQ(kNearbyStatusOK, nearby_platform_GetSecp160r1PublicKey( - kInput, output, &hashed_field)); - - ASSERT_THAT(kExpectedHashed, hashed_field); -} - -#ifdef NEARBY_SPOT_BATTERY_LEVEL_INDICATION -TEST_F(SpotTest, SetAdvertisementWithNormalBattery) { - nearby_test_fakes_SetGetBatteryInfoResult(kNearbyStatusOK); - nearby_test_fakes_SetMainBatteryLevel(60); - uint8_t kExpectedAdvertisement[29]; - memcpy(kExpectedAdvertisement, kAdvertisement, 28); - kExpectedAdvertisement[28] = 0x8E; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - - ASSERT_EQ(kNearbyStatusOK, nearby_spot_SetAdvertisement(true)); - ASSERT_THAT(kExpectedAdvertisement, - ElementsAreArray(nearby_test_fakes_GetSpotAdvertisement())); -} - -TEST_F(SpotTest, SetAdvertisementWithLowBattery) { - nearby_test_fakes_SetGetBatteryInfoResult(kNearbyStatusOK); - nearby_test_fakes_SetMainBatteryLevel(20); - uint8_t kExpectedAdvertisement[29]; - memcpy(kExpectedAdvertisement, kAdvertisement, 28); - kExpectedAdvertisement[28] = 0x88; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - - ASSERT_EQ(kNearbyStatusOK, nearby_spot_SetAdvertisement(true)); - ASSERT_THAT(kExpectedAdvertisement, - ElementsAreArray(nearby_test_fakes_GetSpotAdvertisement())); -} - -TEST_F(SpotTest, SetAdvertisementWithCriticallyLowBattery) { - nearby_test_fakes_SetGetBatteryInfoResult(kNearbyStatusOK); - nearby_test_fakes_SetMainBatteryLevel(10); - uint8_t kExpectedAdvertisement[29]; - memcpy(kExpectedAdvertisement, kAdvertisement, 28); - kExpectedAdvertisement[28] = 0x8A; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - - ASSERT_EQ(kNearbyStatusOK, nearby_spot_SetAdvertisement(true)); - ASSERT_THAT(kExpectedAdvertisement, - ElementsAreArray(nearby_test_fakes_GetSpotAdvertisement())); -} - -TEST_F(SpotTest, - SetAdvertisementWithUnwantedTrackingProtectionAndNormalBattery) { - nearby_test_fakes_SetGetBatteryInfoResult(kNearbyStatusOK); - nearby_test_fakes_SetMainBatteryLevel(60); - uint8_t kExpectedAdvertisement[29]; - memcpy(kExpectedAdvertisement, kAdvertisement, 28); - // For Unwanted Tracking protection frame type is 0x41 - kExpectedAdvertisement[7] = 0x41; - kExpectedAdvertisement[28] = 0x8F; - SetEphemeralKey(); - SetOwnerKey(); - nearby_spot_Init(); - - nearby_spot_SetUnwantedTrackingProtectionMode(true); - ASSERT_EQ(kNearbyStatusOK, nearby_spot_SetAdvertisement(true)); - ASSERT_THAT(kExpectedAdvertisement, - ElementsAreArray(nearby_test_fakes_GetSpotAdvertisement())); -} -#endif /* NEARBY_SPOT_BATTERY_LEVEL_INDICATION */ - -#if NEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES -// Case NEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES=1 Unwanted Tracking Protection -// Mode=On -TEST_F(SpotTest, SetAdvertisementMultipleAddressOnUnwantedTrackingOn) { - uint64_t firstSpotAddress, secondSpotAddress, thirdSpotAddress, - fourthSpotAddress, fifthSpotAddress; - uint64_t firstBleAddress, secondBleAddress, thirdBleAddress, fourthBleAddress, - fifthBleAddress; - - nearby_fp_client_Init(NULL); - nearby_test_fakes_SetRandomNumber(31); - SetEphemeralKey(); - SetOwnerKey(); - // We need to reinitialize SPOT with the new ephemeral id. - nearby_spot_Init(); - nearby_fp_client_SetAdvertisement(NEARBY_FP_ADVERTISEMENT_SPOT); - - // 1) Initial. SPOT and BLE addresses should be same - firstSpotAddress = nearby_test_fakes_GetSpotAddress(); - firstBleAddress = nearby_platform_GetBleAddress(); - printf("firstSpotAddress=0x%lx firstBleAddress=0x%lx \n", firstSpotAddress, - firstBleAddress); - ASSERT_EQ(firstSpotAddress, firstBleAddress); - nearby_spot_SetUnwantedTrackingProtectionMode(true); - - // 2) At 20 min. SPOT and BLE addresses should be different - unsigned int next_time_ms = (20 * 60 * 1000); - nearby_test_fakes_SetCurrentTimeMs(next_time_ms); - secondSpotAddress = nearby_test_fakes_GetSpotAddress(); - secondBleAddress = nearby_platform_GetBleAddress(); - printf("secondSpotAddress=0x%lx secondBleAddress=0x%lx \n", secondSpotAddress, - secondBleAddress); - ASSERT_NE(secondSpotAddress, secondBleAddress); - - // 3) At 40 min. BLE address should be different than 2) - nearby_test_fakes_SetRandomNumber(32); - next_time_ms = (40 * 60 * 1000); // 40min - nearby_test_fakes_SetCurrentTimeMs(next_time_ms); - thirdBleAddress = nearby_platform_GetBleAddress(); - printf("secondBleAddress=0x%lx thirdBleAddress=0x%lx \n", secondBleAddress, - thirdBleAddress); - ASSERT_NE(secondBleAddress, thirdBleAddress); - - // 4) At 65 min. BLE address should be different than 3) - nearby_test_fakes_SetRandomNumber(33); - next_time_ms = (65 * 60 * 1000); // 65min - nearby_test_fakes_SetCurrentTimeMs(next_time_ms); - fourthBleAddress = nearby_platform_GetBleAddress(); - printf("thirdBleAddress=0x%lx fourthBleAddress=0x%lx \n", secondBleAddress, - fourthBleAddress); - ASSERT_NE(thirdBleAddress, fourthBleAddress); - - // 5) At 3 hr. SPOT address should be same as 2) as it's under 24 hr - // BLE address should be different than 4) - nearby_test_fakes_SetRandomNumber(34); - next_time_ms = (3 * 60 * 60 * 1000); // 3 hr - nearby_test_fakes_SetCurrentTimeMs(next_time_ms); - fifthBleAddress = nearby_platform_GetBleAddress(); - thirdSpotAddress = nearby_test_fakes_GetSpotAddress(); - printf("thirdSpotAddress=0x%lx fifthBleAddress=0x%lx\n", thirdSpotAddress, - fifthBleAddress); - ASSERT_EQ(secondSpotAddress, thirdSpotAddress); - ASSERT_NE(fourthBleAddress, fifthBleAddress); - - // 6) At 24hr+2min. SPOT address should be different than 5) - nearby_test_fakes_SetRandomNumber(35); - next_time_ms = - ADDRESS_ROTATION_PERIOD_UNWANTED_TRACKING_PROTECTION_MS + (2 * 60 * 1000); - nearby_test_fakes_SetCurrentTimeMs(next_time_ms); - fourthSpotAddress = nearby_test_fakes_GetSpotAddress(); - printf("fourthSpotAddress=0x%lx \n", fourthSpotAddress); - ASSERT_NE(thirdSpotAddress, fourthSpotAddress); - - // 7) At 48hr+2min. SPOT address should be different than 6) - nearby_test_fakes_SetRandomNumber(37); - next_time_ms = ADDRESS_ROTATION_PERIOD_UNWANTED_TRACKING_PROTECTION_MS * 2 + - (2 * 60 * 1000); - nearby_test_fakes_SetCurrentTimeMs(next_time_ms); - fifthSpotAddress = nearby_test_fakes_GetSpotAddress(); - printf("fifthSpotAddress=0x%lx \n", fifthSpotAddress); - ASSERT_NE(fourthSpotAddress, fifthSpotAddress); -} - -// Case NEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES=1 Unwanted Tracking Protection -// Mode=Off -TEST_F(SpotTest, SetAdvertisementMultipleAddressOnUnwantedTrackingOff) { - uint64_t firstSpotAddress, secondSpotAddress, thirdSpotAddress; - uint64_t firstBleAddress, secondBleAddress, thirdBleAddress; - - nearby_fp_client_Init(NULL); - nearby_test_fakes_SetRandomNumber(31); - SetEphemeralKey(); - SetOwnerKey(); - // We need to reinitialize SPOT with the new ephemeral id. - nearby_spot_Init(); - nearby_fp_client_SetAdvertisement(NEARBY_FP_ADVERTISEMENT_SPOT); - - nearby_spot_SetUnwantedTrackingProtectionMode(false); - - // 1) At 20 min. BLE and SPOT addr should be same - nearby_test_fakes_SetRandomNumber(32); - unsigned int next_time_ms = (20 * 60 * 1000); - nearby_test_fakes_SetCurrentTimeMs(next_time_ms); - firstSpotAddress = nearby_test_fakes_GetSpotAddress(); - firstBleAddress = nearby_platform_GetBleAddress(); - printf("firstSpotAddress=0x%lx firstBleAddress=0x%lx \n", firstSpotAddress, - firstBleAddress); - ASSERT_EQ(firstSpotAddress, firstBleAddress); - - // 2) At 40 min. BLE address should be different than 1. BLE and SPOT addr - // should be same - nearby_test_fakes_SetRandomNumber(33); - next_time_ms = (40 * 60 * 1000); - nearby_test_fakes_SetCurrentTimeMs(next_time_ms); - secondSpotAddress = nearby_test_fakes_GetSpotAddress(); - secondBleAddress = nearby_platform_GetBleAddress(); - printf("secondSpotAddress=0x%lx secondBleAddress=0x%lx \n", secondSpotAddress, - secondBleAddress); - ASSERT_EQ(secondSpotAddress, secondBleAddress); - ASSERT_NE(firstBleAddress, secondBleAddress); - - // 3) At 65 min. BLE address should be different than 2. BLE and SPOT addr - // should be same - nearby_test_fakes_SetRandomNumber(34); - next_time_ms = (65 * 60 * 1000); - nearby_test_fakes_SetCurrentTimeMs(next_time_ms); - thirdSpotAddress = nearby_test_fakes_GetSpotAddress(); - thirdBleAddress = nearby_platform_GetBleAddress(); - printf("thirdSpotAddress=0x%lx thirdBleAddress=0x%lx \n", thirdSpotAddress, - thirdBleAddress); - ASSERT_EQ(thirdSpotAddress, thirdBleAddress); - ASSERT_NE(secondBleAddress, thirdBleAddress); -} - -#else -// Case NEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES=0 Unwanted Tracking Protection -// Mode=On -TEST_F(SpotTest, SetAdvertisementMultipleAddressOffUnwantedTrackingOn) { - uint64_t firstSpotAddress, secondSpotAddress, thirdSpotAddress, - fourthSpotAddress; - uint64_t firstBleAddress, secondBleAddress, thirdBleAddress, fourthBleAddress; - - nearby_fp_client_Init(NULL); - nearby_test_fakes_SetRandomNumber(31); - SetEphemeralKey(); - SetOwnerKey(); - // We need to reinitialize SPOT with the new ephemeral id. - nearby_spot_Init(); - nearby_fp_client_SetAdvertisement(NEARBY_FP_ADVERTISEMENT_SPOT); - - nearby_spot_SetUnwantedTrackingProtectionMode(true); - // 1) Initial. SPOT addr should not be 0 - firstSpotAddress = nearby_test_fakes_GetSpotAddress(); - firstBleAddress = nearby_platform_GetBleAddress(); - printf("firstSpotAddress=0x%lx firstBleAddress=0x%lx \n", firstSpotAddress, - firstBleAddress); - ASSERT_NE(firstSpotAddress, 0); - - // 2) At 20 min. SPOT and BLE addresses should be same - unsigned int next_time_ms = (20 * 60 * 1000); - nearby_test_fakes_SetCurrentTimeMs(next_time_ms); - secondSpotAddress = nearby_test_fakes_GetSpotAddress(); - secondBleAddress = nearby_platform_GetBleAddress(); - printf("secondSpotAddress=0x%lx secondBleAddress=0x%lx \n", secondSpotAddress, - secondBleAddress); - ASSERT_EQ(secondBleAddress, secondSpotAddress); - - // 3) At 3 hr. SPOT and BLE addresses should be same. BLE addr should be same - // as 1) - nearby_test_fakes_SetRandomNumber(34); - next_time_ms = (3 * 60 * 60 * 1000); // 3 hr - nearby_test_fakes_SetCurrentTimeMs(next_time_ms); - thirdBleAddress = nearby_platform_GetBleAddress(); - thirdSpotAddress = nearby_test_fakes_GetSpotAddress(); - printf("thirdSpotAddress=0x%lx thirdBleAddress=0x%lx\n", thirdSpotAddress, - thirdBleAddress); - ASSERT_EQ(thirdBleAddress, thirdSpotAddress); - ASSERT_EQ(secondBleAddress, thirdBleAddress); - - // 4) At 24 hr + 2min. SPOT and BLE addresses should be same. BLE addr should - // be different than 2) - nearby_test_fakes_SetRandomNumber(35); - next_time_ms = - ADDRESS_ROTATION_PERIOD_UNWANTED_TRACKING_PROTECTION_MS + (2 * 60 * 1000); - nearby_test_fakes_SetCurrentTimeMs(next_time_ms); - fourthBleAddress = nearby_platform_GetBleAddress(); - fourthSpotAddress = nearby_test_fakes_GetSpotAddress(); - printf("fourthSpotAddress=0x%lx fourthBleAddress=0x%lx\n", fourthSpotAddress, - fourthBleAddress); - ASSERT_EQ(fourthBleAddress, fourthSpotAddress); - ASSERT_NE(thirdBleAddress, fourthBleAddress); -} - -// Case NEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES=0 Unwanted Tracking Protection -// Mode=Off -TEST_F(SpotTest, SetAdvertisementMultipleAddressOffUnwantedTrackingOff) { - uint64_t firstSpotAddress, secondSpotAddress, thirdSpotAddress; - uint64_t firstBleAddress, secondBleAddress, thirdBleAddress; - - nearby_fp_client_Init(NULL); - nearby_test_fakes_SetRandomNumber(31); - SetEphemeralKey(); - SetOwnerKey(); - // We need to reinitialize SPOT with the new ephemeral id. - nearby_spot_Init(); - nearby_fp_client_SetAdvertisement(NEARBY_FP_ADVERTISEMENT_SPOT); - nearby_spot_SetUnwantedTrackingProtectionMode(false); - - // 1) At 20 min. SPOT and BLE addresses should be same - unsigned int next_time_ms = (20 * 60 * 1000); - nearby_test_fakes_SetCurrentTimeMs(next_time_ms); - firstSpotAddress = nearby_test_fakes_GetSpotAddress(); - firstBleAddress = nearby_platform_GetBleAddress(); - printf("firstSpotAddress=0x%lx firstBleAddress=0x%lx \n", firstSpotAddress, - firstBleAddress); - ASSERT_EQ(firstSpotAddress, firstBleAddress); - - // 2) At 40 min. SPOT and BLE addresses should be same. BLE address should be - // different than 1) - nearby_test_fakes_SetRandomNumber(32); - next_time_ms = (40 * 60 * 1000); // 40min - nearby_test_fakes_SetCurrentTimeMs(next_time_ms); - secondBleAddress = nearby_platform_GetBleAddress(); - secondSpotAddress = nearby_test_fakes_GetSpotAddress(); - printf("secondBleAddress=0x%lx secondSpotAddress=0x%lx \n", secondBleAddress, - secondSpotAddress); - ASSERT_EQ(secondSpotAddress, secondBleAddress); - ASSERT_NE(firstBleAddress, secondBleAddress); - - // 3) At 65 min. SPOT and BLE addresses should be same. BLE address should be - // different than 2) - nearby_test_fakes_SetRandomNumber(33); - next_time_ms = (65 * 60 * 1000); // 65min - nearby_test_fakes_SetCurrentTimeMs(next_time_ms); - thirdBleAddress = nearby_platform_GetBleAddress(); - thirdSpotAddress = nearby_test_fakes_GetSpotAddress(); - printf("thirdBleAddress=0x%lx thirdSpotAddress=0x%lx \n", thirdBleAddress, - thirdSpotAddress); - ASSERT_EQ(thirdSpotAddress, thirdBleAddress); - ASSERT_NE(secondBleAddress, thirdBleAddress); -} - -#endif /* NEARBY_SUPPORT_MULTIPLE_BLE_ADDRESSES */ - -#endif /* NEARBY_FP_ENABLE_SPOT */ - -#pragma GCC diagnostic pop - -int main(int argc, char** argv) { - ::testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); -} diff --git a/embedded/common/source/mbedtls/mbedtls.c b/embedded/common/source/mbedtls/mbedtls.c index 01572458..e72b28b9 100644 --- a/embedded/common/source/mbedtls/mbedtls.c +++ b/embedded/common/source/mbedtls/mbedtls.c @@ -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; -} diff --git a/embedded/common/source/micro-ecc/Makefile b/embedded/common/source/micro-ecc/Makefile deleted file mode 100644 index 5f8d26e3..00000000 --- a/embedded/common/source/micro-ecc/Makefile +++ /dev/null @@ -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 \ No newline at end of file diff --git a/embedded/common/source/micro-ecc/micro-ecc.c b/embedded/common/source/micro-ecc/micro-ecc.c deleted file mode 100644 index d260265f..00000000 --- a/embedded/common/source/micro-ecc/micro-ecc.c +++ /dev/null @@ -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 -#include -#include - -#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; -} diff --git a/embedded/common/source/nearby_config.h b/embedded/common/source/nearby_config.h index 29d3e8e6..c425fc22 100644 --- a/embedded/common/source/nearby_config.h +++ b/embedded/common/source/nearby_config.h @@ -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 */ diff --git a/embedded/common/source/nearby_event.h b/embedded/common/source/nearby_event.h index 6ff66ca6..921696ef 100644 --- a/embedded/common/source/nearby_event.h +++ b/embedded/common/source/nearby_event.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 { diff --git a/embedded/common/source/nearby_fp_library.c b/embedded/common/source/nearby_fp_library.c index 24ddbef7..6c1a2a31 100644 --- a/embedded/common/source/nearby_fp_library.c +++ b/embedded/common/source/nearby_fp_library.c @@ -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); diff --git a/embedded/common/source/nearby_fp_library.h b/embedded/common/source/nearby_fp_library.h index 8d7aa504..6e44a930 100644 --- a/embedded/common/source/nearby_fp_library.h +++ b/embedded/common/source/nearby_fp_library.h @@ -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 // diff --git a/embedded/common/source/nearby_utils.c b/embedded/common/source/nearby_utils.c index ed1c4f8e..5fa665c3 100644 --- a/embedded/common/source/nearby_utils.c +++ b/embedded/common/source/nearby_utils.c @@ -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]; diff --git a/embedded/common/source/nearby_utils.h b/embedded/common/source/nearby_utils.h index 6ce421dc..5e24fba8 100644 --- a/embedded/common/source/nearby_utils.h +++ b/embedded/common/source/nearby_utils.h @@ -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! diff --git a/embedded/common/target/nearby.h b/embedded/common/target/nearby.h index f7d91805..79bbf15f 100644 --- a/embedded/common/target/nearby.h +++ b/embedded/common/target/nearby.h @@ -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; diff --git a/embedded/common/target/nearby_platform_battery.h b/embedded/common/target/nearby_platform_battery.h index 938db74c..f12f4d70 100644 --- a/embedded/common/target/nearby_platform_battery.h +++ b/embedded/common/target/nearby_platform_battery.h @@ -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 { diff --git a/embedded/common/target/nearby_platform_ble.h b/embedded/common/target/nearby_platform_ble.h index 20965aaf..db5e54e3 100644 --- a/embedded/common/target/nearby_platform_ble.h +++ b/embedded/common/target/nearby_platform_ble.h @@ -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. diff --git a/embedded/common/target/nearby_platform_os.h b/embedded/common/target/nearby_platform_os.h index 8871f304..0682addc 100644 --- a/embedded/common/target/nearby_platform_os.h +++ b/embedded/common/target/nearby_platform_os.h @@ -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 diff --git a/embedded/common/target/nearby_platform_persistence.h b/embedded/common/target/nearby_platform_persistence.h index bc7924e8..d18b8ed5 100644 --- a/embedded/common/target/nearby_platform_persistence.h +++ b/embedded/common/target/nearby_platform_persistence.h @@ -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(); diff --git a/embedded/common/target/nearby_platform_se.h b/embedded/common/target/nearby_platform_se.h index 971e3e69..d1e4f4e1 100644 --- a/embedded/common/target/nearby_platform_se.h +++ b/embedded/common/target/nearby_platform_se.h @@ -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. diff --git a/embedded/release_notes.md b/embedded/release_notes.md index bfc53e08..c19031e2 100644 --- a/embedded/release_notes.md +++ b/embedded/release_notes.md @@ -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). diff --git a/embedded/target/gLinux/config.mk b/embedded/target/gLinux/config.mk index 2c225694..f5aa00c5 100644 --- a/embedded/target/gLinux/config.mk +++ b/embedded/target/gLinux/config.mk @@ -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 \ No newline at end of file diff --git a/embedded/target/gLinux/rules.mk b/embedded/target/gLinux/rules.mk index 419b85f4..7724f20f 100644 --- a/embedded/target/gLinux/rules.mk +++ b/embedded/target/gLinux/rules.mk @@ -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) \