1 /*
2  * SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /** @file
8  *  @brief Bluetooth Mesh Lighting Client Model APIs.
9  */
10 
11 #ifndef _LIGHTING_CLIENT_H_
12 #define _LIGHTING_CLIENT_H_
13 
14 #include "client_common.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 /* Light client model common structure */
21 typedef bt_mesh_client_user_data_t      bt_mesh_light_client_t;
22 typedef bt_mesh_client_internal_data_t  light_internal_data_t;
23 
24 /* Lighting Client Model Callback */
25 extern const struct bt_mesh_model_cb bt_mesh_lighting_client_cb;
26 
27 /* Light Lightness Client Model Context */
28 extern const struct bt_mesh_model_op bt_mesh_light_lightness_cli_op[];
29 
30 /** @def BLE_MESH_MODEL_LIGHT_LIGHTNESS_CLI
31  *
32  *  Define a new light lightness client model. Note that this API
33  *  needs to be repeated for each element which the application
34  *  wants to have a light lightness client model on.
35  *  @param cli_pub  Pointer to a unique struct bt_mesh_model_pub.
36  *  @param cli_data Pointer to a unique struct bt_mesh_light_lightness_cli.
37  *
38  *  @return New light lightness client model instance.
39  */
40 #define BLE_MESH_MODEL_LIGHT_LIGHTNESS_CLI(cli_pub, cli_data)   \
41         BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI,   \
42             bt_mesh_light_lightness_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb)
43 
44 typedef bt_mesh_client_user_data_t  bt_mesh_light_lightness_client_t;
45 
46 struct bt_mesh_light_lightness_status {
47     bool     op_en;             /* Indicate whether optional parameters included           */
48     uint16_t present_lightness; /* Present value of light lightness actual state           */
49     uint16_t target_lightness;  /* Target value of light lightness actual state (optional) */
50     uint8_t  remain_time;       /* Time to complete state transition (C.1)                 */
51 };
52 
53 struct bt_mesh_light_lightness_linear_status {
54     bool     op_en;             /* Indicate whether optional parameters included           */
55     uint16_t present_lightness; /* Present value of light lightness linear state           */
56     uint16_t target_lightness;  /* Target value of light lightness linear state (optional) */
57     uint8_t  remain_time;       /* Time to complete state transition (C.1)                 */
58 };
59 
60 struct bt_mesh_light_lightness_last_status {
61     uint16_t lightness; /* The value of the Light Lightness Last state */
62 };
63 
64 struct bt_mesh_light_lightness_default_status {
65     uint16_t lightness; /* The value of the Light Lightness default state */
66 };
67 
68 struct bt_mesh_light_lightness_range_status {
69     uint8_t  status_code; /* Status Code for the requesting message                  */
70     uint16_t range_min;   /* Value of range min field of light lightness range state */
71     uint16_t range_max;   /* Value of range max field of light lightness range state */
72 };
73 
74 struct bt_mesh_light_lightness_set {
75     bool     op_en;      /* Indicate whether optional parameters included */
76     uint16_t lightness;  /* Target value of light lightness actual state  */
77     uint8_t  tid;        /* Transaction Identifier                        */
78     uint8_t  trans_time; /* Time to complete state transition (optional)  */
79     uint8_t  delay;      /* Indicate message execution delay (C.1)        */
80 };
81 
82 struct bt_mesh_light_lightness_linear_set {
83     bool     op_en;      /* Indicate whether optional parameters included */
84     uint16_t lightness;  /* Target value of light lightness linear state  */
85     uint8_t  tid;        /* Transaction Identifier                        */
86     uint8_t  trans_time; /* Time to complete state transition (optional)  */
87     uint8_t  delay;      /* Indicate message execution delay (C.1)        */
88 };
89 
90 struct bt_mesh_light_lightness_default_set {
91     uint16_t lightness;  /* The value of the Light Lightness Default state */
92 };
93 
94 struct bt_mesh_light_lightness_range_set {
95     uint16_t range_min; /* Value of range min field of light lightness range state */
96     uint16_t range_max; /* Value of range max field of light lightness range state */
97 };
98 
99 /* Light CTL Client Model Context */
100 extern const struct bt_mesh_model_op bt_mesh_light_ctl_cli_op[];
101 
102 /** @def BLE_MESH_MODEL_LIGHT_CTL_CLI
103  *
104  *  Define a new light CTL client model. Note that this API needs
105  *  to be repeated for each element which the application wants to
106  *  have a light CTL client model on.
107  *  @param cli_pub  Pointer to a unique struct bt_mesh_model_pub.
108  *  @param cli_data Pointer to a unique struct bt_mesh_light_ctl_cli.
109  *
110  *  @return New light CTL client model instance.
111  */
112 #define BLE_MESH_MODEL_LIGHT_CTL_CLI(cli_pub, cli_data)     \
113         BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_CTL_CLI,     \
114             bt_mesh_light_ctl_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb)
115 
116 typedef bt_mesh_client_user_data_t  bt_mesh_light_ctl_client_t;
117 
118 struct bt_mesh_light_ctl_status {
119     bool     op_en;                   /* Indicate whether optional parameters included        */
120     uint16_t present_ctl_lightness;   /* Present value of light ctl lightness state           */
121     uint16_t present_ctl_temperature; /* Present value of light ctl temperature state         */
122     uint16_t target_ctl_lightness;    /* Target value of light ctl lightness state (optional) */
123     uint16_t target_ctl_temperature;  /* Target value of light ctl temperature state (C.1)    */
124     uint8_t  remain_time;             /* Time to complete state transition (C.1)              */
125 };
126 
127 struct bt_mesh_light_ctl_temperature_status {
128     bool     op_en;                   /* Indicate whether optional parameters included          */
129     uint16_t present_ctl_temperature; /* Present value of light ctl temperature state           */
130     uint16_t present_ctl_delta_uv;    /* Present value of light ctl delta UV state              */
131     uint16_t target_ctl_temperature;  /* Target value of light ctl temperature state (optional) */
132     uint16_t target_ctl_delta_uv;     /* Target value of light ctl delta UV state (C.1)         */
133     uint8_t  remain_time;             /* Time to complete state transition (C.1)                */
134 };
135 
136 struct bt_mesh_light_ctl_temperature_range_status {
137     uint8_t  status_code; /* Status code for the requesting message                                    */
138     uint16_t range_min;   /* Value of temperature range min field of light ctl temperature range state */
139     uint16_t range_max;   /* Value of temperature range max field of light ctl temperature range state */
140 };
141 
142 struct bt_mesh_light_ctl_default_status {
143     uint16_t lightness;   /* Value of light lightness default state   */
144     uint16_t temperature; /* Value of light temperature default state */
145     int16_t  delta_uv;    /* Value of light delta UV default state    */
146 };
147 
148 struct bt_mesh_light_ctl_set {
149     bool     op_en;           /* Indicate whether optional parameters included */
150     uint16_t ctl_lightness;   /* Target value of light ctl lightness state     */
151     uint16_t ctl_temperature; /* Target value of light ctl temperature state   */
152     int16_t  ctl_delta_uv;    /* Target value of light ctl delta UV state      */
153     uint8_t  tid;             /* Transaction Identifier                        */
154     uint8_t  trans_time;      /* Time to complete state transition (optional)  */
155     uint8_t  delay;           /* Indicate message execution delay (C.1)        */
156 };
157 
158 struct bt_mesh_light_ctl_temperature_set {
159     bool     op_en;           /* Indicate whether optional parameters included */
160     uint16_t ctl_temperature; /* Target value of light ctl temperature state   */
161     int16_t  ctl_delta_uv;    /* Target value of light ctl delta UV state      */
162     uint8_t  tid;             /* Transaction Identifier                        */
163     uint8_t  trans_time;      /* Time to complete state transition (optional)  */
164     uint8_t  delay;           /* Indicate message execution delay (C.1)        */
165 };
166 
167 struct bt_mesh_light_ctl_temperature_range_set {
168     uint16_t range_min; /* Value of temperature range min field of light ctl temperature range state */
169     uint16_t range_max; /* Value of temperature range max field of light ctl temperature range state */
170 };
171 
172 struct bt_mesh_light_ctl_default_set {
173     uint16_t lightness;   /* Value of light lightness default state   */
174     uint16_t temperature; /* Value of light temperature default state */
175     int16_t  delta_uv;    /* Value of light delta UV default state    */
176 };
177 
178 /* Light HSL Client Model Context */
179 extern const struct bt_mesh_model_op bt_mesh_light_hsl_cli_op[];
180 
181 /** @def BLE_MESH_MODEL_LIGHT_HSL_CLI
182  *
183  *  Define a new light HSL client model. Note that this API needs
184  *  to be repeated for each element which the application wants to
185  *  have a light HSL client model on.
186  *  @param cli_pub  Pointer to a unique struct bt_mesh_model_pub.
187  *  @param cli_data Pointer to a unique struct bt_mesh_light_hsl_cli.
188  *
189  *  @return New light HSL client model instance.
190  */
191 #define BLE_MESH_MODEL_LIGHT_HSL_CLI(cli_pub, cli_data)     \
192         BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_HSL_CLI,     \
193             bt_mesh_light_hsl_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb)
194 
195 typedef bt_mesh_client_user_data_t  bt_mesh_light_hsl_client_t;
196 
197 struct bt_mesh_light_hsl_status {
198     bool     op_en;          /* Indicate whether optional parameters included */
199     uint16_t hsl_lightness;  /* Present value of light hsl lightness state    */
200     uint16_t hsl_hue;        /* Present value of light hsl hue state          */
201     uint16_t hsl_saturation; /* Present value of light hsl saturation state   */
202     uint8_t  remain_time;    /* Time to complete state transition (optional)  */
203 };
204 
205 struct bt_mesh_light_hsl_target_status {
206     bool     op_en;                 /* Indicate whether optional parameters included */
207     uint16_t hsl_lightness_target;  /* Target value of light hsl lightness state     */
208     uint16_t hsl_hue_target;        /* Target value of light hsl hue state           */
209     uint16_t hsl_saturation_target; /* Target value of light hsl saturation state    */
210     uint8_t  remain_time;           /* Time to complete state transition (optional)  */
211 };
212 
213 struct bt_mesh_light_hsl_hue_status {
214     bool     op_en;       /* Indicate whether optional parameters included  */
215     uint16_t present_hue; /* Present value of light hsl hue state           */
216     uint16_t target_hue;  /* Target value of light hsl hue state (optional) */
217     uint8_t  remain_time; /* Time to complete state transition (C.1)   */
218 };
219 
220 struct bt_mesh_light_hsl_saturation_status {
221     bool     op_en;              /* Indicate whether optional parameters included         */
222     uint16_t present_saturation; /* Present value of light hsl saturation state           */
223     uint16_t target_saturation;  /* Target value of light hsl saturation state (optional) */
224     uint8_t  remain_time;        /* Time to complete state transition (C.1)               */
225 };
226 
227 struct bt_mesh_light_hsl_default_status {
228     uint16_t lightness;  /* Value of light lightness default state  */
229     uint16_t hue;        /* Value of light hue default state        */
230     uint16_t saturation; /* Value of light saturation default state */
231 };
232 
233 struct bt_mesh_light_hsl_range_status {
234     uint8_t  status_code;          /* Status code for the requesting message                                  */
235     uint16_t hue_range_min;        /* Value of hue range min field of light hsl hue range state               */
236     uint16_t hue_range_max;        /* Value of hue range max field of light hsl hue range state               */
237     uint16_t saturation_range_min; /* Value of saturation range min field of light hsl saturation range state */
238     uint16_t saturation_range_max; /* Value of saturation range max field of light hsl saturation range state */
239 };
240 
241 struct bt_mesh_light_hsl_set {
242     bool     op_en;          /* Indicate whether optional parameters included */
243     uint16_t hsl_lightness;  /* Target value of light hsl lightness state     */
244     uint16_t hsl_hue;        /* Target value of light hsl hue state           */
245     uint16_t hsl_saturation; /* Target value of light hsl saturation state    */
246     uint8_t  tid;            /* Transaction Identifier                        */
247     uint8_t  trans_time;     /* Time to complete state transition (optional)  */
248     uint8_t  delay;          /* Indicate message execution delay (C.1)        */
249 };
250 
251 struct bt_mesh_light_hsl_hue_set {
252     bool     op_en;      /* Indicate whether optional parameters included */
253     uint16_t hue;        /* Target value of light hsl hue state           */
254     uint8_t  tid;        /* Transaction Identifier                        */
255     uint8_t  trans_time; /* Time to complete state transition (optional)  */
256     uint8_t  delay;      /* Indicate message execution delay (C.1)        */
257 };
258 
259 struct bt_mesh_light_hsl_saturation_set {
260     bool     op_en;      /* Indicate whether optional parameters included */
261     uint16_t saturation; /* Target value of light hsl hue state           */
262     uint8_t  tid;        /* Transaction Identifier                        */
263     uint8_t  trans_time; /* Time to complete state transition (optional)  */
264     uint8_t  delay;      /* Indicate message execution delay (C.1)        */
265 };
266 
267 struct bt_mesh_light_hsl_default_set {
268     uint16_t lightness;  /* Value of light lightness default state  */
269     uint16_t hue;        /* Value of light hue default state        */
270     uint16_t saturation; /* Value of light saturation default state */
271 };
272 
273 struct bt_mesh_light_hsl_range_set {
274     uint16_t hue_range_min;        /* Value of hue range min field of light hsl hue range state               */
275     uint16_t hue_range_max;        /* Value of hue range max field of light hsl hue range state               */
276     uint16_t saturation_range_min; /* Value of saturation range min field of light hsl saturation range state */
277     uint16_t saturation_range_max; /* Value of saturation range max field of light hsl saturation range state */
278 };
279 
280 /* Light xyL Client Model Context */
281 extern const struct bt_mesh_model_op bt_mesh_light_xyl_cli_op[];
282 
283 /** @def BLE_MESH_MODEL_LIGHT_XYL_CLI
284  *
285  *  Define a new light xyL client model. Note that this API needs
286  *  to be repeated for each element which the application wants
287  *  to have a light xyL client model on.
288  *  @param cli_pub  Pointer to a unique struct bt_mesh_model_pub.
289  *  @param cli_data Pointer to a unique struct bt_mesh_light_xyl_cli.
290  *
291  *  @return New light xyL client model instance.
292  */
293 #define BLE_MESH_MODEL_LIGHT_XYL_CLI(cli_pub, cli_data)     \
294         BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_XYL_CLI,     \
295             bt_mesh_light_xyl_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb)
296 
297 typedef bt_mesh_client_user_data_t  bt_mesh_light_xyl_client_t;
298 
299 struct bt_mesh_light_xyl_status {
300     bool     op_en;         /* Indicate whether optional parameters included      */
301     uint16_t xyl_lightness; /* The present value of the Light xyL Lightness state */
302     uint16_t xyl_x;         /* The present value of the Light xyL x state         */
303     uint16_t xyl_y;         /* The present value of the Light xyL y state         */
304     uint8_t  remain_time;   /* Time to complete state transition (optional)       */
305 };
306 
307 struct bt_mesh_light_xyl_target_status {
308     bool     op_en;                /* Indicate whether optional parameters included     */
309     uint16_t target_xyl_lightness; /* The target value of the Light xyL Lightness state */
310     uint16_t target_xyl_x;         /* The target value of the Light xyL x state         */
311     uint16_t target_xyl_y;         /* The target value of the Light xyL y state         */
312     uint8_t  remain_time;          /* Time to complete state transition (optional)      */
313 };
314 
315 struct bt_mesh_light_xyl_default_status {
316     uint16_t lightness; /* The value of the Light Lightness Default state */
317     uint16_t xyl_x;     /* The value of the Light xyL x Default state     */
318     uint16_t xyl_y;     /* The value of the Light xyL y Default state     */
319 };
320 
321 struct bt_mesh_light_xyl_range_status {
322     uint8_t  status_code;     /* Status Code for the requesting message */
323     uint16_t xyl_x_range_min; /* The value of the xyL x Range Min field of the Light xyL x Range state */
324     uint16_t xyl_x_range_max; /* The value of the xyL x Range Max field of the Light xyL x Range state */
325     uint16_t xyl_y_range_min; /* The value of the xyL y Range Min field of the Light xyL y Range state */
326     uint16_t xyl_y_range_max; /* The value of the xyL y Range Max field of the Light xyL y Range state */
327 };
328 
329 struct bt_mesh_light_xyl_set {
330     bool     op_en;         /* Indicate whether optional parameters included     */
331     uint16_t xyl_lightness; /* The target value of the Light xyL Lightness state */
332     uint16_t xyl_x;         /* The target value of the Light xyL x state         */
333     uint16_t xyl_y;         /* The target value of the Light xyL y state         */
334     uint8_t  tid;           /* Transaction Identifier                            */
335     uint8_t  trans_time;    /* Time to complete state transition (optional)      */
336     uint8_t  delay;         /* Indicate message execution delay (C.1)            */
337 };
338 
339 struct bt_mesh_light_xyl_default_set {
340     uint16_t lightness; /* The value of the Light Lightness Default state */
341     uint16_t xyl_x;     /* The value of the Light xyL x Default state     */
342     uint16_t xyl_y;     /* The value of the Light xyL y Default state     */
343 };
344 
345 struct bt_mesh_light_xyl_range_set {
346     uint16_t xyl_x_range_min; /* The value of the xyL x Range Min field of the Light xyL x Range state */
347     uint16_t xyl_x_range_max; /* The value of the xyL x Range Max field of the Light xyL x Range state */
348     uint16_t xyl_y_range_min; /* The value of the xyL y Range Min field of the Light xyL y Range state */
349     uint16_t xyl_y_range_max; /* The value of the xyL y Range Max field of the Light xyL y Range state */
350 };
351 
352 /* Light LC Client Model Context */
353 extern const struct bt_mesh_model_op bt_mesh_light_lc_cli_op[];
354 
355 /** @def BLE_MESH_MODEL_LIGHT_LC_CLI
356  *
357  *  Define a new light lc client model. Note that this API needs
358  *  to be repeated for each element which the application wants
359  *  to have a light lc client model on.
360  *  @param cli_pub  Pointer to a unique struct bt_mesh_model_pub.
361  *  @param cli_data Pointer to a unique struct bt_mesh_light_lc_cli.
362  *
363  *  @return New light lc client model instance.
364  */
365 #define BLE_MESH_MODEL_LIGHT_LC_CLI(cli_pub, cli_data)      \
366         BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_LC_CLI,      \
367             bt_mesh_light_lc_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb)
368 
369 typedef bt_mesh_client_user_data_t  bt_mesh_light_lc_client_t;
370 
371 struct bt_mesh_light_lc_mode_status {
372     uint8_t mode; /* The present value of the Light LC Mode state */
373 };
374 
375 struct bt_mesh_light_lc_om_status {
376     uint8_t mode; /* The present value of the Light LC Occupancy Mode state */
377 };
378 
379 struct bt_mesh_light_lc_light_onoff_status {
380     bool    op_en;               /* Indicate whether optional parameters included                 */
381     uint8_t present_light_onoff; /* The present value of the Light LC Light OnOff state           */
382     uint8_t target_light_onoff;  /* The target value of the Light LC Light OnOff state (Optional) */
383     uint8_t remain_time;         /* Time to complete state transition (C.1)                       */
384 };
385 
386 struct bt_mesh_light_lc_property_status {
387     uint16_t light_lc_property_id;  /* Property ID identifying a Light LC Property */
388     struct net_buf_simple *light_lc_property_value; /* Raw value for the Light LC Property */
389 };
390 
391 struct bt_mesh_light_lc_mode_set {
392     uint8_t mode; /* The target value of the Light LC Mode state */
393 };
394 
395 struct bt_mesh_light_lc_om_set {
396     uint8_t mode; /* The target value of the Light LC Occupancy Mode state */
397 };
398 
399 struct bt_mesh_light_lc_light_onoff_set {
400     bool    op_en;       /* Indicate whether optional parameters included      */
401     uint8_t light_onoff; /* The target value of the Light LC Light OnOff state */
402     uint8_t tid;         /* Transaction Identifier                             */
403     uint8_t trans_time;  /* Time to complete state transition (optional)       */
404     uint8_t delay;       /* Indicate message execution delay (C.1)             */
405 };
406 
407 struct bt_mesh_light_lc_property_get {
408     uint16_t light_lc_property_id;  /* Property ID identifying a Light LC Property */
409 };
410 
411 struct bt_mesh_light_lc_property_set {
412     uint16_t light_lc_property_id;  /* Property ID identifying a Light LC Property */
413     struct net_buf_simple *light_lc_property_value; /* Raw value for the Light LC Property */
414 };
415 
416 /**
417  * @brief This function is called to get light states.
418  *
419  * @param[in]  common: Message common information structure
420  * @param[in]  get:    Pointer of light get message value
421  *
422  * @return Zero-success, other-fail
423  */
424 int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common, void *get);
425 
426 /**
427  * @brief This function is called to set light states.
428  *
429  * @param[in]  common: Message common information structure
430  * @param[in]  set:    Pointer of light set message value
431  *
432  * @return Zero-success, other-fail
433  */
434 int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void *set);
435 
436 #ifdef __cplusplus
437 }
438 #endif
439 
440 #endif /* _LIGHTING_CLIENT_H_ */
441