081bd0bb91a8e129ba0cdb90644932eddfaf77cb
[platform/core/connectivity/bluetooth-frwk.git] / include / bluetooth-mesh-api.h
1 /*
2  * Bluetooth-frwk
3  *
4  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
5  *
6  * @author: Anupam Roy (anupam.r@samsung.com)
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *              http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #ifndef __BLUETOOTH_MESH_API_H
23 #define __BLUETOOTH_MESH_API_H
24
25 #include <stdint.h>
26 #include <glib.h>
27 #include <dlog.h>
28
29 #include <bluetooth-api.h>
30
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 #define BLUETOOTH_MESH_NETWORK_NAME_STRING_MAX  100
37 #define BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH       32
38 #define BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH      16
39 #define BLUETOOTH_MESH_APP_UNIQUE_CRED_STRING_LENGTH    50
40 #define BLUETOOTH_MESH_AUTH_VALUE_LENGTH_MAX    50
41 #define BLUETOOTH_MESH_MODEL_MSG_LENGTH_MAX     32
42
43 typedef enum {
44         BLUETOOTH_MESH_NODE_KEY_ADD,
45         BLUETOOTH_MESH_NODE_KEY_UPDATE,
46         BLUETOOTH_MESH_NODE_KEY_DELETE,
47 } bluetooth_mesh_node_key_conf_e;
48
49 typedef enum {
50         BLUETOOTH_MESH_MODEL_SUB_ADD,
51         BLUETOOTH_MESH_MODEL_SUB_DELETE,
52         BLUETOOTH_MESH_MODEL_SUB_DELETE_ALL,
53         BLUETOOTH_MESH_MODEL_SUB_OVERWRITE,
54 } bluetooth_mesh_model_sub_op_e;
55
56 typedef struct {
57         int event;
58         int result;
59         void *param_data;
60         void *user_data;
61 } mesh_event_param_t;
62
63 typedef struct {
64         uint16_t elem_index;
65         uint32_t model_id;
66 } bluetooth_mesh_model_t;
67
68 typedef struct {
69         uint16_t index;
70         uint16_t num_models;
71 } bluetooth_mesh_element_t;
72
73 typedef struct {
74         uint16_t companyid;
75         uint16_t vendorid;
76         uint16_t versionid;
77         uint16_t crpl;
78 } bluetooth_mesh_vendor_info_t;
79
80 typedef struct {
81         int relay;
82         int proxy;
83         int frnd;
84         int lpn;
85 } bluetooth_mesh_features_t;
86
87 typedef struct {
88         bluetooth_mesh_vendor_info_t vendor_info;
89         uint16_t num_elements;
90         uint16_t primary_unicast;
91         uint8_t uuid[16];
92         union {
93                 uint8_t u8[8];
94                 uint64_t u64;
95         } token;
96 } bluetooth_mesh_node_t;
97
98
99 typedef struct {
100         char token[BLUETOOTH_MESH_NETWORK_TOKEN_STRING_LENGTH +1];
101 } bluetooth_mesh_token_t;
102
103 typedef struct {
104         char name[BLUETOOTH_MESH_NETWORK_NAME_STRING_MAX +1];
105 } bluetooth_mesh_network_name_t;
106
107 typedef struct {
108         bluetooth_mesh_network_name_t name;
109         bluetooth_mesh_token_t token;
110         char uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
111         char app_cred[BLUETOOTH_MESH_APP_UNIQUE_CRED_STRING_LENGTH + 1];
112 } bluetooth_mesh_network_t;
113
114 typedef struct {
115         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
116         int rssi;
117         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
118         uint8_t oob_info[2];
119         uint8_t uri_hash[4];
120 } bluetooth_mesh_scan_result_t;
121
122 typedef struct {
123         uint16_t scan_time;
124 } bluetooth_mesh_scan_param_t;
125
126
127 typedef struct {
128         bool public_oob;
129         bool static_oob;
130         uint16_t out_oob;
131         uint16_t  in_oob;
132 } bluetooth_mesh_provisioner_caps_t;
133
134 typedef struct {
135         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
136         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
137         uint16_t unicast;
138         int count;
139         int netkey_idx;
140 } bluetooth_mesh_node_discover_t;
141
142 typedef struct {
143         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
144         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
145         uint16_t unicast;
146         int elem_count;
147         bluetooth_mesh_vendor_info_t vendor_info;
148         bluetooth_mesh_features_t features;
149 } bluetooth_mesh_node_features_t;
150
151 typedef struct {
152         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
153         uint16_t unicast;
154         uint8_t ttl;
155         bool is_set;
156 } bluetooth_mesh_node_ttl_info_t;
157
158 typedef struct {
159         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
160         uint16_t primary_unicast;
161         int elem_index;
162         uint32_t model;
163         uint16_t netkey_idx;
164         uint16_t appkey_idx;
165         uint16_t **appkey_list;
166         int appkeylist_count;
167         bool is_bind;
168
169         /* For Subscription Configuration */
170         bluetooth_mesh_model_sub_op_e op;
171         bool is_virtual_sub;
172         uint16_t sub_addr;
173         uint16_t **sub_list;
174         int sublist_count;
175
176         /* For Publication Configuration */
177         uint16_t pub_addr;
178         uint8_t ttl;
179         uint8_t period;
180         uint8_t retransmit;
181 } bluetooth_mesh_model_configure_t;
182
183 typedef struct {
184         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
185         uint16_t primary_unicast;
186         int elem_index;
187         uint16_t model;
188         uint16_t appkey_idx;
189         uint16_t opcode;
190         uint16_t msg_len;
191         char msg[BLUETOOTH_MESH_MODEL_MSG_LENGTH_MAX + 1];
192 } bluetooth_mesh_model_msg_t;
193
194 typedef struct {
195         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
196         bool is_virtual;
197         uint16_t group_addr;
198         char label_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH +1];
199 } bluetooth_mesh_network_group_info_t;
200
201 typedef struct {
202         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
203         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
204         uint16_t primary_unicast;
205         uint16_t netkey_idx;
206         uint16_t appkey_idx;
207         bool is_netkey;
208         bluetooth_mesh_node_key_conf_e op;
209 } bluetooth_mesh_key_configure_t;
210
211 typedef struct {
212         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
213         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
214 } bluetooth_mesh_provisioning_request_t;
215
216 typedef struct {
217         int result;
218         int reason;
219         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
220         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
221         uint16_t unicast;
222         uint8_t count;
223 } bluetooth_mesh_provisioning_result_t;
224
225 typedef struct {
226         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
227         int auth_type;
228         char auth_value[50];
229 } bluetooth_mesh_authentication_request_t;
230
231 typedef struct {
232         uint16_t primary_unicast;
233         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
234 } bluetooth_mesh_node_info_t;
235
236 /**
237  * Mesh Event handler callback
238  */
239 typedef void (*mesh_cb_func_ptr)(int, mesh_event_param_t *, void *);
240
241 /**
242  * Mesh Init
243  */
244 int bluetooth_mesh_init(mesh_cb_func_ptr callback_ptr, void *user_data);
245
246 /**
247  * Mesh De-Init
248  */
249 int bluetooth_mesh_deinit(void);
250
251 /**
252  * Create Local Mesh Network
253  */
254 int bluetooth_mesh_network_create(const char *net_name,
255                 bluetooth_mesh_node_t *node, uint16_t total_models,
256                         bluetooth_mesh_model_t **models,
257                                 bluetooth_mesh_network_t *network);
258
259 int bluetooth_mesh_network_destroy(bluetooth_mesh_network_t *network);
260
261 /**
262  * Load already created Network
263  */
264 int bluetooth_mesh_network_load(const char *token,
265                 bluetooth_mesh_network_t *network);
266
267 /**
268  * Scan for Unprovisioned Devices
269  */
270 int bluetooth_mesh_network_scan(bluetooth_mesh_network_t *network,
271                 bluetooth_mesh_scan_param_t *scan_param);
272
273 /**
274  * Cancel the ongoing Scan
275  */
276 int bluetooth_mesh_network_cancel_scan(bluetooth_mesh_network_t *network);
277
278 /**
279  * Set Local Network Provisioning Capabilities
280  */
281 int bluetooth_mesh_network_set_capabilities(
282                 bluetooth_mesh_network_t *network,
283                         bluetooth_mesh_provisioner_caps_t *caps);
284
285 /**
286  * Povision a Device
287 */
288 int bluetooth_mesh_network_provision_device(
289                 bluetooth_mesh_provisioning_request_t *req);
290
291 /**
292  * Reply to Authentication request
293  */
294 int bluetooth_mesh_authentication_reply(int auth_type,
295                 const char *auth_val, gboolean reply);
296
297 /**
298  * Set Local Mesh Network name
299  */
300 int bluetooth_mesh_network_set_name(bluetooth_mesh_network_t *network);
301
302 /**
303  * Add Subnet key in local Network
304  */
305 int bluetooth_mesh_network_add_netkey(bluetooth_mesh_network_t *network,
306                 uint16_t *netkey_idx);
307
308 /**
309  * Delete Subnet key in local Network
310  */
311 int bluetooth_mesh_network_delete_netkey(
312                 bluetooth_mesh_network_t *network, uint16_t netkey_idx);
313
314 /**
315  * Update Subnet key in local Network
316  */
317 int bluetooth_mesh_network_update_netkey(bluetooth_mesh_network_t *network,
318                 uint16_t netkey_idx);
319
320 /**
321  * Add Application Key in local Network
322  */
323 int bluetooth_mesh_network_add_appkey(bluetooth_mesh_network_t *network,
324                 uint16_t netkey_idx, uint16_t *appkey_index);
325
326 /**
327  * Update Application Key in local Network
328  */
329 int bluetooth_mesh_network_update_appkey(bluetooth_mesh_network_t *network,
330                 uint16_t netkey_index, uint16_t appkey_idx);
331
332 /**
333  * Delete Application Key in local Network
334  */
335 int bluetooth_mesh_network_delete_appkey(bluetooth_mesh_network_t *network,
336                 uint16_t netkey_index, uint16_t appkey_idx);
337
338 /**
339  * Get All Netkeys in Local Network
340  */
341 int bluetooth_mesh_network_get_all_netkey(bluetooth_mesh_network_t *network,
342                         GPtrArray **netkeys);
343
344 /**
345  * Get All Appkeys Bound to a Netkey in Local Network
346  * Mesh Init
347  */
348 int bluetooth_mesh_netkey_get_all_appkey(bluetooth_mesh_network_t *network,
349                 uint16_t netkey_idx,  GPtrArray **appkeys);
350
351 /**
352  * Get All nodes's basic information, that are added in the local Network
353  */
354 int bluetooth_mesh_network_get_all_nodes(bluetooth_mesh_network_t *network,
355                 GPtrArray **nodes);
356
357 /**
358  * Get all Model information
359  */
360 int bluetooth_mesh_element_get_all_models(bluetooth_mesh_network_t *network,
361                  uint16_t node_addr, int elem_idx, GPtrArray **models);
362
363
364 /**
365  * Get All Netkeys bound to a node
366  */
367 int bluetooth_mesh_node_get_all_netkeys(bluetooth_mesh_node_discover_t *req,
368                         GPtrArray **netkeys);
369
370 /**
371  * Get All Application Keys bound to a node
372  */
373 int bluetooth_mesh_node_get_all_appkeys(bluetooth_mesh_node_discover_t *req,
374                         GPtrArray **appkeys);
375
376 /**
377  * Discover remote node exported informations (E.g: Models)
378  */
379 int bluetooth_mesh_browse_remote_node(bluetooth_mesh_node_discover_t *req);
380
381 /**
382  * Configure Key to a node
383  */
384 int bluetooth_mesh_node_configure_key(bluetooth_mesh_key_configure_t *req);
385
386 /**
387  * Confiure Appplication key to a model of a node
388  */
389 int bluetooth_mesh_model_configure_appkey(
390                 bluetooth_mesh_model_configure_t *req);
391
392 /**
393  * Send message to a model of a node
394  */
395 int bluetooth_mesh_model_send_msg(
396                         bluetooth_mesh_model_msg_t *req);
397
398 /**
399  * Get all application keys added to a model of a node
400  */
401 int bluetooth_mesh_model_get_all_appkeys(
402                 bluetooth_mesh_model_configure_t *req);
403
404 /**
405  * Get full subscription list added to a Model in a node
406  */
407 int bluetooth_mesh_model_get_subscriptopn_list(
408                 bluetooth_mesh_model_configure_t *req);
409
410 /**
411  * Get/Set Time To Live value of a node
412  */
413 int bluetooth_mesh_node_ttl_execute(
414                 bluetooth_mesh_node_ttl_info_t *req);
415
416 /**
417  * Get all groups available in local Network
418  */
419 int bluetooth_mesh_network_get_all_groups(
420                 bluetooth_mesh_network_t *network,
421                 GPtrArray **groups);
422
423 /**
424  * Create a group in a network
425  */
426 int bluetooth_mesh_network_create_group(bluetooth_mesh_network_t *network,
427                 bool is_virtual, uint16_t grp_addr,
428                         bluetooth_mesh_network_group_info_t *info);
429
430 /**
431  * Remove a group in a network
432  */
433 int bluetooth_mesh_network_remove_group(bluetooth_mesh_network_t *network,
434                 bluetooth_mesh_network_group_info_t *req);
435
436 /**
437  * Configure a Mesh group to a Mesh odel
438  */
439 int bluetooth_mesh_model_configure_group_sub(
440         bluetooth_mesh_model_configure_t *req);
441
442 /**
443  * Confgure Virtual group to a Mesh Model
444  */
445 int bluetooth_mesh_model_configure_virtual_group_sub(
446                 bluetooth_mesh_model_configure_t *req);
447
448 /**
449  * Set Publication Information to a model of a node
450  */
451 int bluetooth_mesh_model_set_publication(bluetooth_mesh_model_configure_t *req);
452
453 /**
454  * Get Publication Information from a model of a node
455  */
456 int bluetooth_mesh_model_get_publication(bluetooth_mesh_model_configure_t *req);
457
458 /**
459  * Browse Vendor specific features from node
460  */
461 int bluetooth_mesh_node_browse_vendor_features(bluetooth_mesh_node_features_t *req);
462
463 #ifdef __cplusplus
464 }
465 #endif
466 #endif /* __BLUETOOTH_MESH_API_H */