Fix the svace issue (DEREF_OF_NULL)
[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         char net_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
233         uint16_t primary_unicast;
234         uint16_t num_elements;
235         char dev_uuid[BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1];
236 } bluetooth_mesh_node_info_t;
237
238 /**
239  * Mesh Event handler callback
240  */
241 typedef void (*mesh_cb_func_ptr)(int, mesh_event_param_t *, void *);
242
243 /**
244  * Mesh Init
245  */
246 int bluetooth_mesh_init(mesh_cb_func_ptr callback_ptr, void *user_data);
247
248 /**
249  * Mesh De-Init
250  */
251 int bluetooth_mesh_deinit(void);
252
253 /**
254  * Create Local Mesh Network
255  */
256 int bluetooth_mesh_network_create(const char *net_name,
257                 bluetooth_mesh_node_t *node, uint16_t total_models,
258                         bluetooth_mesh_model_t **models,
259                                 bluetooth_mesh_network_t *network);
260
261
262 /**
263  * Destroy Local Network Configuration
264  */
265 int bluetooth_mesh_network_destroy(bluetooth_mesh_network_t *network);
266
267 /**
268  * Unload Local network Configuration
269  */
270 int bluetooth_mesh_network_unload(bluetooth_mesh_network_t *network);
271
272 /**
273  * Reset a remote Node & remove it from network
274  */
275 int bluetooth_mesh_node_reset(bluetooth_mesh_node_info_t *node);
276
277 /**
278  * Load already created Network
279  */
280 int bluetooth_mesh_network_load(const char *token,
281                 bluetooth_mesh_network_t *network);
282
283 /**
284  * Scan for Unprovisioned Devices
285  */
286 int bluetooth_mesh_network_scan(bluetooth_mesh_network_t *network,
287                 bluetooth_mesh_scan_param_t *scan_param);
288
289 /**
290  * Cancel the ongoing Scan
291  */
292 int bluetooth_mesh_network_cancel_scan(bluetooth_mesh_network_t *network);
293
294 /**
295  * Set Local Network Provisioning Capabilities
296  */
297 int bluetooth_mesh_network_set_capabilities(
298                 bluetooth_mesh_network_t *network,
299                         bluetooth_mesh_provisioner_caps_t *caps);
300
301 /**
302  * Povision a Device
303 */
304 int bluetooth_mesh_network_provision_device(
305                 bluetooth_mesh_provisioning_request_t *req);
306
307 /**
308  * Reply to Authentication request
309  */
310 int bluetooth_mesh_authentication_reply(int auth_type,
311                 const char *auth_val, gboolean reply);
312
313 /**
314  * Set Local Mesh Network name
315  */
316 int bluetooth_mesh_network_set_name(bluetooth_mesh_network_t *network);
317
318 /**
319  * Add Subnet key in local Network
320  */
321 int bluetooth_mesh_network_add_netkey(bluetooth_mesh_network_t *network,
322                 uint16_t *netkey_idx);
323
324 /**
325  * Delete Subnet key in local Network
326  */
327 int bluetooth_mesh_network_delete_netkey(
328                 bluetooth_mesh_network_t *network, uint16_t netkey_idx);
329
330 /**
331  * Update Subnet key in local Network
332  */
333 int bluetooth_mesh_network_update_netkey(bluetooth_mesh_network_t *network,
334                 uint16_t netkey_idx);
335
336 /**
337  * Add Application Key in local Network
338  */
339 int bluetooth_mesh_network_add_appkey(bluetooth_mesh_network_t *network,
340                 uint16_t netkey_idx, uint16_t *appkey_index);
341
342 /**
343  * Update Application Key in local Network
344  */
345 int bluetooth_mesh_network_update_appkey(bluetooth_mesh_network_t *network,
346                 uint16_t netkey_index, uint16_t appkey_idx);
347
348 /**
349  * Delete Application Key in local Network
350  */
351 int bluetooth_mesh_network_delete_appkey(bluetooth_mesh_network_t *network,
352                 uint16_t netkey_index, uint16_t appkey_idx);
353
354 /**
355  * Get All Netkeys in Local Network
356  */
357 int bluetooth_mesh_network_get_all_netkey(bluetooth_mesh_network_t *network,
358                         GPtrArray **netkeys);
359
360 /**
361  * Get All Appkeys Bound to a Netkey in Local Network
362  * Mesh Init
363  */
364 int bluetooth_mesh_netkey_get_all_appkey(bluetooth_mesh_network_t *network,
365                 uint16_t netkey_idx,  GPtrArray **appkeys);
366
367 /**
368  * Get All nodes's basic information, that are added in the local Network
369  */
370 int bluetooth_mesh_network_get_all_nodes(bluetooth_mesh_network_t *network,
371                 GPtrArray **nodes);
372
373 /**
374  * Get all Model information
375  */
376 int bluetooth_mesh_element_get_all_models(bluetooth_mesh_network_t *network,
377                  uint16_t node_addr, int elem_idx, GPtrArray **models);
378
379
380 /**
381  * Get All Netkeys bound to a node
382  */
383 int bluetooth_mesh_node_get_all_netkeys(bluetooth_mesh_node_discover_t *req,
384                         GPtrArray **netkeys);
385
386 /**
387  * Get All Application Keys bound to a node
388  */
389 int bluetooth_mesh_node_get_all_appkeys(bluetooth_mesh_node_discover_t *req,
390                         GPtrArray **appkeys);
391
392 /**
393  * Discover remote node exported informations (E.g: Models)
394  */
395 int bluetooth_mesh_browse_remote_node(bluetooth_mesh_node_discover_t *req);
396
397 /**
398  * Configure Key to a node
399  */
400 int bluetooth_mesh_node_configure_key(bluetooth_mesh_key_configure_t *req);
401
402 /**
403  * Confiure Appplication key to a model of a node
404  */
405 int bluetooth_mesh_model_configure_appkey(
406                 bluetooth_mesh_model_configure_t *req);
407
408 /**
409  * Send message to a model of a node
410  */
411 int bluetooth_mesh_model_send_msg(
412                         bluetooth_mesh_model_msg_t *req);
413
414 /**
415  * Get all application keys added to a model of a node
416  */
417 int bluetooth_mesh_model_get_all_appkeys(
418                 bluetooth_mesh_model_configure_t *req);
419
420 /**
421  * Get full subscription list added to a Model in a node
422  */
423 int bluetooth_mesh_model_get_subscriptopn_list(
424                 bluetooth_mesh_model_configure_t *req);
425
426 /**
427  * Get/Set Time To Live value of a node
428  */
429 int bluetooth_mesh_node_ttl_execute(
430                 bluetooth_mesh_node_ttl_info_t *req);
431
432 /**
433  * Get all groups available in local Network
434  */
435 int bluetooth_mesh_network_get_all_groups(
436                 bluetooth_mesh_network_t *network,
437                 GPtrArray **groups);
438
439 /**
440  * Create a group in a network
441  */
442 int bluetooth_mesh_network_create_group(bluetooth_mesh_network_t *network,
443                 bool is_virtual, uint16_t grp_addr,
444                         bluetooth_mesh_network_group_info_t *info);
445
446 /**
447  * Remove a group in a network
448  */
449 int bluetooth_mesh_network_remove_group(bluetooth_mesh_network_t *network,
450                 bluetooth_mesh_network_group_info_t *req);
451
452 /**
453  * Configure a Mesh group to a Mesh odel
454  */
455 int bluetooth_mesh_model_configure_group_sub(
456         bluetooth_mesh_model_configure_t *req);
457
458 /**
459  * Confgure Virtual group to a Mesh Model
460  */
461 int bluetooth_mesh_model_configure_virtual_group_sub(
462                 bluetooth_mesh_model_configure_t *req);
463
464 /**
465  * Set Publication Information to a model of a node
466  */
467 int bluetooth_mesh_model_set_publication(bluetooth_mesh_model_configure_t *req);
468
469 /**
470  * Get Publication Information from a model of a node
471  */
472 int bluetooth_mesh_model_get_publication(bluetooth_mesh_model_configure_t *req);
473
474 /**
475  * Browse Vendor specific features from node
476  */
477 int bluetooth_mesh_node_browse_vendor_features(bluetooth_mesh_node_features_t *req);
478
479 #ifdef __cplusplus
480 }
481 #endif
482 #endif /* __BLUETOOTH_MESH_API_H */