forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProvisionStorageCustom.cpp
129 lines (112 loc) · 3.09 KB
/
ProvisionStorageCustom.cpp
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Copyright (c) 2024 Project CHIP Authors
* All rights reserved.
*
* 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
*
* http://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 <algorithm>
#include <lib/support/CodeUtils.h>
#include <platform/silabs/provision/ProvisionStorage.h>
#include <string.h>
namespace chip {
namespace DeviceLayer {
namespace Silabs {
namespace Provision {
namespace {
constexpr uint8_t kExample1 = 0x0001;
constexpr uint8_t kExample2 = 0x0002;
uint8_t sExample1 = 0;
uint8_t sExample2[32] = { 0 };
} // namespace
CHIP_ERROR CustomStorage::Set(uint16_t id, const uint8_t * value)
{
switch (id)
{
case kExample1:
sExample1 = (nullptr == value) ? 0 : *value;
break;
default:
return CHIP_ERROR_UNKNOWN_RESOURCE_ID;
}
return CHIP_NO_ERROR;
}
CHIP_ERROR CustomStorage::Get(uint16_t id, uint8_t & value)
{
switch (id)
{
case kExample1:
value = sExample1;
break;
default:
return CHIP_ERROR_UNKNOWN_RESOURCE_ID;
}
return CHIP_NO_ERROR;
}
CHIP_ERROR CustomStorage::Set(uint16_t id, const uint16_t * value)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}
CHIP_ERROR CustomStorage::Get(uint16_t id, uint16_t & value)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}
CHIP_ERROR CustomStorage::Set(uint16_t id, const uint32_t * value)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}
CHIP_ERROR CustomStorage::Get(uint16_t id, uint32_t & value)
{
return CHIP_ERROR_NOT_IMPLEMENTED;
}
CHIP_ERROR CustomStorage::Set(uint16_t id, const uint64_t * value)
{
return CHIP_ERROR_UNKNOWN_RESOURCE_ID;
}
CHIP_ERROR CustomStorage::Get(uint16_t id, uint64_t & value)
{
return CHIP_ERROR_UNKNOWN_RESOURCE_ID;
}
CHIP_ERROR CustomStorage::Set(uint16_t id, const uint8_t * value, size_t size)
{
switch (id)
{
case kExample2:
memset(sExample2, 0x00, sizeof(sExample2));
if (nullptr != value)
{
memcpy(sExample2, value, std::min(size, sizeof(sExample2)));
}
break;
default:
return CHIP_ERROR_UNKNOWN_RESOURCE_ID;
}
return CHIP_NO_ERROR;
}
CHIP_ERROR CustomStorage::Get(uint16_t id, uint8_t * value, size_t max_size, size_t & size)
{
VerifyOrReturnError((nullptr != value) && (max_size > 0), CHIP_ERROR_INVALID_ARGUMENT);
switch (id)
{
case kExample2:
size = std::min(max_size, sizeof(sExample2));
memcpy(value, sExample2, size);
break;
default:
return CHIP_ERROR_UNKNOWN_RESOURCE_ID;
}
return CHIP_NO_ERROR;
}
} // namespace Provision
} // namespace Silabs
} // namespace DeviceLayer
} // namespace chip