-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathaliro_state_control.cpp
More file actions
53 lines (41 loc) · 1.17 KB
/
aliro_state_control.cpp
File metadata and controls
53 lines (41 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* Copyright (c) 2025 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#include "aliro_state_control.h"
#include "aliro/init.h"
#include "reader.h"
#include <aliro/aliro.h>
#include <aliro/utils.h>
#include <cstdlib>
#include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(aliro);
namespace {
bool IsProvisioningComplete()
{
return DoorLock::Storage::Reader::IsIdentifierSet() && DoorLock::Storage::Reader::IsPrivateKeySet();
}
} // anonymous namespace
namespace DoorLock::AliroStateControl {
AliroError UpdateAliroState()
{
if (IsProvisioningComplete()) {
if (!IsAliroRunning()) {
const int startRc = AliroStart();
VerifyOrReturnStatus(startRc == EXIT_SUCCESS, ALIRO_ERROR_INTERNAL,
LOG_ERR("Failed to start Aliro: %d", startRc));
#ifdef CONFIG_DOOR_LOCK_BLE_UWB
} else {
ReturnErrorOnFailure(StartAliroAdvertising());
#endif // CONFIG_DOOR_LOCK_BLE_UWB
}
return ALIRO_NO_ERROR;
}
if (IsAliroRunning()) {
const int rc = AliroStop();
VerifyOrReturnStatus(rc == EXIT_SUCCESS, ALIRO_ERROR_INTERNAL, LOG_ERR("Failed to stop Aliro: %d", rc));
}
return ALIRO_NO_ERROR;
}
} // namespace DoorLock::AliroStateControl