1 // Copyright 2017-2019 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "mesh_common.h"
16 #include "server_common.h"
17 #include "device_property.h"
18 
19 static struct bt_mesh_dev_prop {
20     uint16_t prop_id;
21     uint8_t  len;
22 } device_properties[] = {
23     { BLE_MESH_INVALID_DEVICE_PROPERTY_ID,                               0xFF }, /* Prohibited */
24     { BLE_MESH_AVERAGE_AMBIENT_TEMPERATURE_IN_A_PERIOD_OF_DAY,           0x03 },
25     { BLE_MESH_AVERAGE_INPUT_CURRENT,                                    0x03 },
26     { BLE_MESH_AVERAGE_INPUT_VOLTAGE,                                    0x03 },
27     { BLE_MESH_AVERAGE_OUTPUT_CURRENT,                                   0x03 },
28     { BLE_MESH_AVERAGE_OUTPUT_VOLTAGE,                                   0x03 },
29     { BLE_MESH_CENTER_BEAM_INTENSITY_AT_FULL_POWER,                      0x02 },
30     { BLE_MESH_CHROMATICITY_TOLERANCE,                                   0x01 },
31     { BLE_MESH_COLOR_RENDERING_INDEX_R9,                                 0x01 },
32     { BLE_MESH_COLOR_RENDERING_INDEX_RA,                                 0x01 },
33     { BLE_MESH_DEVICE_APPEARANCE,                                        0x02 },
34     { BLE_MESH_DEVICE_COUNTRY_OF_ORIGIN,                                 0x02 },
35     { BLE_MESH_DEVICE_DATE_OF_MANUFACTURE,                               0x03 },
36     { BLE_MESH_DEVICE_ENERGY_USE_SINCE_TURN_ON,                          0x03 },
37     { BLE_MESH_DEVICE_FIRMWARE_REVISION,                                 0x08 },
38     { BLE_MESH_DEVICE_GLOBAL_TRADE_ITEM_NUMBER,                          0x06 },
39     { BLE_MESH_DEVICE_HARDWARE_REVISION,                                 0x10 },
40     { BLE_MESH_DEVICE_MANUFACTURER_NAME,                                 0x24 },
41     { BLE_MESH_DEVICE_MODEL_NUMBER,                                      0x18 },
42     { BLE_MESH_DEVICE_OPERATING_TEMPERATURE_RANGE_SPECIFICATION,         0x04 },
43     { BLE_MESH_DEVICE_OPERATING_TEMPERATURE_STATISTICAL_VALUES,          0x09 },
44     { BLE_MESH_DEVICE_OVER_TEMPERATURE_EVENT_STATISTICS,                 0x06 },
45     { BLE_MESH_DEVICE_POWER_RANGE_SPECIFICATION,                         0x09 },
46     { BLE_MESH_DEVICE_RUNTIME_SINCE_TURN_ON,                             0x03 },
47     { BLE_MESH_DEVICE_RUNTIME_WARRANTY,                                  0x03 },
48     { BLE_MESH_DEVICE_SERIAL_NUMBER,                                     0x10 },
49     { BLE_MESH_DEVICE_SOFTWARE_REVISION,                                 0x08 },
50     { BLE_MESH_DEVICE_UNDER_TEMPERATURE_EVENT_STATISTICS,                0x06 },
51     { BLE_MESH_INDOOR_AMBIENT_TEMPERATURE_STATISTICAL_VALUES,            0x05 },
52     { BLE_MESH_INITIAL_CIE_1931_CHROMATICITY_COORDINATES,                0x04 },
53     { BLE_MESH_INITIAL_CORRELATED_COLOR_TEMPERATURE,                     0x02 },
54     { BLE_MESH_INITIAL_LUMINOUS_FLUX,                                    0x02 },
55     { BLE_MESH_INITIAL_PLANCKIAN_DISTANCE,                               0x02 },
56     { BLE_MESH_INPUT_CURRENT_RANGE_SPECIFICATION,                        0x06 },
57     { BLE_MESH_INPUT_CURRENT_STATISTICS,                                 0x09 },
58     { BLE_MESH_INPUT_OVER_CURRENT_EVENT_STATISTICS,                      0x06 },
59     { BLE_MESH_INPUT_OVER_RIPPLE_VOLTAGE_EVENT_STATISTICS,               0x06 },
60     { BLE_MESH_INPUT_OVER_VOLTAGE_EVENT_STATISTICS,                      0x06 },
61     { BLE_MESH_INPUT_UNDER_CURRENT_EVENT_STATISTICS,                     0x06 },
62     { BLE_MESH_INPUT_UNDER_VOLTAGE_EVENT_STATISTICS,                     0x06 },
63     { BLE_MESH_INPUT_VOLTAGE_RANGE_SPECIFICATION,                        0x06 },
64     { BLE_MESH_INPUT_VOLTAGE_RIPPLE_SPECIFICATION,                       0x01 },
65     { BLE_MESH_INPUT_VOLTAGE_STATISTICS,                                 0x09 },
66     { BLE_MESH_LIGHT_CONTROL_AMBIENT_LUXLEVEL_ON,                        0x03 },
67     { BLE_MESH_LIGHT_CONTROL_AMBIENT_LUXLEVEL_PROLONG,                   0x03 },
68     { BLE_MESH_LIGHT_CONTROL_AMBIENT_LUXLEVEL_STANDBY,                   0x03 },
69     { BLE_MESH_LIGHT_CONTROL_LIGHTNESS_ON,                               0x02 },
70     { BLE_MESH_LIGHT_CONTROL_LIGHTNESS_PROLONG,                          0x02 },
71     { BLE_MESH_LIGHT_CONTROL_LIGHTNESS_STANDBY,                          0x02 },
72     { BLE_MESH_LIGHT_CONTROL_REGULATOR_ACCURACY,                         0x01 },
73     { BLE_MESH_LIGHT_CONTROL_REGULATOR_KID,                              0x04 },
74     { BLE_MESH_LIGHT_CONTROL_REGULATOR_KIU,                              0x04 },
75     { BLE_MESH_LIGHT_CONTROL_REGULATOR_KPD,                              0x04 },
76     { BLE_MESH_LIGHT_CONTROL_REGULATOR_KPU,                              0x04 },
77     { BLE_MESH_LIGHT_CONTROL_TIME_FADE,                                  0x03 },
78     { BLE_MESH_LIGHT_CONTROL_TIME_FADE_ON,                               0x03 },
79     { BLE_MESH_LIGHT_CONTROL_TIME_FADE_STANDBY_AUTO,                     0x03 },
80     { BLE_MESH_LIGHT_CONTROL_TIME_FADE_STANDBY_MANUAL,                   0x03 },
81     { BLE_MESH_LIGHT_CONTROL_TIME_OCCUPANCY_DELAY,                       0x03 },
82     { BLE_MESH_LIGHT_CONTROL_TIME_PROLONG,                               0x03 },
83     { BLE_MESH_LIGHT_CONTROL_TIME_RUN_ON,                                0x03 },
84     { BLE_MESH_LUMEN_MAINTENANCE_FACTOR,                                 0x01 },
85     { BLE_MESH_LUMINOUS_EFFICACY,                                        0x02 },
86     { BLE_MESH_LUMINOUS_ENERGY_SINCE_TURN_ON,                            0x03 },
87     { BLE_MESH_LUMINOUS_EXPOSURE,                                        0x03 },
88     { BLE_MESH_LUMINOUS_FLUX_RANGE,                                      0x04 },
89     { BLE_MESH_MOTION_SENSED,                                            0x01 },
90     { BLE_MESH_MOTION_THRESHOLD,                                         0x01 },
91     { BLE_MESH_OPEN_CIRCUIT_EVENT_STATISTICS,                            0x06 },
92     { BLE_MESH_OUTDOOR_STATISTICAL_VALUES,                               0x05 },
93     { BLE_MESH_OUTPUT_CURRENT_RANGE,                                     0x04 },
94     { BLE_MESH_OUTPUT_CURRENT_STATISTICS,                                0x09 },
95     { BLE_MESH_OUTPUT_RIPPLE_VOLTAGE_SPECIFICATION,                      0x01 },
96     { BLE_MESH_OUTPUT_VOLTAGE_RANGE,                                     0x06 },
97     { BLE_MESH_OUTPUT_VOLTAGE_STATISTICS,                                0x09 },
98     { BLE_MESH_OVER_OUTPUT_RIPPLE_VOLTAGE_EVENT_STATISTICS,              0x06 },
99     { BLE_MESH_PEOPLE_COUNT,                                             0x02 },
100     { BLE_MESH_PRESENCE_DETECTED,                                        0x01 },
101     { BLE_MESH_PRESENT_AMBIENT_LIGHT_LEVEL,                              0x03 },
102     { BLE_MESH_PRESENT_AMBIENT_TEMPERATURE,                              0x01 },
103     { BLE_MESH_PRESENT_CIE_1931_CHROMATICITY,                            0x04 },
104     { BLE_MESH_PRESENT_CORRELATED_COLOR_TEMPERATURE,                     0x02 },
105     { BLE_MESH_PRESENT_DEVICE_INPUT_POWER,                               0x03 },
106     { BLE_MESH_PRESENT_DEVICE_OPERATING_EFFICIENCY,                      0x01 },
107     { BLE_MESH_PRESENT_DEVICE_OPERATING_TEMPERATURE,                     0x02 },
108     { BLE_MESH_PRESENT_ILLUMINANCE,                                      0x03 },
109     { BLE_MESH_PRESENT_INDOOR_AMBIENT_TEMPERATURE,                       0x01 },
110     { BLE_MESH_PRESENT_INPUT_CURRENT,                                    0x02 },
111     { BLE_MESH_PRESENT_INPUT_RIPPLE_VOLTAGE,                             0x01 },
112     { BLE_MESH_PRESENT_INPUT_VOLTAGE,                                    0x02 },
113     { BLE_MESH_PRESENT_LUMINOUS_FLUX,                                    0x02 },
114     { BLE_MESH_PRESENT_OUTDOOR_AMBIENT_TEMPERATURE,                      0x01 },
115     { BLE_MESH_PRESENT_OUTPUT_CURRENT,                                   0x02 },
116     { BLE_MESH_PRESENT_OUTPUT_VOLTAGE,                                   0x02 },
117     { BLE_MESH_PRESENT_PLANCKIAN_DISTANCE,                               0x02 },
118     { BLE_MESH_PRESENT_RELATIVE_OUTPUT_RIPPLE_VOLTAGE,                   0x01 },
119     { BLE_MESH_RELATIVE_DEVICE_ENERGY_USE_IN_A_PERIOD_OF_DAY,            0x05 },
120     { BLE_MESH_RELATIVE_DEVICE_RUNTIME_IN_A_GENERIC_LEVEL_RANGE,         0x05 },
121     { BLE_MESH_RELATIVE_EXPOSURE_TIME_IN_AN_ILLUMINANCE_RANGE,           0x05 },
122     { BLE_MESH_RELATIVE_RUNTIME_IN_A_CORRELATED_COLOR_TEMPERATURE_RANGE, 0x03 },
123     { BLE_MESH_RELATIVE_RUNTIME_IN_A_DEVICE_OPERATING_TEMPERATURE_RANGE, 0x03 },
124     { BLE_MESH_RELATIVE_RUNTIME_IN_AN_INPUT_CURRENT_RANGE,               0x05 },
125     { BLE_MESH_RELATIVE_RUNTIME_IN_AN_INPUT_VOLTAGE_RANGE,               0x05 },
126     { BLE_MESH_SHORT_CIRCUIT_EVENT_STATISTICS,                           0x06 },
127     { BLE_MESH_TIME_SINCE_MOTION_SENSED,                                 0x02 },
128     { BLE_MESH_TIME_SINCE_PRESENCE_DETECTED,                             0x02 },
129     { BLE_MESH_TOTAL_DEVICE_ENERGY_USE,                                  0x03 },
130     { BLE_MESH_TOTAL_DEVICE_OFF_ON_CYCLES,                               0x03 },
131     { BLE_MESH_TOTAL_DEVICE_POWER_ON_CYCLES,                             0x03 },
132     { BLE_MESH_TOTAL_DEVICE_POWER_ON_TIME,                               0x03 },
133     { BLE_MESH_TOTAL_DEVICE_RUNTIME,                                     0x03 },
134     { BLE_MESH_TOTAL_LIGHT_EXPOSURE_TIME,                                0x03 },
135     { BLE_MESH_TOTAL_LUMINOUS_ENERGY,                                    0x03 },
136     { BLE_MESH_DESIRED_AMBIENT_TEMPERATURE,                              0x01 },
137     { BLE_MESH_PRECISE_TOTAL_DEVICE_ENERGY_USE,                          0x04 },
138     { BLE_MESH_POWER_FACTOR,                                             0x01 },
139     { BLE_MESH_SENSOR_GAIN,                                              0x04 },
140     { BLE_MESH_PRECISE_PRESENT_AMBIENT_TEMPERATURE,                      0x02 },
141     { BLE_MESH_PRESENT_AMBIENT_RELATIVE_HUMIDITY,                        0x02 },
142     { BLE_MESH_PRESENT_AMBIENT_CARBON_DIOXIDE_CONCENTRATION,             0x02 },
143     { BLE_MESH_PRESENT_AMBIENT_VOLATILE_ORGANIC_COMPOUNDS_CONCENTRATION, 0x02 },
144     { BLE_MESH_PRESENT_AMBIENT_NOISE,                                    0x01 },
145     { 0x007A,                                                            0xFF }, /* Not defined */
146     { 0x007B,                                                            0xFF }, /* Not defined */
147     { 0x007C,                                                            0xFF }, /* Not defined */
148     { 0x007D,                                                            0xFF }, /* Not defined */
149     { 0x007E,                                                            0xFF }, /* Not defined */
150     { 0x007F,                                                            0xFF }, /* Not defined */
151     { BLE_MESH_ACTIVE_ENERGY_LOADSIDE,                                   0x04 },
152     { BLE_MESH_ACTIVE_POWER_LOADSIDE,                                    0x03 },
153     { BLE_MESH_AIR_PRESSURE,                                             0x04 },
154     { BLE_MESH_APPARENT_ENERGY,                                          0x04 },
155     { BLE_MESH_APPARENT_POWER,                                           0x03 },
156     { BLE_MESH_APPARENT_WIND_DIRECTION,                                  0x02 },
157     { BLE_MESH_APPARENT_WIND_SPEED,                                      0x02 },
158     { BLE_MESH_DEW_POINT,                                                0x01 },
159     { BLE_MESH_EXTERNAL_SUPPLY_VOLTAGE,                                  0x03 },
160     { BLE_MESH_EXTERNAL_SUPPLY_VOLTAGE_FREQUENCY,                        0x02 },
161     { BLE_MESH_GUST_FACTOR,                                              0x01 },
162     { BLE_MESH_HEAT_INDEX,                                               0x01 },
163     { BLE_MESH_LIGHT_DISTRIBUTION,                                       0x01 },
164     { BLE_MESH_LIGHT_SOURCE_CURRENT,                                     0x03 },
165     { BLE_MESH_LIGHT_SOURCE_ON_TIME_NOT_RESETTABLE,                      0x04 },
166     { BLE_MESH_LIGHT_SOURCE_ON_TIME_RESETTABLE,                          0x04 },
167     { BLE_MESH_LIGHT_SOURCE_OPEN_CIRCUIT_STATISTICS,                     0x06 },
168     { BLE_MESH_LIGHT_SOURCE_OVERALL_FAILURES_STATISTICS,                 0x06 },
169     { BLE_MESH_LIGHT_SOURCE_SHORT_CIRCUIT_STATISTICS,                    0x06 },
170     { BLE_MESH_LIGHT_SOURCE_START_COUNTER_RESETTABLE,                    0x03 },
171     { BLE_MESH_LIGHT_SOURCE_TEMPERATURE,                                 0x02 },
172     { BLE_MESH_LIGHT_SOURCE_THERMAL_DERATING_STATISTICS,                 0x06 },
173     { BLE_MESH_LIGHT_SOURCE_THERMAL_SHUTDOWN_STATISTICS,                 0x06 },
174     { BLE_MESH_LIGHT_SOURCE_TOTAL_POWER_ON_CYCLES,                       0x03 },
175     { BLE_MESH_LIGHT_SOURCE_VOLTAGE,                                     0x03 },
176     { BLE_MESH_LUMINAIRE_COLOR,                                          0x18 },
177     { BLE_MESH_LUMINAIRE_IDENTIFICATION_NUMBER,                          0x18 },
178     { BLE_MESH_LUMINAIRE_MANUFACTURER_GTIN,                              0x06 },
179     { BLE_MESH_LUMINAIRE_NOMINAL_INPUT_POWER,                            0x03 },
180     { BLE_MESH_LUMINAIRE_NOMINAL_MAXIMUM_AC_MAINS_VOLTAGE,               0x02 },
181     { BLE_MESH_LUMINAIRE_NOMINAL_MINIMUM_AC_MAINS_VOLTAGE,               0x02 },
182     { BLE_MESH_LUMINAIRE_POWER_AT_MINIMUM_DIM_LEVEL,                     0x03 },
183     { BLE_MESH_LUMINAIRE_TIME_OF_MANUFACTURE,                            0x03 },
184     { BLE_MESH_MAGNETIC_DECLINATION,                                     0x02 },
185     { BLE_MESH_MAGNETIC_FLUX_DENSITY_2D,                                 0x04 },
186     { BLE_MESH_MAGNETIC_FLUX_DENSITY_3D,                                 0x06 },
187     { BLE_MESH_NOMINAL_LIGHT_OUTPUT,                                     0x03 },
188     { BLE_MESH_OVERALL_FAILURE_CONDITION,                                0x06 },
189     { BLE_MESH_POLLEN_CONCENTRATION,                                     0x03 },
190     { BLE_MESH_PRESENT_INDOOR_RELATIVE_HUMIDITY,                         0x02 },
191     { BLE_MESH_PRESENT_OUTDOOR_RELATIVE_HUMIDITY,                        0x02 },
192     { BLE_MESH_PRESSURE,                                                 0x04 },
193     { BLE_MESH_RAINFALL,                                                 0x02 },
194     { BLE_MESH_RATED_MEDIAN_USEFUL_LIFE_OF_LUMINAIRE,                    0x03 },
195     { BLE_MESH_RATED_MEDIAN_USEFUL_LIGHT_SOURCE_STARTS,                  0x03 },
196     { BLE_MESH_REFERENCE_TEMPERATURE,                                    0x02 },
197     { BLE_MESH_TOTAL_DEVICE_STARTS,                                      0x03 },
198     { BLE_MESH_TRUE_WIND_DIRECTION,                                      0x02 },
199     { BLE_MESH_TRUE_WIND_SPEED,                                          0x02 },
200     { BLE_MESH_UV_INDEX,                                                 0x01 },
201     { BLE_MESH_WIND_CHILL,                                               0x01 },
202     { BLE_MESH_LIGHT_SOURCE_TYPE,                                        0x01 },
203     { BLE_MESH_LUMINAIRE_IDENTIFICATION_STRING,                          0x40 },
204     { BLE_MESH_OUTPUT_POWER_LIMITATION,                                  0x06 },
205     { BLE_MESH_THERMAL_DERATING,                                         0x06 },
206     { BLE_MESH_OUTPUT_CURRENT_PERCENT,                                   0x01 },
207 };
208 
bt_mesh_get_dev_prop_len(uint16_t prop_id)209 uint8_t bt_mesh_get_dev_prop_len(uint16_t prop_id)
210 {
211     if (prop_id > BLE_MESH_OUTPUT_CURRENT_PERCENT) {
212         BT_ERR("Unknown Device Property ID 0x%04x", prop_id);
213         return UINT8_MAX;
214     }
215 
216     return device_properties[prop_id].len;
217 }
218