Mesh: Add OAL Mesh API
authorAnupam Roy <anupam.r@samsung.com>
Thu, 25 Jun 2020 04:11:59 +0000 (09:41 +0530)
committerAnupam Roy <anupam.r@samsung.com>
Fri, 17 Jul 2020 08:56:48 +0000 (14:26 +0530)
This patch adds basic Mesh OAL API's.

Note:
- The current set of OAL API's can fully cover
  all Tizen Native API's developed so far.

- Following API is added for forward compatibility.
 'oal_status_t mesh_model_send_message()'
  Above API will transport Mesh Application specific messages
  which are generated by Application specific Models.
  It is upto Application to support any Models (BT SIG or Vendor)

Change-Id: I5984a5949a9fe0f3fa527d00b8d0feff0a01055b
Signed-off-by: Anupam Roy <anupam.r@samsung.com>
bt-oal/include/oal-mesh.h [new file with mode: 0644]

diff --git a/bt-oal/include/oal-mesh.h b/bt-oal/include/oal-mesh.h
new file mode 100644 (file)
index 0000000..5002d11
--- /dev/null
@@ -0,0 +1,428 @@
+/*
+ * Open Adaptation Layer (OAL)
+ *
+ * Copyright (c) 2019 -2020 Samsung Electronics Co., Ltd All Rights Reserved.
+ *
+ * @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 OAL_MESH_H_
+#define OAL_MESH_H_
+
+#include <oal-manager.h>
+
+/* Start of BLE Mesh structures and enum declarations */
+
+#define OAL_MESH_DEVKEY_MSG_BUF_MAX 2048
+
+/* Mesh Key Operation Enums (For Appkey & NetKey) */
+typedef enum {
+       OAL_MESH_KEY_ADD = 0,
+       OAL_MESH_KEY_UPDATE,
+       OAL_MESH_KEY_DELETE
+} oal_mesh_key_op_e;
+
+/* Mesh Authentication types */
+typedef enum {
+       /*< Output authentication request types */
+       OAL_MESH_AUTH_ALPHANUMERIC_DISPLAY = 0,
+       OAL_MESH_AUTH_NUMERIC_DISPLAY,
+       OAL_MESH_AUTH_PUSH_COUNT_DISPLAY,
+       OAL_MESH_AUTH_TWIST_COUNT_DISPLAY,
+
+       /*< Input authentication request types */
+       OAL_MESH_AUTH_REQ_ALPHANUMERIC_INPUT,
+       OAL_MESH_AUTH_REQ_NUMERIC_INPUT,
+       OAL_MESH_AUTH_REQ_BLINK_COUNT_INPUT,
+       OAL_MESH_AUTH_REQ_BEEP_COUNT_INPUT,
+       OAL_MESH_AUTH_REQ_VIBRATE_COUNT_INPUT,
+
+       /**< OOB Key Inputs */
+       OAL_MESH_AUTH_REQ_OOB_PUBLIC_KEY_INPUT,
+       OAL_MESH_AUTH_REQ_OOB_STATIC_KEY_INPUT
+} oal_mesh_variant_authentication_e;
+
+ /* Mesh Enumerations of 2 octet OUT OOB Actions */
+typedef enum {
+       OAL_MESH_OUT_OOB_METHOD_BLINK            = 0x01,
+       OAL_MESH_OUT_OOB_METHOD_BEEP             = 0x02,
+       OAL_MESH_OUT_OOB_METHOD_VIBRATE          = 0x04,
+       OAL_MESH_OUT_OOB_METHOD_NUMERIC          = 0x08,
+       OAL_MESH_OUT_OOB_METHOD_ALPHANUMERIC     = 0x10,
+       /* bit 5 ~ 15 : RFU */
+} oal_mesh_output_oob_action_e;
+
+ /* Mesh Enumerations of 2 octet IN OOB Actions */
+typedef enum {
+       OAL_MESH_IN_OOB_METHOD_PUSH              = 0x01,
+       OAL_MESH_IN_OOB_METHOD_TWIST             = 0x02,
+       OAL_MESH_IN_OOB_METHOD_NUMERIC           = 0x04,
+       OAL_MESH_IN_OOB_METHOD_ALPHANUMERIC      = 0x08,
+       /* bit 4 ~ 15 : RFU */
+} oal_mesh_input_oob_action_e;
+
+/* Mesh strcuture of Mesh Provisioning Capabilities */
+typedef struct {
+       /**< Indicates Public Key for ECC Key exchange, can be fetched OOB */
+       bool public_oob;
+       /**< Indicates Static Key for authentication, can be fetched OOB */
+       bool static_oob;
+       /**< Indicates suport for bitmap combination of OUT-OOB actions */
+       oal_mesh_output_oob_action_e out_oob;
+       /**< Indicates suport for bitmap combination of IN-OOB actions */
+       oal_mesh_input_oob_action_e  in_oob;
+} oal_mesh_capabilities_t;
+
+/* Mesh  Unprovisioned Device Scan result */
+typedef struct {
+       int rssi;
+       oal_uuid_t dev_uuid;
+       /* 2-octet OOB info */
+       uint8_t oob_info[2];
+       /* 4-octet URI Hash info */
+       uint8_t uri_hash[4];
+} oal_mesh_scan_result_t;
+
+/* Mesh Scan Parameters */
+typedef struct {
+       uint32_t seconds;
+       /* Structure may be expanded in future to support more scan parameters*/
+} oal_mesh_scan_params_t;
+
+/* Mesh Node Properties */
+typedef struct {
+       uint16_t companyid;
+       uint16_t vendorid;
+       uint16_t versionid;
+       uint16_t crpl;
+       int relay;
+       int frnd;
+       int proxy;
+       int lpn;
+} oal_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;
+} oal_mesh_model_t;
+
+/* Mesh Element structure */
+typedef struct {
+       uint16_t index;
+       uint16_t num_models;
+} oal_mesh_element_t;
+
+/* Mesh Node structure */
+typedef struct {
+       oal_mesh_vendor_info_t vendor_info;
+       uint16_t num_elements;
+       uint16_t primary_unicast;
+       oal_uuid_t uuid;
+       union {
+               uint8_t u8[8];
+               uint64_t u64;
+       } token;
+} oal_mesh_node_t;
+
+typedef struct {
+       oal_status_t status;
+       uint8_t token[8];
+       oal_uuid_t uuid;
+} event_mesh_network_attached_t;
+
+typedef struct {
+       oal_status_t status;
+       oal_uuid_t net_uuid;
+       oal_mesh_scan_result_t result;
+} event_mesh_scan_result_t;
+
+typedef struct {
+       oal_status_t status;
+       oal_uuid_t net_uuid;
+} event_mesh_scan_status_t;
+
+typedef struct {
+       oal_status_t status;
+       oal_uuid_t net_uuid;
+       oal_uuid_t dev_uuid;
+} event_mesh_provisioning_status_t;
+
+typedef struct {
+       oal_uuid_t net_uuid;
+       uint8_t count;
+} event_mesh_provisioning_data_requested_t;
+
+typedef struct {
+       oal_uuid_t net_uuid;
+       oal_mesh_variant_authentication_e auth_type;
+       /* MAX length of Auth value is 50 */
+       char auth_value[50 + 1];
+} event_mesh_authentication_requested_t;
+
+typedef struct {
+       oal_status_t status;
+       int reason;
+       oal_uuid_t net_uuid;
+       oal_uuid_t dev_uuid;
+       uint16_t unicast;
+       uint8_t count;
+} event_mesh_provisioning_finished_t;
+
+typedef struct {
+       oal_status_t status;
+       oal_uuid_t net_uuid;
+       oal_mesh_key_op_e op;
+       uint16_t key_idx;
+} event_mesh_netkey_operation_t;
+
+typedef struct {
+       oal_status_t status;
+       oal_uuid_t net_uuid;
+       oal_mesh_key_op_e op;
+       uint16_t net_idx;
+       uint16_t app_idx;
+} event_mesh_appkey_operation_t;
+
+typedef struct {
+       oal_uuid_t net_uuid;
+       /* Source means the node which sent the DevKey Message*/
+       uint16_t source;
+       bool remote;
+       uint16_t subnet;
+       uint16_t data_len;
+       uint8_t data[OAL_MESH_DEVKEY_MSG_BUF_MAX];
+} event_mesh_devkey_message_t;
+
+/**
+ * @brief Enables Bluetooth Mesh Stack
+ *
+ * @remarks  Application will be able to BLE Mesh features.
+ * @remarks  Initializes Bluetooth Mesh HAL interface.
+ *
+ */
+oal_status_t mesh_enable(void);
+
+/**
+ * @brief Disables Bluetooth Mesh Stack
+ *
+ * @remarks  De-Initializes Bluetooth Mesh HAL interface.
+ * @remarks  Application will not be able to BLE Mesh features.
+ *
+ * @pre OAL API should be enabled with mesh_enable().
+ *
+ * @see  mesh_enable()
+ */
+oal_status_t mesh_disable(void);
+
+/**
+ * @brief Register the BLE Mesh Node
+ *
+ * @remarks  Application will register the Mesh Provisioner node
+ * or Device node
+ *
+ * @pre OAl API should be enabled with mesh_enable().
+ *
+ * @see  mesh_enable()
+ */
+oal_status_t mesh_register_node(oal_mesh_node_t *node,
+               GSList *model_list, bool is_provisioner);
+
+/**
+ * @brief UnRegister the BLE Mesh Node
+ *
+ * @remarks  Application will unregister the Mesh Provisioner
+ * node or Device node
+ *
+ * @pre OAl API should be enabled with mesh_enable().
+ *
+ * @see  mesh_enable()
+ * @see  mesh_register_node()
+ */
+oal_status_t mesh_deregister_node(oal_mesh_node_t *node);
+
+/**
+ * @brief Local Network Subnet Operations by Mesh Provisioner Node
+ *
+ * @remarks  Application can Create/Delete/Update subnets in
+ * local key database
+ *
+ * @pre OAl API should be enabled with mesh_enable().
+ *
+ * @see  mesh_enable()
+ * @see  mesh_network_subnet_execute()
+ */
+oal_status_t mesh_network_subnet_execute(oal_uuid_t* network_uuid,
+               oal_mesh_key_op_e operation, uint16_t net_index);
+
+/**
+ * @brief Local Network Appkey Operations by Mesh Provisioner Node
+ *
+ * @remarks  Application can Create/Delete/Update Appkeys, bound to
+ * netkeys in local key database
+ *
+ * @pre OAl API should be enabled with mesh_enable().
+ *
+ * @see  mesh_enable()
+ * @see  mesh_network_subnet_execute()
+ * @see  mesh_network_subnet_execute()
+ */
+oal_status_t mesh_network_appkey_execute(oal_uuid_t* network_uuid,
+               oal_mesh_key_op_e operation,
+                       uint16_t net_index, uint16_t app_index);
+
+/**
+ * @brief Discover unprovisioned device
+ *
+ * @remarks  Provisioner application can discover Unprovisioned Device
+ * beaons which want to Join Mesh network
+ * @remarks  scan params structure is defined for forward compatibility.
+ * Currently only single parameter (seconds) is supported
+ *
+ * @pre OAl API should be enabled with mesh_enable().
+ *
+ * @see  mesh_enable()
+ * @see  mesh_network_start_scan()
+ */
+oal_status_t mesh_network_start_scan(oal_uuid_t* network_uuid,
+               oal_mesh_scan_params_t *params);
+
+/**
+ * @brief Cancel unprovisionined Device scanning
+ *
+ * @see  mesh_enable()
+ * @see  mesh_network_start_scan()
+ */
+oal_status_t mesh_network_scan_cancel(oal_uuid_t* network_uuid);
+
+/**
+ * @brief Set Provisioning capabilities
+ *
+ * @remarks  Provisioner application should set the capabilities
+ * before initiating device provision. Provisioning parameters are
+ * chosen based on combination of provisioner & device's capabilities
+ *
+ * @pre OAl API should be enabled with mesh_enable().
+ *
+ * @see  mesh_enable()
+ */
+oal_status_t mesh_network_set_provisioning_capabilities(
+               oal_uuid_t *network_uuid, oal_mesh_capabilities_t *caps);
+
+/**
+ * @brief Security provision a device to Mesh Network
+ *
+ * @remarks  Provisioner application can provision device after
+ * scanning for device beacons.
+ * @remarks  Provisioner application should set the Provisioning
+ * capabilities before starting provision.
+ *
+ * @pre OAl API should be enabled with mesh_enable().
+ *
+ * @see  mesh_enable()
+ * @see  mesh_network_set_provisioning_capabilities()
+ * @see  mesh_network_provision_device()
+ */
+oal_status_t mesh_network_provision_device(oal_uuid_t* network_uuid,
+               oal_uuid_t *dev_uuid);
+
+
+/**
+ * @brief Send data for provisioning like NetKey, Primary unicast
+ *
+ * @see  mesh_enable()
+ */
+oal_status_t mesh_network_send_provisioning_data(oal_uuid_t* network_uuid,
+               uint16_t netkey_idx, uint16_t unicast);
+
+/**
+ * @brief Send Reply to Ongoing Security Provisioning
+ *
+ * @remarks  Tizen supports only one Provisioning or Join
+ * Call simulatneously.
+ *
+ * @pre OAl API should be enabled with mesh_enable().
+ *
+ * @see  mesh_enable()
+ * @see  mesh_network_provision_device()
+ * @see  cb_mesh_authentication_request()
+ */
+oal_status_t mesh_authentication_reply(oal_mesh_variant_authentication_e type,
+               const char* auth_value);
+
+/**
+ * @brief Cancels an ongoing security provisioning
+ *
+ * @remarks  Mesh stack does not support Cancelling Ongoing
+ * provisiong currently.
+ *
+ * @pre OAl API should be enabled with mesh_enable().
+ *
+ * @see  mesh_enable()
+ * @see  mesh_network_provision_device()
+ */
+oal_status_t mesh_provisioning_cancel(oal_uuid_t *local_device_uuid);
+
+/**
+ * @brief Sends Configuration Client message originated from Local Node
+ *
+ * @remarks Local Configuration client can send message to both local
+ * & remote Configuration Server.
+ *
+ * @pre OAl API should be enabled with mesh_enable().
+ *
+ * @see  mesh_enable()
+ * @see  cb_mesh_conf_message()
+ */
+oal_status_t mesh_conf_send_message(oal_uuid_t *network_uuid,
+               int16_t dest, bool is_devkey_remote,
+                       uint16_t netkey_idx, uint8_t *buf, int len);
+
+/**
+ * @brief Sends Configuration Client Key (NetKey & AppKey Add/Update)
+ * messages originated from Local Node
+ *
+ * @remarks Local Configuration client can send message to both
+  * local & remote Configuration Server.
+ *
+ * @pre OAl API should be enabled with mesh_enable().
+ *
+ * @see  mesh_enable()
+ * @see  cb_mesh_conf_message()
+ */
+oal_status_t mesh_conf_send_key_message(oal_uuid_t *network_uuid,
+               uint16_t dest, bool is_netkey,
+                       bool is_update, int key_idx, int netkey_idx);
+
+
+/**
+ * @brief Sends Application message to be encrypted with appplication key
+ *
+ * @remarks These messages are generated by Models, which are
+ * implemenetd by Tizen Application.
+ * @remarks Tizen Mesh Framework will not handle these mesages directly
+ * and only transport these to and from application.
+ *
+ * @pre OAl API should be enabled with mesh_enable().
+ *
+ * @see  mesh_enable()
+ * @see cb_mesh_model_message()
+ */
+oal_status_t mesh_model_send_message(oal_uuid_t *network_uuid,
+               uint16_t dest, int appkey_idx,
+                       int netkey_idx, uint8_t *buf, int len);
+
+#endif /* OAL_MESH_H_ */