bad043954a120ab960841e3b5a1f8b6533d456d3
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / hardware / bt_mesh.h
1 /*
2  * Copyright (C) 2020 Samsung Electronics Company Ltd.
3  *
4  * @author: Anupam Roy <anupam.r@samsung.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #ifndef TIZEN_INCLUDE_BT_MESH_H
20 #define TIZEN_INCLUDE_BT_MESH_H
21
22 #include <stdint.h>
23 #include <glib.h>
24
25 __BEGIN_DECLS
26
27 /* Mesh Authentication types */
28 typedef enum {
29         /*< Output authentication request types */
30         BT_HAL_MESH_AUTH_ALPHANUMERIC_DISPLAY = 0,
31         BT_HAL_MESH_AUTH_NUMERIC_DISPLAY,
32         BT_HAL_MESH_AUTH_PUSH_COUNT_DISPLAY,
33         BT_HAL_MESH_AUTH_TWIST_COUNT_DISPLAY,
34
35         /*< Input authentication request types */
36         BT_HAL_MESH_AUTH_REQ_ALPHANUMERIC_INPUT,
37         BT_HAL_MESH_AUTH_REQ_NUMERIC_INPUT,
38         BT_HAL_MESH_AUTH_REQ_BLINK_COUNT_INPUT,
39         BT_HAL_MESH_AUTH_REQ_BEEP_COUNT_INPUT,
40         BT_HAL_MESH_AUTH_REQ_VIBRATE_COUNT_INPUT,
41
42         /**< OOB Key Inputs */
43         BT_HAL_MESH_AUTH_REQ_OOB_PUBLIC_KEY_INPUT,
44         BT_HAL_MESH_AUTH_REQ_OOB_STATIC_KEY_INPUT
45 } bt_hal_mesh_auth_variant_e;
46
47 /* Spec defined Error Codes */
48 typedef enum {
49         BT_HAL_MESH_PROV_ERR_INTERNAL               = -1,
50         BT_HAL_MESH_PROV_ERR_SUCCESS                = 0x00,
51         BT_HAL_MESH_PROV_ERR_INVALID_PDU            = 0x01,
52         BT_HAL_MESH_PROV_ERR_INVALID_FORMAT         = 0x02,
53         BT_HAL_MESH_PROV_ERR_UNEXPECTED_PDU         = 0x03,
54         BT_HAL_MESH_PROV_ERR_CONFIRM_FAILED         = 0x04,
55         BT_HAL_MESH_PROV_ERR_INSUF_RESOURCE         = 0x05,
56         BT_HAL_MESH_PROV_ERR_DECRYPT_FAILED         = 0x06,
57         BT_HAL_MESH_PROV_ERR_UNEXPECTED_ERR         = 0x07,
58         BT_HAL_MESH_PROV_ERR_CANT_ASSIGN_ADDR       = 0x08,
59         /* Internally generated  by Stack */
60         BT_HAL_MESH_PROV_ERR_TIMEOUT                = 0xFF,
61 } bt_hal_mesh_prov_error_codes_e;
62
63 /* Mesh Node Properties */
64 typedef struct {
65         uint16_t companyid;
66         uint16_t vendorid;
67         uint16_t versionid;
68         uint16_t crpl;
69 } bt_hal_mesh_vendor_info_t;
70
71 /* Mesh Model: 2 bytes for BT SIG Model & 4 bytes for Vendor Model */
72 typedef struct {
73         uint16_t elem_index;
74         uint32_t model_id;
75 } bt_hal_mesh_model_t;
76
77 /* Mesh Element structure */
78 typedef struct {
79         uint16_t index;
80         int num_models;
81 } bt_hal_mesh_element_t;
82
83 /* Mesh Node structure */
84 typedef struct {
85         bt_hal_mesh_vendor_info_t vendor_info;
86         uint16_t num_elements;
87         uint16_t primary_unicast;
88         bt_uuid_t uuid;
89         union {
90                 uint8_t u8[8];
91                 uint64_t u64;
92         } token;
93 } bt_hal_mesh_node_t;
94
95 /** Bluetooth Mesh Security Token */
96 typedef struct {
97         uint8_t token[8];
98 } bt_mesh_token_t;
99
100 typedef struct {
101         uint32_t scan_time;
102 } bt_hal_mesh_scan_param_t;
103
104 typedef struct {
105         bool public_oob;
106         bool static_oob;
107         uint16_t out_oob;
108         uint16_t in_oob;
109 } bt_hal_mesh_prov_caps_t;
110
111 /** Bluetooth Mesh Security Token */
112 typedef struct {
113         int rssi;
114         bt_uuid_t dev_uuid;
115         uint8_t oob_info[2];
116         uint8_t uri_hash[4];
117 } bt_mesh_scan_result_t;
118
119 /** Bluetooth Mesh Scan state */
120 typedef enum {
121         BT_MESH_SCAN_STOPPED,
122         BT_MESH_SCAN_STARTED
123 } bt_mesh_scan_state_t;
124
125 /** Bluetooth Mesh Scan state */
126 typedef enum {
127         BT_MESH_KEY_CREATE,
128         BT_MESH_KEY_UPDATE,
129         BT_MESH_KEY_DELETE,
130 } bt_mesh_key_op_e;
131
132 /** Callback Signatures */
133 typedef void (*btmesh_network_attached_callback)(bt_status_t status,
134                 bt_mesh_token_t *token, bt_uuid_t *uuid);
135
136 typedef void (*btmesh_network_scan_status_callback)(
137                 bt_mesh_scan_state_t scan_state, bt_status_t status,
138                         bt_uuid_t *net_uuid);
139
140 typedef void (*btmesh_network_scan_result_callback)(bt_status_t status,
141                 bt_uuid_t *net_uuid, bt_mesh_scan_result_t *scan_result);
142
143 typedef void (*btmesh_network_provisioning_status_callback)(
144                 bt_status_t status, bt_uuid_t *net_uuid, bt_uuid_t *dev_uuid);
145
146 typedef void (*btmesh_network_provisioning_finished_callback)(
147                 bt_status_t status, int reason, bt_uuid_t *net_uuid,
148                         bt_uuid_t *dev_uuid, uint16_t unicast, uint8_t count);
149
150 typedef void (*btmesh_network_provisioning_data_requested_callback)(
151                 bt_uuid_t *net_uuid, uint8_t count);
152
153 typedef void (*btmesh_network_authentication_requested_callback)(
154                 bt_uuid_t *net_uuid,
155                         bt_hal_mesh_auth_variant_e auth_type, char auth_value[]);
156
157 typedef void (*btmesh_network_netkey_execute_callback)(
158                 bt_status_t status, bt_uuid_t *net_uuid,
159                         uint8_t key_event, uint16_t netkey_idx);
160
161 typedef void (*btmesh_network_appkey_execute_callback)(
162                 bt_status_t status, bt_uuid_t *net_uuid, uint8_t key_event,
163                         uint16_t netkey_idx, uint16_t appkey_idx);
164
165 typedef void (*btmesh_devkey_message_received_callback)(bt_uuid_t *net_uuid,
166                 uint16_t source_addr, bool is_devkey_remote, uint16_t netkey_idx,
167                         uint16_t data_len, uint8_t *data);
168
169 /** BT-Mesh callback structure. */
170 typedef struct {
171         /** set to sizeof(btmesh_callbacks_t) */
172         size_t      size;
173         btmesh_network_attached_callback  network_attached_cb;
174         btmesh_network_scan_status_callback  scan_status_cb;
175         btmesh_network_scan_result_callback  scan_result_cb;
176         btmesh_network_provisioning_status_callback  provisioning_status_cb;
177         btmesh_network_provisioning_finished_callback  provisioning_finished_cb;
178         btmesh_network_provisioning_data_requested_callback  provisioning_data_requested_cb;
179         btmesh_network_authentication_requested_callback  authentication_requested_cb;
180         btmesh_network_netkey_execute_callback  netkey_execute_cb;
181         btmesh_network_appkey_execute_callback  appkey_execute_cb;
182         btmesh_devkey_message_received_callback  devkey_msg_cb;
183 } btmesh_callbacks_t;
184
185 /** Represents the standard BT-MESH interface. */
186 typedef struct {
187
188         /** set to sizeof(btmesh_interface_t) */
189         size_t          size;
190         /**
191          * Register the BT Mesh callbacks
192          */
193         bt_status_t (*init)(btmesh_callbacks_t* callbacks);
194         bt_status_t (*create)(bt_hal_mesh_node_t *node,
195                 GSList *model_list, bool is_prov);
196         bt_status_t (*scan)(bt_uuid_t *network,
197                 bt_hal_mesh_scan_param_t *param);
198         bt_status_t (*scan_cancel)(bt_uuid_t *network);
199         bt_status_t (*capability)(bt_uuid_t *network,
200                 bt_hal_mesh_prov_caps_t *param);
201         bt_status_t (*provision)(bt_uuid_t *network, bt_uuid_t *dev_uuid);
202         bt_status_t (*provision_data)(bt_uuid_t* network_uuid,
203                 uint16_t netkey_idx, uint16_t unicast);
204         bt_status_t (*auth_reply)(bt_hal_mesh_auth_variant_e auth_type,
205                 const char *auth_value);
206         bt_status_t (*subnet_execute)(bt_uuid_t* network_uuid,
207                 bt_mesh_key_op_e op, uint16_t netkey_idx);
208         bt_status_t (*appkey_execute)(bt_uuid_t* network_uuid,
209                 bt_mesh_key_op_e op, uint16_t netkey_idx, uint16_t appkey_idx);
210         bt_status_t (*config_send)(bt_uuid_t *network, uint16_t dest,
211                 bool is_dev_key, uint16_t netkey_idx, uint8_t *buf, int len);
212         bt_status_t (*key_send)(bt_uuid_t *network, uint16_t dest,
213                 bool is_netkey, bool is_update, uint16_t key_idx, uint16_t netkey_idx);
214         bt_status_t (*attach)(void);
215         /** Closes the interface. */
216         void (*cleanup)(void);
217 } btmesh_interface_t;
218 __END_DECLS
219
220 #endif /* TIZEN_INCLUDE_BT_MESH_H */