From 0bd1781c9d77ae762ab7415278f6205d9700fe1e Mon Sep 17 00:00:00 2001 From: Abhay Agarwal Date: Thu, 30 Jul 2020 22:26:47 +0530 Subject: [PATCH] Mesh: Add OAL interface for Mesh message execution Change-Id: Ib97aa28dd5b8fba288898f5e6763f9bb5997b057 Signed-off-by: Abhay Agarwal --- bt-oal/include/oal-event.h | 1 + bt-oal/include/oal-mesh.h | 14 ++++++++++++-- bt-oal/oal-mesh.c | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/bt-oal/include/oal-event.h b/bt-oal/include/oal-event.h index 4360a88..fb2aca4 100644 --- a/bt-oal/include/oal-event.h +++ b/bt-oal/include/oal-event.h @@ -198,6 +198,7 @@ extern "C" { EVENT(OAL_EVENT_MESH_NETKEY_EXECUTE_EVENT) /* Subnet Operations (Add/Update/Delete) Event */\ EVENT(OAL_EVENT_MESH_APPKEY_EXECUTE_EVENT) /* AppKey Operations (Add/Update/Delete) Event */\ EVENT(OAL_EVENT_MESH_DEVKEY_MESSAGE_RECEIVED) /* DevKey message received Event */\ + EVENT(OAL_EVENT_MESH_MESSAGE_RECEIVED) /* Message received Event */\ EVENT(OAL_EVENT_END) /* End of event*/\ diff --git a/bt-oal/include/oal-mesh.h b/bt-oal/include/oal-mesh.h index 853e139..9084aeb 100644 --- a/bt-oal/include/oal-mesh.h +++ b/bt-oal/include/oal-mesh.h @@ -27,6 +27,7 @@ /* Start of BLE Mesh structures and enum declarations */ #define OAL_MESH_DEVKEY_MSG_BUF_MAX 2048 +#define OAL_MESH_MSG_BUF_MAX 2048 /* Mesh Key Operation Enums (For Appkey & NetKey) */ typedef enum { @@ -207,6 +208,16 @@ typedef struct { uint8_t data[OAL_MESH_DEVKEY_MSG_BUF_MAX]; } event_mesh_devkey_message_t; +typedef struct { + oal_uuid_t net_uuid; + uint16_t source; /* address of remote element which sent msg */ + uint16_t dest; /* address of local element which received msg*/ + uint16_t key_idx; + uint16_t data_len; + uint8_t data[OAL_MESH_MSG_BUF_MAX]; +} event_mesh_message_t; + + /** * @brief Enables Bluetooth Mesh Stack * @@ -422,7 +433,6 @@ oal_status_t mesh_conf_send_key_message(oal_uuid_t *network_uuid, * @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); + uint16_t dest, uint16_t appkey_idx, uint8_t *buf, int len); #endif /* OAL_MESH_H_ */ diff --git a/bt-oal/oal-mesh.c b/bt-oal/oal-mesh.c index c3cffc3..c4cab7a 100644 --- a/bt-oal/oal-mesh.c +++ b/bt-oal/oal-mesh.c @@ -67,6 +67,9 @@ static void mesh_network_appkey_execute_callback(bt_status_t status, static void mesh_devkey_message_received_callback(bt_uuid_t *net_uuid, uint16_t source_addr, bool is_remote_devkey, uint16_t netkey_idx, uint16_t ata_len, uint8_t *data); +static void mesh_message_received_callback(bt_uuid_t *net_uuid, + uint16_t source_addr, uint16_t dest_addr, + uint16_t key_idx, uint16_t data_len, uint8_t *data); static btmesh_callbacks_t sBluetoothMeshCallbacks = { @@ -81,6 +84,7 @@ static btmesh_callbacks_t sBluetoothMeshCallbacks = { .netkey_execute_cb = mesh_network_netkey_execute_callback, .appkey_execute_cb = mesh_network_appkey_execute_callback, .devkey_msg_cb = mesh_devkey_message_received_callback, + .msg_cb = mesh_message_received_callback, }; /* Mesh HAL event handlers */ @@ -262,6 +266,24 @@ static void mesh_devkey_message_received_callback(bt_uuid_t *net_uuid, sizeof(event_mesh_devkey_message_t), NULL); } +static void mesh_message_received_callback(bt_uuid_t *net_uuid, + uint16_t source_addr, uint16_t dest_addr, uint16_t key_idx, + uint16_t data_len, uint8_t *data) +{ + event_mesh_message_t *event = g_new0(event_mesh_message_t, 1); + + BT_INFO("Mesh Event: Model Message Received"); + event->source = source_addr; + event->dest = dest_addr; + event->key_idx = key_idx; + event->data_len = data_len; + memcpy(event->net_uuid.uuid, net_uuid->uu, sizeof(bt_uuid_t)); + memcpy(event->data, data, data_len); + + send_event_bda_trace(OAL_EVENT_MESH_MESSAGE_RECEIVED, event, + sizeof(event_mesh_message_t), NULL); +} + oal_status_t mesh_enable(void) { int ret; @@ -415,6 +437,25 @@ oal_status_t mesh_conf_send_key_message(oal_uuid_t *network_uuid, return OAL_STATUS_SUCCESS; } +oal_status_t mesh_model_send_message(oal_uuid_t *network_uuid, + uint16_t dest, uint16_t appkey_idx, + uint8_t *buf, int len) +{ + int ret = BT_STATUS_SUCCESS; + API_TRACE(); + CHECK_OAL_MESH_ENABLED(); + + ret = mesh_api->msg_execute((bt_uuid_t*)network_uuid, + dest, appkey_idx, buf, len); + if (ret != BT_STATUS_SUCCESS) { + BT_ERR("MESH: Key Configuration Message sending failed: %s", + status2string(ret)); + return convert_to_oal_status(ret); + } + + return OAL_STATUS_SUCCESS; +} + oal_status_t mesh_network_provision_device(oal_uuid_t* network_uuid, oal_uuid_t *dev_uuid) { -- 2.7.4