#include <time.h>
#include <sys/time.h>
#include <ell/ell.h>
+#include <actd/unit_control.h>
#include "bluetooth-api.h"
#include "bt-internal-types.h"
#include <oal-mesh.h>
+#define MESH_SYSTEMD_SERVICE_NAME "bluetooth-mesh.service"
+
/* Event handlers */
static void __bt_mesh_handle_pending_request_info(int result,
int service_function, void *param,
_bt_service_method_return(req_info->context,
out_param, result);
_bt_free_info_from_invocation_list(req_info);
- g_free(req_info->user_data);
g_array_free(out_param, TRUE);
}
break;
g_array_append_vals(out_param, network, sizeof(bluetooth_mesh_network_t));
_bt_service_method_return(req_info->context, out_param, result);
_bt_free_info_from_invocation_list(req_info);
- g_free(req_info->user_data);
g_array_free(out_param, TRUE);
}
break;
_bt_service_method_return(req_info->context,
out_param, result);
_bt_free_info_from_invocation_list(req_info);
- g_free(req_info->user_data);
g_array_free(out_param, TRUE);
}
break;
_bt_mesh_util_convert_hex_to_string(
(uint8_t *) event->dev_uuid.uuid, 16, status_data.dev_uuid,
BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
+ BT_INFO("Mesh: Provision Status: Device UUID [%s]", status_data.dev_uuid);
+ BT_INFO("Mesh: Provision Status: Net UUID [%s]", status_data.net_uuid);
+ BT_INFO("Mesh: Provision Status: Result [%d]", event->status);
+ if (event->status == OAL_STATUS_SUCCESS)
+ BT_INFO("Mesh: Provisioning status : SUCCESS");
+ else
+ BT_INFO("Mesh: Provisioning status : FAIL");
BT_DBG("Request Sender: [%s]", req_info->sender);
if (!g_strcmp0(req_data->net_uuid, status_data.net_uuid)) {
sizeof(bluetooth_mesh_provisioning_request_t));
_bt_service_method_return(req_info->context, out_param, result);
_bt_free_info_from_invocation_list(req_info);
- g_free(req_info->user_data);
g_array_free(out_param, TRUE);
}
break;
g_array_append_vals(out_param, &event->key_idx, sizeof(guint16));
_bt_service_method_return(req_info->context, out_param, result);
_bt_free_info_from_invocation_list(req_info);
- g_free(req_info->user_data);
g_array_free(out_param, TRUE);
}
break;
g_array_append_vals(out_param, &event->app_idx, sizeof(guint16));
_bt_service_method_return(req_info->context, out_param, result);
_bt_free_info_from_invocation_list(req_info);
- g_free(req_info->user_data);
g_array_free(out_param, TRUE);
}
break;
if (event->status != OAL_STATUS_SUCCESS)
result = BLUETOOTH_ERROR_INTERNAL;
-
/* Handle DBUS Context return */
if (event->op == OAL_MESH_KEY_ADD) {
+ BT_INFO("Mesh: Appkey Add event");
if (result == BLUETOOTH_ERROR_NONE)
_bt_mesh_network_handle_appkey_added(
event->net_uuid.uuid, event->net_idx, event->app_idx);
__bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_ADD_APPKEY,
event, sizeof(event_mesh_netkey_operation_t));
} else if (event->op == OAL_MESH_KEY_DELETE) {
+ BT_INFO("Mesh: Appkey Delete event");
if (result == BLUETOOTH_ERROR_NONE)
_bt_mesh_network_handle_appkey_deleted(
event->net_uuid.uuid, event->net_idx, event->app_idx);
__bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_DELETE_APPKEY,
event, sizeof(event_mesh_netkey_operation_t));
} else if (event->op == OAL_MESH_KEY_UPDATE) {
+ BT_INFO("Mesh: Appkey Update event");
__bt_mesh_handle_pending_request_info(result, BT_MESH_NETWORK_UPDATE_APPKEY,
event, sizeof(event_mesh_netkey_operation_t));
}
GVariant *out_var = NULL, *param = NULL;
GArray *info = NULL;
bluetooth_mesh_network_t network;
-
int result = BLUETOOTH_ERROR_NONE;
- if (event->status != OAL_STATUS_SUCCESS)
+ if (event->status != OAL_STATUS_SUCCESS) {
+ BT_INFO("Mesh: Scan Finished: status:: FAILED!");
result = BLUETOOTH_ERROR_INTERNAL;
-
+ } else
+ BT_INFO("Mesh: Scan Finished: status:: SUCCESS!");
/* Handle Scan finsihed event */
if (result == BLUETOOTH_ERROR_NONE) {
event_mesh_provisioning_status_t *status)
{
int result = BLUETOOTH_ERROR_NONE;
+ BT_INFO("Mesh: Provisioning started");
__bt_mesh_handle_pending_request_info(result,
BT_MESH_NETWORK_PROVISION_DEVICE,
- status, sizeof(event_mesh_scan_status_t));
+ status, sizeof(event_mesh_provisioning_status_t));
_bt_mesh_set_provisioning_state(true);
}
event_mesh_provisioning_status_t *status)
{
int result = BLUETOOTH_ERROR_INTERNAL;
-
+ BT_INFO("Mesh: Provisioning failed!!");
__bt_mesh_handle_pending_request_info(result,
BT_MESH_NETWORK_PROVISION_DEVICE,
- status, sizeof(event_mesh_scan_status_t));
+ status, sizeof(event_mesh_provisioning_status_t));
_bt_mesh_set_provisioning_state(false);
}
GVariant *out_var = NULL, *param = NULL;
GArray *info = NULL;
bluetooth_mesh_provisioning_result_t prov_result;
+ BT_INFO("Mesh: Provisioning Finished!");
memset(&prov_result, 0x00,
sizeof(bluetooth_mesh_provisioning_result_t));
if (event->status != OAL_STATUS_SUCCESS)
prov_result.result = BLUETOOTH_ERROR_INTERNAL;
- prov_result.result = BLUETOOTH_ERROR_NONE;
+ else
+ prov_result.result = BLUETOOTH_ERROR_NONE;
prov_result.reason = event->reason;
prov_result.unicast = event->unicast;
/* Add Remote Node entry in Local CDB */
if (event->status == OAL_STATUS_SUCCESS) {
+ BT_INFO("Mesh: Provisioning done, add node to Network");
+ BT_INFO("Mesh: Node UUID [%s]", prov_result.dev_uuid);
+ BT_INFO("Mesh: Node Unicast[0x%2.2x] Element Count [%d]",
+ event->unicast, event->count);
+
_bt_mesh_network_add_remote_node(
event->net_uuid.uuid, event->dev_uuid.uuid,
event->unicast, event->count);
}
+ /* Unset provisioning state */
+ _bt_mesh_set_provisioning_state(false);
}
static void __handle_mesh_network_provisioning_data_requested_event(
(uint8_t *) event->net_uuid.uuid, 16, auth_req.net_uuid,
BLUETOOTH_MESH_NETWORK_UUID_STRING_LENGTH + 1);
+ BT_INFO("Mesh: Authentication Requested by Device: Network [%s]",
+ auth_req.net_uuid);
info = g_array_new(FALSE, FALSE, sizeof(gchar));
g_array_append_vals(info, &auth_req,
sizeof(bluetooth_mesh_authentication_request_t));
static void __handle_mesh_events(int event_type,
gpointer event_data)
{
+ BT_INFO("Mesh: Got Mesh event!!! event type [%d]", event_type);
+ if (event_type == OAL_EVENT_MESH_PROVISIONING_STARTED)
+ BT_INFO("Mesh: Provisioning started event");
+
switch (event_type) {
case OAL_EVENT_MESH_NETWORK_ATTACHED:
__handle_mesh_network_attached_event(
BT_PERMANENT_LOG("Mesh: Network Scan Result!!");
break;
case OAL_EVENT_MESH_PROVISIONING_STARTED:
+ BT_INFO("Mesh: Network Provisioning Started");
__handle_mesh_network_provisioning_started_event(
(event_mesh_provisioning_status_t*)event_data);
BT_PERMANENT_LOG("Mesh: Network Provisioning Started");
- break;
+ break;
case OAL_EVENT_MESH_PROVISIONING_FAILED:
+ BT_INFO("Mesh: Network Provisioning Failed!!!!");
__handle_mesh_network_provisioning_failed_event(
(event_mesh_provisioning_status_t*)event_data);
BT_PERMANENT_LOG("Mesh: Network Provisioning Failed");
int _bt_mesh_init(void)
{
+ int ret = UNIT_CONTROL_OK;
oal_status_t status = OAL_STATUS_SUCCESS;
+ /* Launch bluetooth-meshd */
+ ret = actd_start_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM,
+ MESH_SYSTEMD_SERVICE_NAME, 5000);
+
+ if (ret != UNIT_CONTROL_OK) {
+ BT_ERR("Failed to call systemact service: %d", ret);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
status = mesh_enable();
if (OAL_STATUS_SUCCESS != status) {
BT_ERR("Mesh: Failed to initialize Mesh profile, status: %d",
int _bt_mesh_deinit(void)
{
oal_status_t status = OAL_STATUS_SUCCESS;
+ int ret = UNIT_CONTROL_OK;
+
+ /* Terminate bluetooth-meshd */
+ ret = actd_stop_unit(UNIT_CONTROL_BUS_TYPE_SYSTEM,
+ MESH_SYSTEMD_SERVICE_NAME, 5000);
+
+ if (ret != UNIT_CONTROL_OK)
+ BT_ERR("Failed to call systemact service: %d", ret);
status = mesh_disable();
if (OAL_STATUS_SUCCESS != status) {