2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <bluetooth.h>
20 #include "oal-event.h"
21 #include "oal-internal.h"
22 #include "oal-manager.h"
23 #include "oal-utils.h"
24 #include "oal-common.h"
27 #define CHECK_OAL_TDS_ENABLED() \
29 if (tds_api == NULL) { \
30 BT_ERR("TDS Not Enabled"); \
31 return OAL_STATUS_NOT_READY; \
35 static const bttds_interface_t *tds_api;
37 static void tds_activation_requested_cb(char *address, unsigned char org_id, unsigned char *data, unsigned int data_len)
39 event_tds_activation_requested_t *event = g_malloc0(sizeof(event_tds_activation_requested_t));
40 g_strlcpy(event->address, address, BT_ADDRESS_STR_LEN);
41 event->org_id = org_id;
42 memcpy(event->tds_data, data, sizeof(event->tds_data));
43 event->data_len = data_len;
45 send_event(OAL_EVENT_TDS_ACTIVATION_REQUESTED, event, sizeof(event_tds_activation_requested_t));
48 static bttds_callbacks_t tds_callbacks = {
49 .activation_requested_cb = tds_activation_requested_cb,
52 oal_status_t tds_enable(void)
54 const bt_interface_t * blued_api;
57 /* Get stack interface */
58 blued_api = (const bt_interface_t *)adapter_get_stack_interface();
60 if (blued_api == NULL) {
61 BT_ERR("Stack is not initialized");
62 return OAL_STATUS_NOT_READY;
66 BT_WARN("TDS Interface is already initialized...");
67 return OAL_STATUS_ALREADY_DONE;
70 tds_api = (const bttds_interface_t *)blued_api->get_profile_interface(BT_PROFILE_TDS_ID);
71 if (tds_api == NULL) {
72 BT_ERR("TDS interface failed");
73 return OAL_STATUS_INTERNAL_ERROR;
76 if ((ret = tds_api->init(&tds_callbacks)) != BT_STATUS_SUCCESS) {
77 BT_ERR("Error: Unable to initialise TDS :%s", status2string(ret));
80 return convert_to_oal_status(ret);
83 BT_INFO("TDS successfully initialized");
84 return OAL_STATUS_SUCCESS;
87 oal_status_t tds_disable(void)
94 return OAL_STATUS_SUCCESS;
97 oal_status_t tds_provider_send_activation_response(unsigned char response,
98 unsigned char *data, unsigned int data_len)
102 CHECK_OAL_TDS_ENABLED();
104 ret = tds_api->send_activation_response(response, data, data_len);
105 if (ret != BT_STATUS_SUCCESS) {
106 BT_ERR("send_activation_response() failed: %s", status2string(ret));
107 return convert_to_oal_status(ret);
109 return OAL_STATUS_SUCCESS;
112 oal_status_t tds_provider_set_block_data(unsigned char *data, unsigned int data_len)
116 CHECK_OAL_TDS_ENABLED();
118 ret = tds_api->set_block_data(data, data_len);
119 if (ret != BT_STATUS_SUCCESS) {
120 BT_ERR("set_block_data() failed: %s", status2string(ret));
121 return convert_to_oal_status(ret);
123 return OAL_STATUS_SUCCESS;
126 oal_status_t tds_provider_unregister()
130 CHECK_OAL_TDS_ENABLED();
132 ret = tds_api->unregister_provider();
133 if (ret != BT_STATUS_SUCCESS) {
134 BT_ERR("unregister_provider() failed: %s", status2string(ret));
135 return convert_to_oal_status(ret);
137 return OAL_STATUS_SUCCESS;
140 oal_status_t tds_provider_register()
144 CHECK_OAL_TDS_ENABLED();
146 ret = tds_api->register_provider();
147 if (ret != BT_STATUS_SUCCESS) {
148 BT_ERR("register_provider() failed: %s", status2string(ret));
149 return convert_to_oal_status(ret);
151 return OAL_STATUS_SUCCESS;