Mesh: Add HAL interface
authorAnupam Roy <anupam.r@samsung.com>
Thu, 25 Jun 2020 05:32:33 +0000 (11:02 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Fri, 17 Jul 2020 08:59:20 +0000 (14:29 +0530)
This patch adds following
- Mesh HAL events
- Application callback signatures
- Application API signatures

Mesh Application shall comply with above
Mesh HAL interface

Change-Id: I09c2ddf29173feff6f183913700513891791aa02
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-oal/bluez_hal/inc/bt-hal-msg.h
bt-oal/bluez_hal/inc/bt-hal.h
bt-oal/hardware/bluetooth.h
bt-oal/hardware/bt_mesh.h [new file with mode: 0644]

index 1e73678..846a74f 100644 (file)
@@ -836,4 +836,103 @@ struct hal_ev_gatt_client_mtu_exchange_completed {
 struct hal_ev_controller_error_recieved {
        uint8_t code;
 } __attribute__((packed));
+
+
+/* MESH HAL events */
+#define HAL_EV_MESH_NETWORK_ATTACHED   0xD2
+struct hal_ev_mesh_network_attached {
+       uint8_t status;
+       uint8_t uuid[16];
+       uint8_t token[8];
+} __attribute__((packed));
+
+#define HAL_MESH_SCAN_STATE_STOPPED     0x00
+#define HAL_MESH_SCAN_STATE_STARTED     0x01
+
+#define HAL_EV_MESH_SCAN_STATE_CHANGED   0xD3
+struct hal_ev_mesh_scan_state_changed {
+       uint8_t status;
+       uint8_t state;
+       uint8_t net_uuid[16];
+} __attribute__((packed));
+
+#if 0
+#define HAL_EV_MESH_SCAN_FINISHED      0xD4
+struct hal_ev_mesh_scan_finished {
+       uint8_t status;
+       uint8_t net_uuid[16];
+} __attribute__((packed));
+#endif
+
+#define HAL_EV_MESH_SCAN_RESULT                0xD5
+struct hal_ev_mesh_scan_result {
+       uint8_t status;
+       int rssi;
+       uint8_t net_uuid[16];
+       uint8_t dev_uuid[16];
+       uint8_t oob_info[2];
+       uint8_t uri_hash[4];
+} __attribute__((packed));
+
+#define HAL_EV_MESH_PROVISIONING_STATUS        0xD6
+struct hal_ev_mesh_provision_status {
+       uint8_t status;
+       uint8_t net_uuid[16];
+       uint8_t dev_uuid[16];
+} __attribute__((packed));
+
+#define HAL_EV_MESH_PROVISIONING_FINISHED 0xD7
+struct hal_ev_mesh_provision_finished {
+       uint8_t status;
+       int reason;
+       uint8_t net_uuid[16];
+       uint16_t unicast;
+       uint8_t count;
+       uint8_t dev_uuid[16];
+} __attribute__((packed));
+
+#define HAL_EV_MESH_PROVISIONING_DATA_REQUEST 0xD8
+struct hal_ev_mesh_provision_data_request {
+       uint8_t net_uuid[16];
+       uint8_t count;
+} __attribute__((packed));
+
+#define HAL_EV_MESH_AUTHENTICATION_REQUEST 0xD9
+struct hal_ev_mesh_authentication_request {
+       uint8_t net_uuid[16];
+       char auth_value[50];
+       int auth_type;
+} __attribute__((packed));
+
+
+#define HAL_MESH_KEY_ADD     0x00
+#define HAL_MESH_KEY_UPDATE  0x01
+#define HAL_MESH_KEY_DELETE  0x02
+
+#define HAL_EV_MESH_NETKEY_EXECUTE_EVENT 0xDA
+struct hal_ev_mesh_netkey_execute_event {
+       uint8_t status;
+       uint8_t key_event;
+       uint8_t net_uuid[16];
+       uint16_t key_idx;
+} __attribute__((packed));
+
+#define HAL_EV_MESH_APPKEY_EXECUTE_EVENT 0xDB
+struct hal_ev_mesh_appkey_execute_event {
+       uint8_t status;
+       uint8_t key_event;
+       uint8_t net_uuid[16];
+       uint16_t net_idx;
+       uint16_t app_idx;
+} __attribute__((packed));
+
+#define HAL_EV_MESH_DEVKEY_MESSAGE_EVENT       0xDC
+struct hal_ev_mesh_devkey_message_event {
+       uint8_t net_uuid[16];
+       uint16_t source_addr;
+       uint8_t is_remote_devkey;
+       uint16_t netkey_idx;
+       int data_len;
+       uint8_t data[0];
+} __attribute__((packed));
 #endif //_BT_HAL_MSG_H_
index 7f789ad..f40f92c 100644 (file)
@@ -31,6 +31,7 @@
 #include <hardware/bt_hl.h>
 #include <hardware/bt_rc.h>
 #include <hardware/bt_hf_client.h>
+#include <hardware/bt_mesh.h>
 
 /*TODO: Profile interfaces headers and exposed methods of Android HAL framework to be included in next patches */
 #endif //_BT_HAL_H
index c6a886b..67185b8 100644 (file)
@@ -49,6 +49,7 @@ __BEGIN_DECLS
 #define BT_PROFILE_MAP_CLIENT_ID "map_client"
 
 #define BT_PROFILE_GATT_ID "gatt"
+#define BT_PROFILE_MESH_ID "mesh"
 #define BT_PROFILE_AV_RC_ID "avrcp"
 #define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl"
 #define BT_MANUFACTURER_DATA_LENGTH_MAX 31 /**< This specifies the Maximum manufacturer data Length>*/
diff --git a/bt-oal/hardware/bt_mesh.h b/bt-oal/hardware/bt_mesh.h
new file mode 100644 (file)
index 0000000..bad0439
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2020 Samsung Electronics Company Ltd.
+ *
+ * @author: Anupam Roy <anupam.r@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef TIZEN_INCLUDE_BT_MESH_H
+#define TIZEN_INCLUDE_BT_MESH_H
+
+#include <stdint.h>
+#include <glib.h>
+
+__BEGIN_DECLS
+
+/* Mesh Authentication types */
+typedef enum {
+       /*< Output authentication request types */
+       BT_HAL_MESH_AUTH_ALPHANUMERIC_DISPLAY = 0,
+       BT_HAL_MESH_AUTH_NUMERIC_DISPLAY,
+       BT_HAL_MESH_AUTH_PUSH_COUNT_DISPLAY,
+       BT_HAL_MESH_AUTH_TWIST_COUNT_DISPLAY,
+
+       /*< Input authentication request types */
+       BT_HAL_MESH_AUTH_REQ_ALPHANUMERIC_INPUT,
+       BT_HAL_MESH_AUTH_REQ_NUMERIC_INPUT,
+       BT_HAL_MESH_AUTH_REQ_BLINK_COUNT_INPUT,
+       BT_HAL_MESH_AUTH_REQ_BEEP_COUNT_INPUT,
+       BT_HAL_MESH_AUTH_REQ_VIBRATE_COUNT_INPUT,
+
+       /**< OOB Key Inputs */
+       BT_HAL_MESH_AUTH_REQ_OOB_PUBLIC_KEY_INPUT,
+       BT_HAL_MESH_AUTH_REQ_OOB_STATIC_KEY_INPUT
+} bt_hal_mesh_auth_variant_e;
+
+/* Spec defined Error Codes */
+typedef enum {
+       BT_HAL_MESH_PROV_ERR_INTERNAL               = -1,
+       BT_HAL_MESH_PROV_ERR_SUCCESS                = 0x00,
+       BT_HAL_MESH_PROV_ERR_INVALID_PDU            = 0x01,
+       BT_HAL_MESH_PROV_ERR_INVALID_FORMAT         = 0x02,
+       BT_HAL_MESH_PROV_ERR_UNEXPECTED_PDU         = 0x03,
+       BT_HAL_MESH_PROV_ERR_CONFIRM_FAILED         = 0x04,
+       BT_HAL_MESH_PROV_ERR_INSUF_RESOURCE         = 0x05,
+       BT_HAL_MESH_PROV_ERR_DECRYPT_FAILED         = 0x06,
+       BT_HAL_MESH_PROV_ERR_UNEXPECTED_ERR         = 0x07,
+       BT_HAL_MESH_PROV_ERR_CANT_ASSIGN_ADDR       = 0x08,
+       /* Internally generated  by Stack */
+       BT_HAL_MESH_PROV_ERR_TIMEOUT                = 0xFF,
+} bt_hal_mesh_prov_error_codes_e;
+
+/* Mesh Node Properties */
+typedef struct {
+       uint16_t companyid;
+       uint16_t vendorid;
+       uint16_t versionid;
+       uint16_t crpl;
+} bt_hal_mesh_vendor_info_t;
+
+/* Mesh Model: 2 bytes for BT SIG Model & 4 bytes for Vendor Model */
+typedef struct {
+       uint16_t elem_index;
+       uint32_t model_id;
+} bt_hal_mesh_model_t;
+
+/* Mesh Element structure */
+typedef struct {
+       uint16_t index;
+       int num_models;
+} bt_hal_mesh_element_t;
+
+/* Mesh Node structure */
+typedef struct {
+       bt_hal_mesh_vendor_info_t vendor_info;
+       uint16_t num_elements;
+       uint16_t primary_unicast;
+       bt_uuid_t uuid;
+       union {
+               uint8_t u8[8];
+               uint64_t u64;
+       } token;
+} bt_hal_mesh_node_t;
+
+/** Bluetooth Mesh Security Token */
+typedef struct {
+        uint8_t token[8];
+} bt_mesh_token_t;
+
+typedef struct {
+        uint32_t scan_time;
+} bt_hal_mesh_scan_param_t;
+
+typedef struct {
+       bool public_oob;
+       bool static_oob;
+       uint16_t out_oob;
+       uint16_t in_oob;
+} bt_hal_mesh_prov_caps_t;
+
+/** Bluetooth Mesh Security Token */
+typedef struct {
+       int rssi;
+       bt_uuid_t dev_uuid;
+       uint8_t oob_info[2];
+       uint8_t uri_hash[4];
+} bt_mesh_scan_result_t;
+
+/** Bluetooth Mesh Scan state */
+typedef enum {
+       BT_MESH_SCAN_STOPPED,
+       BT_MESH_SCAN_STARTED
+} bt_mesh_scan_state_t;
+
+/** Bluetooth Mesh Scan state */
+typedef enum {
+       BT_MESH_KEY_CREATE,
+       BT_MESH_KEY_UPDATE,
+       BT_MESH_KEY_DELETE,
+} bt_mesh_key_op_e;
+
+/** Callback Signatures */
+typedef void (*btmesh_network_attached_callback)(bt_status_t status,
+               bt_mesh_token_t *token, bt_uuid_t *uuid);
+
+typedef void (*btmesh_network_scan_status_callback)(
+               bt_mesh_scan_state_t scan_state, bt_status_t status,
+                       bt_uuid_t *net_uuid);
+
+typedef void (*btmesh_network_scan_result_callback)(bt_status_t status,
+               bt_uuid_t *net_uuid, bt_mesh_scan_result_t *scan_result);
+
+typedef void (*btmesh_network_provisioning_status_callback)(
+               bt_status_t status, bt_uuid_t *net_uuid, bt_uuid_t *dev_uuid);
+
+typedef void (*btmesh_network_provisioning_finished_callback)(
+               bt_status_t status, int reason, bt_uuid_t *net_uuid,
+                       bt_uuid_t *dev_uuid, uint16_t unicast, uint8_t count);
+
+typedef void (*btmesh_network_provisioning_data_requested_callback)(
+               bt_uuid_t *net_uuid, uint8_t count);
+
+typedef void (*btmesh_network_authentication_requested_callback)(
+               bt_uuid_t *net_uuid,
+                       bt_hal_mesh_auth_variant_e auth_type, char auth_value[]);
+
+typedef void (*btmesh_network_netkey_execute_callback)(
+               bt_status_t status, bt_uuid_t *net_uuid,
+                       uint8_t key_event, uint16_t netkey_idx);
+
+typedef void (*btmesh_network_appkey_execute_callback)(
+               bt_status_t status, bt_uuid_t *net_uuid, uint8_t key_event,
+                       uint16_t netkey_idx, uint16_t appkey_idx);
+
+typedef void (*btmesh_devkey_message_received_callback)(bt_uuid_t *net_uuid,
+               uint16_t source_addr, bool is_devkey_remote, uint16_t netkey_idx,
+                       uint16_t data_len, uint8_t *data);
+
+/** BT-Mesh callback structure. */
+typedef struct {
+       /** set to sizeof(btmesh_callbacks_t) */
+       size_t      size;
+       btmesh_network_attached_callback  network_attached_cb;
+       btmesh_network_scan_status_callback  scan_status_cb;
+       btmesh_network_scan_result_callback  scan_result_cb;
+       btmesh_network_provisioning_status_callback  provisioning_status_cb;
+       btmesh_network_provisioning_finished_callback  provisioning_finished_cb;
+       btmesh_network_provisioning_data_requested_callback  provisioning_data_requested_cb;
+       btmesh_network_authentication_requested_callback  authentication_requested_cb;
+       btmesh_network_netkey_execute_callback  netkey_execute_cb;
+       btmesh_network_appkey_execute_callback  appkey_execute_cb;
+       btmesh_devkey_message_received_callback  devkey_msg_cb;
+} btmesh_callbacks_t;
+
+/** Represents the standard BT-MESH interface. */
+typedef struct {
+
+       /** set to sizeof(btmesh_interface_t) */
+       size_t          size;
+       /**
+        * Register the BT Mesh callbacks
+        */
+       bt_status_t (*init)(btmesh_callbacks_t* callbacks);
+       bt_status_t (*create)(bt_hal_mesh_node_t *node,
+               GSList *model_list, bool is_prov);
+       bt_status_t (*scan)(bt_uuid_t *network,
+               bt_hal_mesh_scan_param_t *param);
+       bt_status_t (*scan_cancel)(bt_uuid_t *network);
+       bt_status_t (*capability)(bt_uuid_t *network,
+               bt_hal_mesh_prov_caps_t *param);
+       bt_status_t (*provision)(bt_uuid_t *network, bt_uuid_t *dev_uuid);
+       bt_status_t (*provision_data)(bt_uuid_t* network_uuid,
+               uint16_t netkey_idx, uint16_t unicast);
+       bt_status_t (*auth_reply)(bt_hal_mesh_auth_variant_e auth_type,
+               const char *auth_value);
+       bt_status_t (*subnet_execute)(bt_uuid_t* network_uuid,
+               bt_mesh_key_op_e op, uint16_t netkey_idx);
+       bt_status_t (*appkey_execute)(bt_uuid_t* network_uuid,
+               bt_mesh_key_op_e op, uint16_t netkey_idx, uint16_t appkey_idx);
+       bt_status_t (*config_send)(bt_uuid_t *network, uint16_t dest,
+               bool is_dev_key, uint16_t netkey_idx, uint8_t *buf, int len);
+       bt_status_t (*key_send)(bt_uuid_t *network, uint16_t dest,
+               bool is_netkey, bool is_update, uint16_t key_idx, uint16_t netkey_idx);
+       bt_status_t (*attach)(void);
+       /** Closes the interface. */
+       void (*cleanup)(void);
+} btmesh_interface_t;
+__END_DECLS
+
+#endif /* TIZEN_INCLUDE_BT_MESH_H */