2 * Open Adaptation Layer (OAL)
4 * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include <bluetooth.h>
22 #include "oal-event.h"
23 #include "oal-internal.h"
24 #include "oal-manager.h"
25 #include "oal-adapter-mgr.h"
26 #include "oal-utils.h"
28 #include "oal-common.h"
30 #define DEV_APPEARANCE 0x0000
31 #define DEFAULT_GATT_CLIENT_UUID "0000A00A-1111-1111-0123-456789ABCDEF"
32 #define MAX_PROP_LEN 95 /* SVACE WGID: 324403*/
33 #define MAX_PERM_LEN 80 //Fix for svace wgid:324402
35 #define NUM_SERVER_INST 10 // Maximum slots supported by stack is set to 10
36 #define CHECK_OAL_GATT_ENABLED() \
38 if (gatt_api == NULL) { \
39 BT_ERR("GATT Not Enabled"); \
40 return OAL_STATUS_NOT_READY; \
44 #define CHECK_SERVER_INSTANCE(instance_id) \
46 if (instance_id < 1 || instance_id > NUM_SERVER_INST) { \
47 BT_ERR("Invalid Instance"); \
48 return OAL_STATUS_INVALID_PARAM; \
52 #define CHECK_SERVER_REGISTRATION(instance_id) \
54 if (gatt_servers[instance_id - 1].server_id < 0) {\
55 BT_INFO("GATT server registeration is not done for server Instance : %d", instance_id);\
56 return OAL_STATUS_INTERNAL_ERROR;\
60 #define CHECK_CORRECT_SERVER_ID(instance_id, server_if, server_inst)\
62 for (instance_id = 1 ; instance_id <= NUM_SERVER_INST; instance_id++) { \
63 if (gatt_servers[instance_id - 1].server_id == server_if) { \
64 server_inst = instance_id; \
70 #define PRINT_ADV_DATA(length, manuf_data, data_type) \
72 char * buf_str = g_malloc0(3*length + 1);\
73 if (NULL != buf_str) { \
74 convert_hex_2_str(manuf_data, length, buf_str);\
75 if (TRUE == data_type) \
76 BT_INFO("Scan Response Data:%s\n", buf_str);\
78 BT_INFO("Advertising Data:%s\n", buf_str);\
83 #define CHECK_CLIENT_REGISTRATION(client_id) \
85 if (client_id <= 0) { \
86 BT_DBG("No client registered yet...");\
87 return OAL_STATUS_INTERNAL_ERROR;\
91 #define CHECK_CLIENT_CONNECTION(conn_id) \
94 BT_ERR("No active connection");\
95 return OAL_STATUS_INTERNAL_ERROR;\
102 GATT_INS_DATA_SETTING,
114 const char *oal_device_type[] = {
125 } oal_pending_gattc_req_e;
127 static const btgatt_interface_t * gatt_api;
128 static gboolean cur_adv_state[NUM_SERVER_INST];
129 static gatt_server_t gatt_servers[NUM_SERVER_INST];
131 /* Forward declarations of GATT Server callbacks */
132 static void cb_gatts_register_app(int status, int server_if, bt_uuid_t *uuid);
133 static void cb_gatts_multi_adv_enable(int server_if, int status);
134 static void cb_gatts_multi_adv_set_inst_data(int server_if, int status);
135 static void cb_gatts_multi_adv_disable(int server_if, int status);
136 static void cb_gatts_multi_adv_update(int server_if, int status);
138 static void cb_gatts_listen(int status, int server_if);
141 static void cb_gatts_service_added(int status, int server_if, btgatt_srvc_id_t *srvc_id, int srvc_handle);
142 static void cb_gatts_included_service_added(int status, int server_if, int srvc_handle, int incl_srvc_handle);
143 static void cb_gatts_characteristic_added(int status, int server_if, bt_uuid_t *char_id, int srvc_handle, int char_handle);
144 static void cb_gatts_descriptor_added(int status, int server_if, bt_uuid_t *descr_id, int srvc_handle, int descr_handle);
146 static void cb_gatts_service_started(int status, int server_if, int srvc_handle);
147 static void cb_gatts_service_stopped(int status, int server_if, int srvc_handle);
148 static void cb_gatts_service_deleted(int status, int server_if, int srvc_handle);
150 static void cb_gatts_request_read(int conn_id, int trans_id, bt_bdaddr_t *bda, int attr_handle, int offset, bool is_long);
151 static void cb_gatts_request_write(int conn_id, int trans_id, bt_bdaddr_t *bda, int attr_handle, int offset, int length,
152 bool need_rsp, bool is_prep, uint8_t* value);
153 static void cb_gatts_response_confirmation(int status, int handle);
155 static void cb_gatts_acquire_write(int fd, int conn_id, int trans_id, int attr_handle, bt_bdaddr_t*);
156 static void cb_gatts_acquire_notify(int fd, int conn_id, int trans_id, int attr_handle);
158 static void cb_indication_confirmation(int conn_id, int trans_id, int attr_handle, bt_bdaddr_t *bda);
159 static void cb_gatts_connection(int conn_id, int server_if, int connected, bt_bdaddr_t *bda);
161 static void cb_gatts_mtu_changed(int conn_id, int mtu);
164 static void cb_notifcation_changed(int conn_id, int trans_id, int attr_handle, bool notify, bt_bdaddr_t *bda);
167 /************************************HAL Interface *************************************/
169 /*TODO GATT Server callbacks will be implemented in subsequent patches */
170 static const btgatt_server_callbacks_t btgatt_server_callbacks = {
171 cb_gatts_register_app,
173 cb_gatts_service_added,
174 cb_gatts_included_service_added,
175 cb_gatts_characteristic_added,
176 cb_gatts_descriptor_added,
177 cb_gatts_service_started,
178 cb_gatts_service_stopped,
179 cb_gatts_service_deleted,
180 cb_indication_confirmation,
181 cb_gatts_request_read,
182 cb_gatts_request_write,
183 NULL, /*cb_gatts_request_exec_write,*/
184 cb_gatts_response_confirmation,
186 cb_gatts_multi_adv_enable,
187 cb_gatts_multi_adv_update,
188 cb_gatts_multi_adv_set_inst_data,
189 cb_gatts_multi_adv_disable,
190 cb_gatts_mtu_changed,
192 cb_notifcation_changed,
194 cb_gatts_acquire_write,
195 cb_gatts_acquire_notify
198 /* Forward declaration for GATT client callbacks */
199 static void cb_gattc_register_app(int status, int clientIf, bt_uuid_t *app_uuid);
200 static void cb_gattc_scan_result(bt_bdaddr_t* bdaddress, int rssi, uint8_t *adv_data);
201 static void cb_gattc_connection(int conn_id, int status, int client_if, bt_bdaddr_t* bda);
202 static void cb_gattc_disconnect(int conn_id, int status, int client_if, bt_bdaddr_t* bda);
203 static void cb_gattc_search_result(int conn_id, btgatt_srvc_id_t *srvc_id);
204 static void cb_gattc_search_complete(int conn_id, int status);
205 static void cb_gattc_get_characteristics(int conn_id, int status, btgatt_srvc_id_t *srvc_id,
206 btgatt_gatt_id_t *char_id, int char_prop);
207 static void cb_gattc_get_descriptor(int conn_id, int status, btgatt_srvc_id_t *srvc_id,
208 btgatt_gatt_id_t *char_id, btgatt_gatt_id_t *descr_id);
209 static void cb_gattc_read_characteristic(int conn_id, int status, btgatt_read_params_t *p_data);
210 static void cb_gattc_read_descriptor(int conn_id, int status, btgatt_read_params_t *p_data);
211 static void cb_gattc_write_characteristic(int conn_id, int status, btgatt_write_params_t *p_data);
212 static void cb_gattc_write_descriptor(int conn_id, int status, btgatt_write_params_t *p_data);
213 static void cb_gattc_register_for_notification(int conn_id, int registered, int status,
214 btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id);
215 static void cb_gattc_notify(int conn_id, btgatt_notify_params_t *p_data);
217 /*TODO GATT CLient callbacks will be implemented in subsequent patches */
218 static const btgatt_client_callbacks_t btgatt_client_callbacks = {
219 cb_gattc_register_app,
220 cb_gattc_scan_result,
221 cb_gattc_connection, /*cb_gattc_connection*/
222 cb_gattc_disconnect, /*cb_gattc_disconnect*/
223 cb_gattc_search_complete, /*cb_gattc_search_complete*/
224 cb_gattc_search_result, /*cb_gattc_search_result*/
225 cb_gattc_get_characteristics, /*cb_gattc_get_characteristics*/
226 cb_gattc_get_descriptor, /*cb_gattc_get_descriptor*/
227 NULL, /*cb_gattc_get_included_service*/
228 cb_gattc_register_for_notification, /*cb_gattc_register_for_notification*/
229 cb_gattc_notify, /*cb_gattc_notify*/
230 cb_gattc_read_characteristic, /*cb_gattc_read_characteristic*/
231 cb_gattc_write_characteristic, /*cb_gattc_write_characteristic*/
232 cb_gattc_read_descriptor, /*cb_gattc_read_descriptor*/
233 cb_gattc_write_descriptor, /*cb_gattc_write_descriptor*/
234 NULL, /*cb_gattc_execute_write*/
235 NULL, /*cb_gattc_remote_rssi*/
236 NULL, /*cb_gattc_configure_mtu_cmpl*/
237 #ifdef PLATFORM_ANDROID_HAL
238 NULL, /*cb_scan_filter_cfg*/
239 NULL, /*cb_scan_filter_param*/
240 NULL, /*cb_scan_filter_status*/
241 NULL, /*cb_congestion*/
242 NULL, /*cb_batchscan_cfg_storag*/
243 NULL, /*cb_batchscan_enb_disable*/
244 NULL, /*cb_batchscan_reports*/
245 NULL, /*cb_batchscan_threshold*/
246 NULL, /*cb_track_adv_event*/
250 static btgatt_callbacks_t btgatt_callbacks = {
251 sizeof(btgatt_callbacks_t),
252 &btgatt_client_callbacks,
253 &btgatt_server_callbacks
256 /*******************************GATT Initialisation - Deinitialisation********************************/
257 oal_status_t gatt_enable(void)
259 const bt_interface_t * blued_api;
263 for (i = 0; i < NUM_SERVER_INST; i++) {
264 gatt_servers[i].server_id = -1;
265 gatt_servers[i].state = GATT_INS_DISABLED;
266 memset(&gatt_servers[i].uuid, 0, sizeof(oal_uuid_t));
267 cur_adv_state[i] = FALSE;
270 /* Get stack interface */
271 blued_api = (const bt_interface_t *) adapter_get_stack_interface();
273 if (blued_api == NULL) {
274 BT_ERR("Stack is not initialized");
275 return OAL_STATUS_NOT_READY;
279 BT_WARN("GATT Interface is already initialized...");
280 return OAL_STATUS_ALREADY_DONE;
283 gatt_api = (const btgatt_interface_t *)blued_api->get_profile_interface(BT_PROFILE_GATT_ID);
284 if (gatt_api == NULL) {
285 BT_ERR("GATT interface failed");
286 return OAL_STATUS_INTERNAL_ERROR;
289 if ((ret = gatt_api->init(&btgatt_callbacks)) != BT_STATUS_SUCCESS) {
290 BT_ERR("Error: Unable to initialise GATT :%s", status2string(ret));
293 return convert_to_oal_status(ret);
296 BT_INFO("GATT successfully initialized");
297 return OAL_STATUS_SUCCESS;
300 oal_status_t gatt_disable(void)
308 for (i = 0; i < NUM_SERVER_INST; i++) {
309 gatt_servers[i].server_id = -1;
310 gatt_servers[i].state = GATT_INS_DISABLED;
311 memset(&gatt_servers[i].uuid, 0, sizeof(oal_uuid_t));
313 return OAL_STATUS_SUCCESS;
316 /************************************GATT Server Functions*************************************/
318 oal_status_t gatts_register(oal_uuid_t* server_uuid)
320 char str[2*BT_UUID_STRING_MAX];
321 int ret = OAL_STATUS_SUCCESS;
324 CHECK_OAL_GATT_ENABLED();
325 uuid_to_stringname((service_uuid_t*)server_uuid->uuid, str);
326 API_TRACE("Register the server instance: UUID: [%s]", str);
328 for (i = 0; i < NUM_SERVER_INST; i++) {
329 if (memcmp(server_uuid->uuid, gatt_servers[i].uuid.uuid, sizeof(oal_uuid_t)) == 0) {
330 if (gatt_servers[i].server_id != -1) {
331 BT_ERR("This is resevered UUID for easy set up application i = %d \
332 gatt_servers[i].server_id = %d", i, gatt_servers[i].server_id);
333 return OAL_STATUS_ALREADY_DONE;
338 ret = gatt_api->server->register_server((bt_uuid_t*)server_uuid);
340 if (ret != BT_STATUS_SUCCESS) {
341 BT_ERR("GATT server registration with UUID:%s failed: %s", str, status2string(ret));
342 return convert_to_oal_status(ret);
344 return OAL_STATUS_SUCCESS;
347 oal_status_t gatts_unregister(int instance_id)
349 int ret = OAL_STATUS_SUCCESS;
350 API_TRACE("Unregister the registered server, instance_id: %d", instance_id);
352 CHECK_OAL_GATT_ENABLED();
353 CHECK_SERVER_INSTANCE(instance_id);
354 CHECK_SERVER_REGISTRATION(instance_id);
356 ret = gatt_api->server->unregister_server(gatt_servers[instance_id - 1].server_id);
358 if (ret != BT_STATUS_SUCCESS) {
359 BT_ERR("GATT server unregistration failed: %d", instance_id);
360 return convert_to_oal_status(ret);
363 gatt_servers[instance_id-1].server_id = -1;
364 gatt_servers[instance_id-1].state = GATT_INS_DISABLED;
366 if (instance_id != 1 && instance_id != 2)
367 memset(&gatt_servers[instance_id-1].uuid, 0, sizeof(oal_uuid_t));
369 return OAL_STATUS_SUCCESS;
372 /* Legacy Advertisement */
373 oal_status_t gatts_start_listen(int instance_id, gboolean enable)
375 int ret = OAL_STATUS_SUCCESS;
376 API_TRACE("server-id:%d enable: %d", gatt_servers[instance_id-1].server_id, enable);
378 CHECK_OAL_GATT_ENABLED();
379 CHECK_SERVER_INSTANCE(instance_id);
380 CHECK_SERVER_REGISTRATION(instance_id);
382 ret = gatt_api->server->listen(gatt_servers[instance_id-1].server_id, enable);
384 if (ret != BT_STATUS_SUCCESS) {
385 BT_ERR("Error:Advertising start/stop on server-id:%d failed With Status: [%s]",
386 gatt_servers[instance_id-1].server_id, status2string(ret));
387 return convert_to_oal_status(ret);
390 return OAL_STATUS_SUCCESS;
393 oal_status_t gatts_stop_advertising(int instance_id)
395 int ret = OAL_STATUS_SUCCESS;
396 API_TRACE("Stop advertising");
398 CHECK_OAL_GATT_ENABLED();
399 CHECK_SERVER_INSTANCE(instance_id);
400 CHECK_SERVER_REGISTRATION(instance_id);
402 ret = gatt_api->server->listen(gatt_servers[instance_id - 1].server_id, FALSE);
404 if (ret != BT_STATUS_SUCCESS) {
405 BT_ERR("Stop Advertising failed for server Instance:%d With Status: %s",
406 instance_id, status2string(ret));
407 return convert_to_oal_status(ret);
409 return OAL_STATUS_SUCCESS;
413 /* Below API's need to be removed as they are hardcoded API's.
414 If at all, product specific API's are required to set specific data, then new naming should
415 be adopted for these API's */
416 oal_status_t gatts_set_advertising_params(int instance_id, float min_intv, float max_intv)
418 int ret = OAL_STATUS_SUCCESS;
420 API_TRACE("Set advertising params min_int:%f, max_int:%f", min_intv, max_intv);
421 CHECK_OAL_GATT_ENABLED();
422 CHECK_SERVER_INSTANCE(instance_id);
423 CHECK_SERVER_REGISTRATION(instance_id);
425 /* Historically used for Legacy Advertising */
426 return OAL_STATUS_NOT_SUPPORT;
429 oal_status_t gatts_set_advertising_data(int instance_id, uint16_t manufac_len, char* manufac_data)
431 int ret = OAL_STATUS_SUCCESS;
433 API_TRACE("Set advertising data");
434 CHECK_OAL_GATT_ENABLED();
435 CHECK_SERVER_INSTANCE(instance_id);
436 CHECK_SERVER_REGISTRATION(instance_id);
438 /* Historically used for Legacy Advertising */
439 return OAL_STATUS_NOT_SUPPORT;
442 oal_status_t gatts_set_scan_response(int instance_id, uint16_t manufac_len, char* manufac_data)
444 int ret = OAL_STATUS_SUCCESS;
446 API_TRACE("Set Scan Response data");
447 CHECK_OAL_GATT_ENABLED();
448 CHECK_SERVER_INSTANCE(instance_id);
449 CHECK_SERVER_REGISTRATION(instance_id);
451 /* Historically used for Legacy Advertising */
452 return OAL_STATUS_NOT_SUPPORT;
456 oal_status_t gatts_multi_adv_enable(int instance_id)
458 int ret = OAL_STATUS_SUCCESS;
459 API_TRACE("Start Multi advertising, srv_if: %d, instance_id: %d",
460 gatt_servers[instance_id - 1].server_id, instance_id);
462 CHECK_OAL_GATT_ENABLED();
463 CHECK_SERVER_INSTANCE(instance_id);
464 CHECK_SERVER_REGISTRATION(instance_id);
466 if (gatt_api->server->multi_adv_enable == NULL)
467 return OAL_STATUS_NOT_SUPPORT;
469 /* Platform Requirement: Advertising to be enabled even when no data is set: i.e Empty Advertisement
470 if (gatt_servers[instance_id - 1].state != GATT_INS_DATA_SET){
471 BT_ERR("Not allowed, state: %d, instance_id: %d",
472 gatt_servers[instance_id - 1].state, instance_id);
473 return OAL_STATUS_BUSY;
476 if (gatt_servers[instance_id - 1].state == GATT_INS_ENABLED) {
477 BT_ERR("Not allowed, state: %d, instance_id: %d",
478 gatt_servers[instance_id - 1].state, instance_id);
479 return OAL_STATUS_ALREADY_DONE;
482 if (gatt_servers[instance_id - 1].state == GATT_INS_ENABLING) {
483 BT_ERR("Not allowed, state: %d, instance_id: %d",
484 gatt_servers[instance_id - 1].state, instance_id);
485 return OAL_STATUS_BUSY;
488 gatt_servers[instance_id - 1].state = GATT_INS_ENABLING;
490 ret = gatt_api->server->multi_adv_enable(gatt_servers[instance_id - 1].server_id);
492 if (ret != BT_STATUS_SUCCESS) {
493 BT_ERR("GATT enable multi advertising failed for server Instance: %d With Status: %s",
494 instance_id, status2string(ret));
495 // gatt_servers[instance_id - 1].state = GATT_INS_DATA_SET;
496 return convert_to_oal_status(ret);
498 return OAL_STATUS_SUCCESS;
501 oal_status_t gatts_multi_adv_disable(int instance_id)
503 int ret = OAL_STATUS_SUCCESS;
504 API_TRACE("Stop Multi advertising, srv_if: %d, instance_id: %d",
505 gatt_servers[instance_id - 1].server_id, instance_id);
507 CHECK_OAL_GATT_ENABLED();
508 CHECK_SERVER_INSTANCE(instance_id);
509 CHECK_SERVER_REGISTRATION(instance_id);
511 if (gatt_api->server->multi_adv_disable == NULL)
512 return OAL_STATUS_NOT_SUPPORT;
514 if ((gatt_servers[instance_id - 1].state != GATT_INS_ENABLED)) {
515 BT_ERR("Not Allowed, state: %d, instance_id: %d",
516 gatt_servers[instance_id - 1].state, instance_id);
517 return OAL_STATUS_BUSY;
520 ret = gatt_api->server->multi_adv_disable(gatt_servers[instance_id - 1].server_id);
522 if (ret != BT_STATUS_SUCCESS) {
523 BT_ERR("GATT disable multi advertising failed for server Instance: %d With Status: %s",
524 instance_id, status2string(ret));
525 return convert_to_oal_status(ret);
527 return OAL_STATUS_SUCCESS;
530 oal_status_t gatts_multi_adv_update(int instance_id,
531 int min_intv, int max_intv,
532 int adv_type, int chnl_map,
533 int tx_power, int timeout_s)
535 int ret = OAL_STATUS_SUCCESS;
536 API_TRACE("Multi advertising Update");
538 CHECK_OAL_GATT_ENABLED();
539 CHECK_SERVER_INSTANCE(instance_id);
540 CHECK_SERVER_REGISTRATION(instance_id);
542 if (gatt_api->server->multi_adv_update == NULL)
543 return OAL_STATUS_NOT_SUPPORT;
545 ret = gatt_api->server->multi_adv_update(gatt_servers[instance_id - 1].server_id,
548 tx_power, timeout_s);
550 if (ret != BT_STATUS_SUCCESS) {
551 BT_ERR("GATT update multi advertising failed for server Instance: %d With Status: %s",
552 instance_id, status2string(ret));
553 return convert_to_oal_status(ret);
555 return OAL_STATUS_SUCCESS;
558 oal_status_t gatts_multi_adv_set_inst_data(int instance_id,
559 oal_ble_multi_adv_param_setup_t *adv_param_setup)
561 int ret = OAL_STATUS_SUCCESS;
562 btgatt_adv_param_setup_t adv_setup;
563 API_TRACE("Set Multi advertising data, srv_if: %d, instance_id: %d",
564 gatt_servers[instance_id - 1].server_id, instance_id);
566 CHECK_OAL_GATT_ENABLED();
567 CHECK_SERVER_INSTANCE(instance_id);
568 CHECK_SERVER_REGISTRATION(instance_id);
570 if (gatt_api->server->multi_adv_set_inst_data == NULL)
571 return OAL_STATUS_NOT_SUPPORT;
573 if ((gatt_servers[instance_id - 1].state >= GATT_INS_DATA_SETTING) && (gatt_servers[instance_id - 1].state != GATT_INS_DATA_SET)) {
574 BT_ERR("Not Allowed, state: %d, instance_id: %d", gatt_servers[instance_id - 1].state, instance_id);
575 return OAL_STATUS_BUSY;
578 gatt_servers[instance_id - 1].state = GATT_INS_DATA_SETTING;
581 adv_setup.set_scan_rsp = adv_param_setup->set_scan_rsp;
582 adv_setup.include_name = adv_param_setup->include_name;
583 adv_setup.include_txpower = adv_param_setup->include_txpower;
584 adv_setup.appearance = adv_param_setup->appearance;
585 adv_setup.manufacturer_data = adv_param_setup->manufacturer_data;
586 adv_setup.manufacturer_data_len = adv_param_setup->manufacturer_data_len;
587 adv_setup.service_data = adv_param_setup->service_data;
588 adv_setup.service_data_len = adv_param_setup->service_data_len;
589 adv_setup.service_uuid = adv_param_setup->service_uuid;
590 adv_setup.service_uuid_len = adv_param_setup->service_uuid_len;
591 /* Solicit UUID handler: Start */
592 adv_setup.solicit_uuid = adv_param_setup->solicit_uuid;
593 adv_setup.solicit_uuid_len = adv_param_setup->solicit_uuid_len;
594 /* Solicit UUID handler: End */
595 adv_setup.min_interval = adv_param_setup->min_interval;
596 adv_setup.max_interval = adv_param_setup->min_interval;
597 adv_setup.adv_type = adv_param_setup->adv_type;
598 adv_setup.chnl_map = adv_param_setup->chnl_map;
599 adv_setup.tx_power = adv_param_setup->tx_power;
600 adv_setup.timeout_s = adv_param_setup->timeout_s;
602 adv_setup.server_if = gatt_servers[instance_id - 1].server_id;
603 if (adv_setup.manufacturer_data_len > 0 && adv_setup.manufacturer_data != NULL) {
604 BT_INFO("Manufacture data.....\n");
605 PRINT_ADV_DATA(adv_setup.manufacturer_data_len, (unsigned char *)adv_setup.manufacturer_data, adv_setup.set_scan_rsp);
608 if (adv_setup.service_uuid_len > 0 && adv_setup.service_uuid != NULL) {
609 BT_INFO("Service uuid.....\n");
610 PRINT_ADV_DATA(adv_setup.service_uuid_len, (unsigned char*)adv_setup.service_uuid, FALSE);
614 ret = gatt_api->server->multi_adv_set_inst_data(adv_setup);
616 if (ret != BT_STATUS_SUCCESS) {
617 BT_ERR("GATT Set Multi advertising data failed: %s", status2string(ret));
618 gatt_servers[instance_id - 1].state = GATT_INS_DISABLED;
619 return convert_to_oal_status(ret);
621 return OAL_STATUS_SUCCESS;
624 /************************************GATT Server Functions*************************************/
626 static void cb_gatts_register_app(int status, int server_if, bt_uuid_t *uuid)
629 char str[2*BT_UUID_STRING_MAX];
630 uuid_to_stringname((service_uuid_t*)uuid, str);
632 event_gatts_register_t *event = g_malloc0(sizeof(event_gatts_register_t));
634 BT_INFO("BTGATT SERVER REGISTER APP CB, status:%d, server_if:%d", status, server_if);
635 BT_INFO("UUID: [%s]", str);
637 for (i = 0; i < NUM_SERVER_INST; i++) {
638 if (gatt_servers[i].server_id == -1) {
639 BT_INFO("Server Instance registered with stack [%d]", i+1);
640 gatt_servers[i].server_id = server_if;
641 event->server_inst = i+1;
642 memcpy(gatt_servers[i].uuid.uuid, uuid->uu, sizeof(bt_uuid_t));
643 memcpy(event->server_uuid.uuid, uuid->uu, sizeof(bt_uuid_t));
647 send_event(OAL_EVENT_BLE_SERVER_INSTANCE_INITIALISED, event, sizeof(event_gatts_register_t));
650 static void cb_gatts_listen(int status, int server_if)
652 gboolean prev_state[NUM_SERVER_INST];
654 event_ble_adv_status *event = g_malloc0(sizeof(event_ble_adv_status));
657 for (instance_id = 1 ; instance_id <= NUM_SERVER_INST ; instance_id++) {
658 if (gatt_servers[instance_id - 1].server_id == server_if) {
659 event->server_inst = instance_id;
662 BT_WARN("Server ID:%d recevied server Id:%d\n", gatt_servers[instance_id - 1].server_id, server_if);
665 if ((event->server_inst > 0) && (event->server_inst <= 10)) {
666 prev_state[event->server_inst - 1] = cur_adv_state[event->server_inst - 1];
667 new_state = (status == BT_STATUS_SUCCESS) ? !(prev_state[event->server_inst - 1]) : (prev_state[event->server_inst - 1]);
668 cur_adv_state[event->server_inst - 1] = new_state;
670 BT_ERR("Invalid Callback...");
675 BT_INFO("Adv State of server instance %d :%d", instance_id, new_state);
677 if (TRUE == new_state)
678 send_event(OAL_EVENT_BLE_ADVERTISING_STARTED, event, sizeof(event_ble_adv_status));
680 send_event(OAL_EVENT_BLE_ADVERTISING_STOPPED, event, sizeof(event_ble_adv_status));
683 static void cb_gatts_multi_adv_enable(int server_if, int status)
686 BT_INFO("BTGATT SERVER MULTI ADV ENABLE CB, status:%d, srv_if: %d", status, server_if);
687 event_ble_multiadv_status *event = g_malloc0(sizeof(event_ble_multiadv_status));
690 if (status != BT_STATUS_SUCCESS)
691 BT_ERR("MULTI ADV ENABLE failed, status:%d, srv_if: %d", status, server_if);
693 for (instance_id = 1 ; instance_id <= NUM_SERVER_INST ; instance_id++) {
694 if (gatt_servers[instance_id - 1].server_id == server_if) {
695 event->server_inst = instance_id;
696 gatt_servers[instance_id - 1].state = GATT_INS_ENABLED;
700 BT_ERR("Invalid Interface, srv_if: %d", server_if);
701 event->server_inst = -1;
703 event->status = convert_to_oal_status(status);
704 send_event(OAL_EVENT_BLE_MULTI_ADVERTISING_ENABLE, event, sizeof(event_ble_multiadv_status));
707 static void cb_gatts_multi_adv_disable(int server_if, int status)
709 BT_INFO("BTGATT SERVER MULTI ADV DISABLE CB, status:%d, srv_if: %d", status, server_if);
710 event_ble_multiadv_status *event = g_malloc0(sizeof(event_ble_multiadv_status));
713 if (status != BT_STATUS_SUCCESS)
714 BT_ERR("MULTI ADV DISABLE failed, status:%d, srv_if: %d", status, server_if);
716 for (instance_id = 1 ; instance_id <= NUM_SERVER_INST; instance_id++) {
717 if (gatt_servers[instance_id - 1].server_id == server_if) {
718 event->server_inst = instance_id;
719 gatt_servers[instance_id - 1].state = GATT_INS_DISABLED;
723 BT_ERR("Invalid Interface, srv_if: %d", server_if);
724 event->server_inst = -1;
726 event->status = convert_to_oal_status(status);
727 send_event(OAL_EVENT_BLE_MULTI_ADVERTISING_DISABLE, event, sizeof(event_ble_multiadv_status));
730 static void cb_gatts_multi_adv_update(int server_if, int status)
732 BT_INFO("BTGATT SERVER MULTI ADV UPDATE CB, status:%d, srv_if: %d", status, server_if);
733 event_ble_multiadv_status *event = g_malloc0(sizeof(event_ble_multiadv_status));
736 if (status != BT_STATUS_SUCCESS)
737 BT_ERR("MULTI ADV UPDATE failed, status:%d, srv_if: %d", status, server_if);
739 for (instance_id = 1 ; instance_id <= NUM_SERVER_INST ; instance_id++) {
740 if (gatt_servers[instance_id - 1].server_id == server_if) {
741 event->server_inst = instance_id;
745 BT_ERR("Invalid Interface, srv_if: %d", server_if);
746 event->server_inst = -1;
748 event->status = convert_to_oal_status(status);
749 send_event(OAL_EVENT_BLE_MULTI_ADVERTISING_UPDATE, event, sizeof(event_ble_multiadv_status));
752 static void cb_gatts_multi_adv_set_inst_data(int server_if, int status)
754 BT_INFO("BTGATT SERVER MULTI ADV SET INST DATA CB, status:%d, srv_if: %d", status, server_if);
755 event_ble_multiadv_status *event = g_malloc0(sizeof(event_ble_multiadv_status));
758 if (status != BT_STATUS_SUCCESS)
759 BT_ERR("MULTI ADV SET DATA failed, status:%d, srv_if: %d", status, server_if);
761 for (instance_id = 1 ; instance_id <= NUM_SERVER_INST ; instance_id++) {
762 if (gatt_servers[instance_id - 1].server_id == server_if) {
763 event->server_inst = instance_id;
764 gatt_servers[instance_id - 1].state = GATT_INS_DATA_SET;
768 BT_ERR("Invalid Interface, srv_if: %d", server_if);
769 event->server_inst = -1;
771 event->status = convert_to_oal_status(status);
772 send_event(OAL_EVENT_BLE_MULTI_ADVERTISING_SET_INST_DATA, event, sizeof(event_ble_multiadv_status));
775 oal_status_t gatts_get_att_mtu(int conn_id, int *mtu)
777 int ret = OAL_STATUS_SUCCESS;
778 API_TRACE("Get ATT MTU, conn_id: %d", conn_id);
779 CHECK_OAL_GATT_ENABLED();
780 OAL_CHECK_PARAMETER(mtu, return);
782 /* To prevent crash in case other libraries not support this api */
783 if (gatt_api->server->get_att_mtu == NULL) {
784 BT_WARN("get_att_mtu is NULL");
785 return OAL_STATUS_NOT_SUPPORT;
788 ret = gatt_api->server->get_att_mtu(conn_id, mtu);
789 if (ret != BT_STATUS_SUCCESS) {
790 BT_ERR("GATT MTU Size failed, status: %d", status2string(ret));
791 return convert_to_oal_status(ret);
794 BT_INFO("Current ATT MTU Size: %d", *mtu);
795 return OAL_STATUS_SUCCESS;
797 oal_status_t gatt_send_response_acquire(int conn_id, int trans_id,
798 int status, int fd, int mtu , void * fdlist)
800 int ret = OAL_STATUS_SUCCESS;
802 API_TRACE("Server Send Response : ConnId = %d, TransId = %d, %d", conn_id, trans_id, fd);
803 CHECK_OAL_GATT_ENABLED();
805 ret = gatt_api->server->send_response_acquire(conn_id, trans_id, status, fd, mtu, fdlist);
806 if (ret != BT_STATUS_SUCCESS) {
807 BT_ERR("GATT Server Send Response failed: %s", status2string(ret));
808 return convert_to_oal_status(ret);
810 return OAL_STATUS_SUCCESS;
813 oal_status_t gatts_add_service(int instance_id, oal_gatt_srvc_id_t *gatt_serv_id,
816 int ret = OAL_STATUS_SUCCESS;
817 btgatt_srvc_id_t btgatt_srvc_id;
818 char str[2*BT_UUID_STRING_MAX];
820 API_TRACE("Server Add Service : instance_id = %d, num_handles = %d", instance_id, num_handles);
821 CHECK_OAL_GATT_ENABLED();
823 CHECK_SERVER_INSTANCE(instance_id);
824 CHECK_SERVER_REGISTRATION(instance_id);
826 if (gatt_serv_id != NULL) {
827 uuid_to_stringname(&(gatt_serv_id->id.uuid), str);
828 API_TRACE("Service uuid: [%s]", str);
829 memcpy(btgatt_srvc_id.id.uuid.uu, gatt_serv_id->id.uuid.uuid, sizeof(gatt_serv_id->id.uuid));
830 btgatt_srvc_id.id.inst_id = gatt_serv_id->id.inst_id;
831 btgatt_srvc_id.is_primary = gatt_serv_id->is_prmry;
833 BT_INFO("GATT Server Service Id is NULL");
834 return OAL_STATUS_INVALID_PARAM;
837 ret = gatt_api->server->add_service(gatt_servers[instance_id - 1].server_id, &btgatt_srvc_id, num_handles);
839 if (ret != BT_STATUS_SUCCESS) {
840 BT_ERR("GATT Server add service failed: %s", status2string(ret));
841 return convert_to_oal_status(ret);
843 return OAL_STATUS_SUCCESS;
846 oal_status_t gatts_add_included_services(int instance_id, int serv_handle,
849 int ret = OAL_STATUS_SUCCESS;
850 API_TRACE("Server Add included Service : instance_id = %d, serv_handle = %d, incl_handle = %d",
851 instance_id, serv_handle, incl_handle);
852 CHECK_OAL_GATT_ENABLED();
854 CHECK_SERVER_INSTANCE(instance_id);
856 CHECK_SERVER_REGISTRATION(instance_id);
858 ret = gatt_api->server->add_included_service(gatt_servers[instance_id - 1].server_id, serv_handle, incl_handle);
859 if (ret != BT_STATUS_SUCCESS) {
860 BT_ERR("GATT Server Add included Service failed: %s", status2string(ret));
861 return convert_to_oal_status(ret);
863 return OAL_STATUS_SUCCESS;
866 oal_status_t gatts_add_characteristics(int instance_id, int serv_handle,
867 oal_uuid_t* charc_uuid, int propts, int permsn)
869 int ret = OAL_STATUS_SUCCESS;
870 char str[2*BT_UUID_STRING_MAX];
871 char prop[MAX_PROP_LEN], perm[MAX_PERM_LEN];
872 char_prop_to_string(propts, prop);
873 char_perm_to_string(permsn, perm);
874 API_TRACE("Server Add Characteristic : instance_id = %d, serv_handle = %d, Properties =%s, Permisison = %s",
875 instance_id, serv_handle, prop, perm);
876 CHECK_OAL_GATT_ENABLED();
878 CHECK_SERVER_INSTANCE(instance_id);
880 CHECK_SERVER_REGISTRATION(instance_id);
882 if (charc_uuid != NULL) {
883 uuid_to_stringname(charc_uuid, str);
884 API_TRACE("uuid: [%s]", str);
887 ret = gatt_api->server->add_characteristic(gatt_servers[instance_id - 1].server_id,
888 serv_handle, (bt_uuid_t*)charc_uuid, propts, permsn);
889 if (ret != BT_STATUS_SUCCESS) {
890 BT_ERR("GATT Server Add Characteristic failed: %s", status2string(ret));
891 return convert_to_oal_status(ret);
893 return OAL_STATUS_SUCCESS;
896 oal_status_t gatts_add_descriptor(int instance_id, int serv_handle,
897 oal_uuid_t* desc_uuid, int permsn)
899 int ret = OAL_STATUS_SUCCESS;
900 char str[2*BT_UUID_STRING_MAX];
901 char perm[MAX_PERM_LEN];
902 char_perm_to_string(permsn, perm);
903 API_TRACE("Server Add Descriptor : instance_id = %d, serv_handle = %d, Permisison = %s",
904 instance_id, serv_handle, perm);
905 CHECK_OAL_GATT_ENABLED();
907 CHECK_SERVER_INSTANCE(instance_id);
909 CHECK_SERVER_REGISTRATION(instance_id);
911 if (desc_uuid != NULL) {
912 uuid_to_stringname(desc_uuid, str);
913 API_TRACE("uuid: [%s]", str);
916 ret = gatt_api->server->add_descriptor(gatt_servers[instance_id - 1].server_id,
917 serv_handle, (bt_uuid_t*)desc_uuid, permsn);
919 if (ret != BT_STATUS_SUCCESS) {
920 BT_ERR("GATT Server Add Descriptor failed: %s", status2string(ret));
921 return convert_to_oal_status(ret);
923 return OAL_STATUS_SUCCESS;
926 oal_status_t gatts_start_service(int instance_id, int svc_handle, int transport)
928 int ret = OAL_STATUS_SUCCESS;
930 API_TRACE("Server Start Service : Ins_id = %d, srvHndl = %d, transport = %d",
931 instance_id, svc_handle, transport);
932 CHECK_OAL_GATT_ENABLED();
934 CHECK_SERVER_INSTANCE(instance_id);
936 CHECK_SERVER_REGISTRATION(instance_id);
938 ret = gatt_api->server->start_service(gatt_servers[instance_id - 1].server_id, svc_handle, transport);
940 if (ret != BT_STATUS_SUCCESS) {
941 BT_ERR("GATT Server Start Service failed: %s", status2string(ret));
942 return convert_to_oal_status(ret);
944 return OAL_STATUS_SUCCESS;
947 oal_status_t gatts_stop_service(int ins_id, int srv_hdl)
949 int ret = OAL_STATUS_SUCCESS;
951 API_TRACE("Server Stop Service : Ins_id = %d, srvHndl = %d, ", ins_id, srv_hdl);
952 CHECK_OAL_GATT_ENABLED();
954 CHECK_SERVER_INSTANCE(ins_id);
955 CHECK_SERVER_REGISTRATION(ins_id);
957 ret = gatt_api->server->stop_service(gatt_servers[ins_id - 1].server_id, srv_hdl);
958 if (ret != BT_STATUS_SUCCESS) {
959 BT_ERR("GATT Server Stop Service failed: %s", status2string(ret));
960 return convert_to_oal_status(ret);
962 return OAL_STATUS_SUCCESS;
965 oal_status_t gatts_delete_service(int ins_id, int srv_hdl)
967 int ret = OAL_STATUS_SUCCESS;
969 API_TRACE("Server Delete Service : Ins_id = %d, srvHndl = %d, ", ins_id, srv_hdl);
970 CHECK_OAL_GATT_ENABLED();
972 CHECK_SERVER_INSTANCE(ins_id);
974 CHECK_SERVER_REGISTRATION(ins_id);
976 ret = gatt_api->server->delete_service(gatt_servers[ins_id - 1].server_id, srv_hdl);
977 if (ret != BT_STATUS_SUCCESS) {
978 BT_ERR("GATT Server Delete Service failed: %s", status2string(ret));
979 return convert_to_oal_status(ret);
981 return OAL_STATUS_SUCCESS;
984 oal_status_t gatts_send_response(int conn_id, int trans_id, int resp_status, oal_gatt_response_t *response)
986 int ret = OAL_STATUS_SUCCESS;
988 API_TRACE("Server Send Response : ConnId = %d, TransId = %d, ", conn_id, trans_id);
989 CHECK_OAL_GATT_ENABLED();
991 if (response == NULL) {
992 BT_ERR("GATT Server attribute value is empty");
993 return OAL_STATUS_INVALID_PARAM;
996 ret = gatt_api->server->send_response(conn_id, trans_id, resp_status, (btgatt_response_t *)response);
997 if (ret != BT_STATUS_SUCCESS) {
998 BT_ERR("GATT Server Send Response failed: %s", status2string(ret));
999 return convert_to_oal_status(ret);
1001 return OAL_STATUS_SUCCESS;
1004 oal_status_t gatts_send_indication(int ins_id, int attr_hndl, int conn_id, int len, int confirm, char* value)
1006 int ret = OAL_STATUS_SUCCESS;
1008 API_TRACE("Server Send Indication : Ins_id = %d, srvHndl = %d, [%s]",
1009 ins_id, attr_hndl, confirm == TRUE ? "INDICATION" : "NOTIFICATION");
1010 CHECK_OAL_GATT_ENABLED();
1012 CHECK_SERVER_INSTANCE(ins_id);
1014 CHECK_SERVER_REGISTRATION(ins_id);
1016 if (value == NULL || len == 0) {
1017 BT_ERR("GATT Server attribute value is empty");
1018 return OAL_STATUS_INVALID_PARAM;
1021 ret = gatt_api->server->send_indication(gatt_servers[ins_id - 1].server_id,
1022 attr_hndl, conn_id, len, confirm, value);
1024 if (ret != BT_STATUS_SUCCESS) {
1025 BT_ERR("GATT Server Send Indication failed: %s", status2string(ret));
1026 return convert_to_oal_status(ret);
1028 return OAL_STATUS_SUCCESS;
1031 oal_status_t gatts_update_att_value(int ins_id, oal_gatt_value_t *value)
1033 int ret = OAL_STATUS_SUCCESS;
1035 CHECK_OAL_GATT_ENABLED();
1037 CHECK_SERVER_INSTANCE(ins_id);
1039 CHECK_SERVER_REGISTRATION(ins_id);
1041 if (value == NULL || value->len == 0) {
1042 BT_ERR("GATT Server attribute value is empty");
1043 return OAL_STATUS_INVALID_PARAM;
1046 API_TRACE("Server Update Value: Ins_id = [%d], att handle = [%d] data len [%d]",
1047 ins_id, value->handle, value->len);
1049 ret = gatt_api->server->update_att_value(gatt_servers[ins_id - 1].server_id,
1050 (int)value->handle, (int)value->len, (char*)value->value);
1052 if (ret != BT_STATUS_SUCCESS) {
1053 BT_ERR("GATT Server Update Attribute Value failed: [%s]", status2string(ret));
1054 return convert_to_oal_status(ret);
1056 return OAL_STATUS_SUCCESS;
1059 /* GATT Server Callbacks:Start */
1060 static void cb_gatts_service_added(int status, int server_if,
1061 btgatt_srvc_id_t *psrvc_id, int srvc_handle)
1065 BT_INFO("BTGATT SERVER SERVICE ADDED CB, status:%d, handle:%d", status, srvc_handle);
1066 event_gatts_srvc_prm_t* event = g_new0(event_gatts_srvc_prm_t, 1);
1068 CHECK_CORRECT_SERVER_ID(instance_id, server_if, event->gatt_srvc_stat.server_inst);
1070 BT_ERR("Invalid Interface, srv_if: %d", server_if);
1071 event->gatt_srvc_stat.server_inst = -1;
1073 event->gatt_srvc_stat.servic_hndl = srvc_handle;
1074 if (psrvc_id != NULL) {
1075 event->gatt_srvc_id.id.inst_id = psrvc_id->id.inst_id;
1076 //event->gatt_srvc_id.id.uuid = psrvc_id->id.uuid;
1077 memcpy(event->gatt_srvc_id.id.uuid.uuid, psrvc_id->id.uuid.uu, sizeof(psrvc_id->id.uuid));
1078 event->gatt_srvc_id.is_prmry = psrvc_id->is_primary;
1081 event->gatt_srvc_stat.status = convert_to_oal_status(status);
1083 send_event(OAL_EVENT_GATTS_SERVICE_ADDED, event, sizeof(event_gatts_srvc_prm_t));
1086 static void cb_gatts_included_service_added(int status, int server_if,
1088 int incl_srvc_handle)
1091 BT_INFO("BTGATT SERVER INCLUDED SERVICE ADDED CB, status:%d, srvc handle:%d, incl handle:%d",
1092 status, srvc_handle, incl_srvc_handle);
1094 event_gatts_incld_srvc_t* event = g_new0(event_gatts_incld_srvc_t, 1);
1096 CHECK_CORRECT_SERVER_ID(ins_id, server_if, event->gatt_srvc_stat.server_inst);
1098 BT_ERR("Invalid Interface, srv_if: %d", server_if);
1099 event->gatt_srvc_stat.server_inst = -1;
1101 event->gatt_srvc_stat.servic_hndl = srvc_handle;
1102 event->incl_srvc_hndl = incl_srvc_handle;
1103 event->gatt_srvc_stat.status = convert_to_oal_status(status);
1104 send_event(OAL_EVENT_GATTS_INCLUDED_SERVICE_ADDED, event, sizeof(event_gatts_incld_srvc_t));
1107 static void cb_gatts_characteristic_added(int status, int server_if, bt_uuid_t *char_id,
1108 int srvc_handle, int char_handle)
1112 BT_INFO("BTGATT SERVER CHARACTERISTIC ADDED CB, status:%d, srvc handle:%d, char handle:%d",
1113 status, srvc_handle, char_handle);
1115 event_gatts_srvc_charctr_t* event = g_new0(event_gatts_srvc_charctr_t, 1);
1117 CHECK_CORRECT_SERVER_ID(Ins_id, server_if, event->gatt_srvc_stat.server_inst);
1119 BT_ERR("Invalid Interface, srv_if: %d", server_if);
1120 event->gatt_srvc_stat.server_inst = -1;
1122 event->gatt_srvc_stat.servic_hndl = srvc_handle;
1123 event->charctr_hndl = char_handle;
1124 event->gatt_srvc_stat.status = convert_to_oal_status(status);
1125 memcpy(event->charctr_uuid.uuid, char_id->uu, sizeof(bt_uuid_t));
1126 send_event(OAL_EVENT_GATTS_CHARACTERISTIC_ADDED, event, sizeof(event_gatts_srvc_charctr_t));
1129 static void cb_gatts_descriptor_added(int status, int server_if,
1130 bt_uuid_t *descr_id, int srvc_handle,
1134 BT_INFO("BTGATT SERVER DESCRIPTOR ADDED CB, status:%d, srvc handle:%d, desc handle:%d",
1135 status, srvc_handle, descr_handle);
1137 event_gatts_srvc_descr_t* event = g_new0(event_gatts_srvc_descr_t, 1);
1139 CHECK_CORRECT_SERVER_ID(Ins_id, server_if, event->gatt_srvc_stat.server_inst);
1141 BT_ERR("Invalid Interface, srv_if: %d", server_if);
1142 event->gatt_srvc_stat.server_inst = -1;
1144 event->gatt_srvc_stat.servic_hndl = srvc_handle;
1145 event->descrptr_hndl = descr_handle;
1146 event->gatt_srvc_stat.status = convert_to_oal_status(status);
1147 memcpy(event->descrptr_uuid.uuid, descr_id->uu, sizeof(bt_uuid_t));
1148 send_event(OAL_EVENT_GATTS_DESCRIPTOR_ADDED, event, sizeof(event_gatts_srvc_descr_t));
1151 static void cb_gatts_service_started(int status, int server_if, int srvc_handle)
1154 BT_INFO("BTGATT SERVER SERVICE STARTED CB, status:%d, srvc_handle:%d", status, srvc_handle);
1156 event_gatts_srvc_t* event = g_new0(event_gatts_srvc_t, 1);
1158 CHECK_CORRECT_SERVER_ID(Ins_id, server_if, event->server_inst);
1160 BT_ERR("Invalid Interface, srv_if: %d", server_if);
1161 event->server_inst = -1;
1163 event->servic_hndl = srvc_handle;
1164 event->status = convert_to_oal_status(status);
1165 send_event(OAL_EVENT_GATTS_SERVICE_STARTED, event, sizeof(event_gatts_srvc_t));
1168 static void cb_gatts_service_stopped(int status, int server_if, int srvc_handle)
1171 BT_INFO("BTGATT SERVER SERVICE STOPPED CB, status:%d, srvc_handle:%d", status, srvc_handle);
1173 event_gatts_srvc_t* event = g_new0(event_gatts_srvc_t, 1);
1175 CHECK_CORRECT_SERVER_ID(ins_id, server_if, event->server_inst);
1177 BT_ERR("Invalid Interface, srv_if: %d", server_if);
1178 event->server_inst = -1;
1180 event->servic_hndl = srvc_handle;
1181 event->status = convert_to_oal_status(status);
1182 send_event(OAL_EVENT_GATTS_SERVICE_STOPED, event, sizeof(event_gatts_srvc_t));
1185 static void cb_gatts_service_deleted(int status, int server_if, int srvc_handle)
1188 BT_INFO("BTGATT SERVER SERVICE DELETED CB, status:%d, srvc_handle:%d", status, srvc_handle);
1190 event_gatts_srvc_t* event = g_new0(event_gatts_srvc_t, 1);
1192 CHECK_CORRECT_SERVER_ID(ins_id, server_if, event->server_inst);
1194 BT_ERR("Invalid Interface, srv_if: %d", server_if);
1195 event->server_inst = -1;
1197 event->servic_hndl = srvc_handle;
1198 event->status = convert_to_oal_status(status);
1199 send_event(OAL_EVENT_GATTS_SERVICE_DELETED, event, sizeof(event_gatts_srvc_t));
1202 static void cb_gatts_connection(int conn_id, int server_if, int connected, bt_bdaddr_t *bda)
1205 oal_event_t event_type;
1207 BT_INFO("BTGATT SERVER CONNECTION connnected:%d, conn_id:%d server_if:%d", connected, conn_id, server_if);
1208 event_gatts_conn_t *event = g_new0(event_gatts_conn_t, 1);
1210 for (ins_id = 1 ; ins_id <= NUM_SERVER_INST ; ins_id++) {
1211 if ((gatt_servers[ins_id - 1].server_id == server_if) &&
1212 (gatt_servers[ins_id - 1].state == GATT_INS_ENABLED)) {
1213 event->server_inst = ins_id;
1216 BT_INFO("Server ID:%d recevied server Id:%d\n", gatt_servers[ins_id - 1].server_id, server_if);
1219 if (ins_id == NUM_SERVER_INST+1) {
1220 BT_WARN("Incorrect Server Interface received: %d\n", server_if);
1224 memcpy(event->address.addr, bda->address, BT_ADDRESS_BYTES_NUM);
1225 event->conn_id = conn_id;
1226 event_type = ((connected == TRUE) ? OAL_EVENT_GATTS_CONNECTION_COMPLETED : OAL_EVENT_GATTS_DISCONNECTION_COMPLETED);
1228 send_event(event_type, event, sizeof(event_gatts_conn_t));
1231 static void cb_gatts_request_read(int conn_id, int trans_id, bt_bdaddr_t *bda,
1232 int attr_handle, int offset, bool is_long)
1234 BT_INFO("BTGATT SERVER REQUEST READ CB: conn_id:%d", conn_id);
1236 event_gatts_srvc_read_attr_t* event = g_new0(event_gatts_srvc_read_attr_t, 1);
1238 memcpy(event->address.addr, bda->address, BT_ADDRESS_BYTES_NUM);
1240 event->attr_trans.attr_handle = attr_handle;
1241 event->attr_trans.conn_id = conn_id;
1242 event->attr_trans.trans_id = trans_id;
1243 event->attr_trans.offset = offset;
1244 event->is_long = is_long;
1246 send_event(OAL_EVENT_GATTS_REQUEST_READ, event, sizeof(event_gatts_srvc_read_attr_t));
1249 static void cb_gatts_request_write(int conn_id, int trans_id,
1250 bt_bdaddr_t *bda, int attr_handle,
1251 int offset, int length,
1252 bool need_rsp, bool is_prep, uint8_t* value)
1254 BT_INFO("BTGATT SERVER REQUEST WRITE conn_id:%d", conn_id);
1256 event_gatts_srvc_write_attr_t* event = g_new0(event_gatts_srvc_write_attr_t, 1);
1258 memcpy(event->address.addr, bda->address, BT_ADDRESS_BYTES_NUM);
1260 event->attr_trans.attr_handle = attr_handle;
1261 event->attr_trans.conn_id = conn_id;
1262 event->attr_trans.trans_id = trans_id;
1263 event->attr_trans.offset = offset;
1264 event->need_rsp = need_rsp;
1265 event->is_prep = is_prep;
1267 if (length > 0 && value != NULL) {
1268 if (length > OAL_GATT_MAX_ATTR_LEN)
1269 length = OAL_GATT_MAX_ATTR_LEN;
1270 memcpy(event->value, value, length);
1271 event->length = length;
1273 send_event(OAL_EVENT_GATTS_REQUEST_WRITE, event, sizeof(event_gatts_srvc_write_attr_t));
1276 static void cb_gatts_acquire_write(int mtu, int conn_id, int trans_id, int attr_handle , bt_bdaddr_t *bda)
1279 BT_INFO("BTGATT SERVER REQUEST ACQUIRE WRITE conn_id:%d", conn_id);
1281 event_gatts_srvc_acquire_attr_t* event = g_new0(event_gatts_srvc_acquire_attr_t, 1);
1283 event->attr_trans.attr_handle = attr_handle;
1284 event->attr_trans.conn_id = conn_id;
1285 event->attr_trans.trans_id = trans_id;
1287 memcpy(event->address.addr, bda->address, BT_ADDRESS_BYTES_NUM);
1289 send_event(OAL_EVENT_GATTS_REQUEST_ACQUIRE_WRITE, event, sizeof(event_gatts_srvc_acquire_attr_t));
1292 static void cb_gatts_acquire_notify(int mtu, int conn_id, int trans_id, int attr_handle)
1294 BT_INFO("BTGATT SERVER REQUEST ACQUIRE NOTIFY conn_id:%d", conn_id);
1296 event_gatts_srvc_acquire_attr_t* event = g_new0(event_gatts_srvc_acquire_attr_t, 1);
1298 event->attr_trans.attr_handle = attr_handle;
1299 event->attr_trans.conn_id = conn_id;
1300 event->attr_trans.trans_id = trans_id;
1303 send_event(OAL_EVENT_GATTS_REQUEST_ACQUIRE_NOTIFY, event, sizeof(event_gatts_srvc_acquire_attr_t));
1307 static void cb_gatts_response_confirmation(int status, int handle)
1309 BT_INFO("BTGATT SERVER RESPONSE CONFIRMATION CB, status:%d, handle:%d", status, handle);
1311 event_gatts_respons_t* event = g_new0(event_gatts_respons_t, 1);
1313 event->hndl = handle;
1314 event->status = convert_to_oal_status(status);
1316 send_event(OAL_EVENT_GATTS_RESPONSE_CONFIRMED, event, sizeof(event_gatts_respons_t));
1319 static void cb_indication_confirmation(int conn_id, int trans_id, int attr_handle, bt_bdaddr_t *bda)
1321 BT_INFO("BTGATT SERVER Indication Confirmation CB, conn_id:%d, trans_id:%d attr_handle:%d",
1322 conn_id, trans_id, attr_handle);
1324 event_gatts_ind_cnfrm_t* event = g_new0(event_gatts_ind_cnfrm_t, 1);
1326 memcpy(event->address.addr, bda->address, BT_ADDRESS_BYTES_NUM);
1328 event->attr_handle = attr_handle;
1329 event->conn_id = conn_id;
1330 event->trans_id = trans_id;
1331 send_event(OAL_EVENT_GATTS_IND_CONFIRM, event, sizeof(event_gatts_ind_cnfrm_t));
1334 static void cb_gatts_mtu_changed(int conn_id, int mtu)
1336 BT_INFO("BTGATT SERVER MTU CHANGED CB, conn_id: %d, mtu_size: %d", conn_id, mtu);
1337 event_gatts_mtu_changed_t *event = g_new0(event_gatts_mtu_changed_t, 1);
1338 event->conn_id = conn_id;
1339 event->mtu_size = mtu;
1340 send_event(OAL_EVENT_GATTS_MTU_CHANGED, event, sizeof(event_gatts_mtu_changed_t));
1344 static void cb_notifcation_changed(int conn_id, int trans_id, int attr_handle, bool notify, bt_bdaddr_t *bda)
1346 BT_INFO("BTGATT SERVER Notication CB, conn_id:%d, trans_id:%d attr_handle:%d Notify:%d",
1347 conn_id, trans_id, attr_handle, notify);
1349 event_gatts_notif_t* event = g_new0(event_gatts_notif_t, 1);
1351 memcpy(event->address.addr, bda->address, BT_ADDRESS_BYTES_NUM);
1353 event->attr_handle = attr_handle;
1354 event->conn_id = conn_id;
1355 event->trans_id = trans_id;
1356 event->notify = notify;
1357 send_event(OAL_EVENT_GATTS_NOTIFICATION, event, sizeof(event_gatts_notif_t));
1362 /* GATT Server Callbacks: End */
1363 /************************************ GATT Client ***********************************/
1364 /* Client Callbacks */
1365 static void cb_gattc_register_app(int status, int clientIf, bt_uuid_t *app_uuid)
1367 char uuid_str[BT_UUID_STRING_MAX];
1368 event_gattc_register_t *event;
1372 /* Check if GATT client registered for Default GATT client UUID */
1373 uuid_to_string((service_uuid_t *)app_uuid, uuid_str);
1374 BT_INFO("UUID:%s", uuid_str);
1376 BT_INFO("BTGATT CLIENT REGISTER APP CB, status:%d, clientIf:%d", status, clientIf);
1377 event = g_new0(event_gattc_register_t, 1);
1378 event->client_if = clientIf;
1379 event->status = (status == 0 ? OAL_STATUS_SUCCESS : OAL_STATUS_INTERNAL_ERROR);
1380 memcpy(event->client_uuid.uuid, app_uuid->uu, sizeof(oal_uuid_t));
1381 send_event(OAL_EVENT_GATTC_REGISTRATION, event, sizeof(event_gattc_register_t));
1384 static void cb_gattc_scan_result(bt_bdaddr_t* bdaddress, int rssi, uint8_t *adv_data)
1386 event_ble_scan_result_info *event;
1388 event = g_new0(event_ble_scan_result_info, 1);
1390 memcpy(event->address.addr, bdaddress->address, BT_ADDRESS_BYTES_NUM);
1391 memcpy(event->adv_data, adv_data, BLE_ADV_DATA_LENGTH);
1392 send_event_bda_trace(OAL_EVENT_BLE_REMOTE_DEVICE_FOUND, event,
1393 sizeof(event_ble_scan_result_info), (bt_address_t *)bdaddress);
1396 static void cb_gattc_connection(int conn_id, int status, int client_if, bt_bdaddr_t* bda)
1398 event_gattc_conn_t *event;
1399 BT_INFO("BTGATT CLIENT CONNECTED CB, status:[%d] client_if[%d] id[%d]",
1400 status, client_if, conn_id);
1402 event = g_new0(event_gattc_conn_t, 1);
1403 memcpy(event->address.addr, bda->address, BT_ADDRESS_BYTES_NUM);
1404 event->client_if = client_if;
1406 if (BT_STATUS_SUCCESS != status) {
1407 event->status = OAL_STATUS_INTERNAL_ERROR;
1408 BT_ERR("gattc connection Error: %d", status);
1410 event->conn_id = conn_id;
1411 event->status = OAL_STATUS_SUCCESS;
1414 send_event_bda_trace(OAL_EVENT_GATTC_CONNECTION_COMPLETED, event,
1415 sizeof(*event), (bt_address_t *)bda);
1419 static void cb_gattc_disconnect(int conn_id, int status, int client_if, bt_bdaddr_t* bda)
1421 event_gattc_conn_t *event;
1422 BT_INFO("BTGATT Client Disconnect Complete cb, status:[%d], client_if[%d] id[%d]",
1423 status, client_if, conn_id);
1424 event = g_new0(event_gattc_conn_t, 1);
1425 event->status = convert_to_oal_status(status);
1426 event->client_if = client_if;
1427 event->conn_id = conn_id;
1428 memcpy(event->address.addr, bda->address, BT_ADDRESS_BYTES_NUM);
1429 send_event_bda_trace(OAL_EVENT_GATTC_DISCONNECTION_COMPLETED, event,
1430 sizeof(*event), (bt_address_t *)bda);
1433 static void cb_gattc_search_result(int conn_id, btgatt_srvc_id_t *srvc_id)
1435 char uuid_str[2*BT_UUID_STRING_MAX];
1437 BT_INFO("BTGATT Client Service Search Result cb, conn_id:%d", conn_id);
1439 uuid_to_stringname((oal_uuid_t *)&(srvc_id->id.uuid), uuid_str);
1440 BT_INFO("Service=> UUID: [%s], Inst_id: [%u], Type: [%s]",
1441 uuid_str, srvc_id->id.inst_id, srvc_id->is_primary ? "Primary" : "Secondary");
1443 event_gattc_service_result_t *event = g_new0(event_gattc_service_result_t, 1);
1444 event->conn_status.status = OAL_STATUS_SUCCESS;
1445 event->conn_status.conn_id = conn_id;
1446 memcpy(&(event->srvc_id), srvc_id, sizeof(oal_gatt_srvc_id_t));
1448 send_event(OAL_EVENT_GATTC_SERVICE_SEARCH_RESULT, event, sizeof(*event));
1451 static void cb_gattc_search_complete(int conn_id, int status)
1453 BT_INFO("BTGATT Client Service Search Complete cb, status:%d, conn_id:%d",
1456 event_gattc_conn_status_t *event = g_new0(event_gattc_conn_status_t, 1);
1457 event->conn_id = conn_id;
1458 event->status = convert_to_oal_status(status);
1460 send_event(OAL_EVENT_GATTC_SERVICE_SEARCH_DONE, event, sizeof(*event));
1464 static void cb_gattc_get_characteristics(int conn_id, int status, btgatt_srvc_id_t *srvc_id,
1465 btgatt_gatt_id_t *char_id, int char_prop)
1467 char uuid_str1[2*BT_UUID_STRING_MAX];
1468 char uuid_str2[2*BT_UUID_STRING_MAX];
1470 BT_INFO("BTGATT Client Get Characteristic Callback, conn_id:%d, status:%d", conn_id, status);
1471 uuid_to_stringname((oal_uuid_t *)&(srvc_id->id.uuid), uuid_str1);
1472 BT_INFO("Service=> UUID: [%s], Inst_id: [%u], Type: [%s]",
1473 uuid_str1, srvc_id->id.inst_id, srvc_id->is_primary ? "Primary" : "Secondary");
1475 event_gattc_characteristic_result_t *event = g_new0(event_gattc_characteristic_result_t, 1);
1476 event->conn_status.conn_id = conn_id;
1477 event->conn_status.status = convert_to_oal_status(status);
1478 memcpy(&(event->srvc_id), srvc_id, sizeof(oal_gatt_srvc_id_t));
1481 uuid_to_stringname((oal_uuid_t *)&(char_id->uuid), uuid_str2);
1482 BT_INFO("Charac=> UUID: [%s], Inst_id: [%u], Prop: [%s]",
1483 uuid_str2, char_id->inst_id, char_prop_to_string(char_prop, str));
1484 event->char_prop = char_prop;
1485 memcpy(&(event->char_id), char_id, sizeof(oal_gatt_id_t));
1487 send_event(OAL_EVENT_GATTC_CHARAC_SERACH_RESULT, event, sizeof(*event));
1492 static void cb_gattc_get_descriptor(int conn_id, int status, btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id, btgatt_gatt_id_t *descr_id)
1494 char uuid_str1[2*BT_UUID_STRING_MAX];
1495 char uuid_str2[2*BT_UUID_STRING_MAX];
1496 char uuid_str3[2*BT_UUID_STRING_MAX];
1497 BT_INFO("BTGATT Client Get Descriptor Callback, conn_id:%d, status:%d", conn_id, status);
1498 uuid_to_stringname((oal_uuid_t *)&(srvc_id->id.uuid), uuid_str1);
1499 uuid_to_stringname((oal_uuid_t *)&(char_id->uuid), uuid_str2);
1500 BT_INFO("Service=> UUID: [%s], Inst_id: [%u], Type: [%s]",
1501 uuid_str1, srvc_id->id.inst_id, srvc_id->is_primary ? "Primary" : "Secondary");
1502 BT_INFO("Charac=> UUID: [%s], Inst_id: [%u]", uuid_str2, char_id->inst_id);
1504 event_gattc_descriptor_result_t *event = g_new0(event_gattc_descriptor_result_t, 1);
1505 event->conn_status.conn_id = conn_id;
1506 event->conn_status.status = convert_to_oal_status(status);
1507 memcpy(&(event->srvc_id), srvc_id, sizeof(oal_gatt_srvc_id_t));
1508 memcpy(&(event->char_id), char_id, sizeof(oal_gatt_id_t));
1511 uuid_to_stringname((oal_uuid_t *)&(descr_id->uuid), uuid_str3);
1512 BT_INFO("Desc=> UUID: [%s], Inst_id: [%u]", uuid_str3, descr_id->inst_id);
1513 memcpy(&(event->descr_id), descr_id, sizeof(oal_gatt_id_t));
1515 send_event(OAL_EVENT_GATTC_DESC_SERACH_RESULT, event, sizeof(*event));
1518 static void cb_gattc_register_for_notification(int client_if, int registered, int status, btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id)
1520 char uuid_str1[2*BT_UUID_STRING_MAX];
1521 char uuid_str2[2*BT_UUID_STRING_MAX];
1522 BT_INFO("BTGATT Client Register For Notification Callback, client_if:%d, status:%d, registered: %s",
1523 client_if, status, registered == 1 ? "REGISTERED" : "DEREGISTERED");
1524 uuid_to_stringname((oal_uuid_t *)&(srvc_id->id.uuid), uuid_str1);
1525 uuid_to_stringname((oal_uuid_t *)&(char_id->uuid), uuid_str2);
1526 BT_INFO("Service=> UUID: [%s], Inst_id: [%u], Type: [%s]", uuid_str1, srvc_id->id.inst_id, srvc_id->is_primary ? "Primary" : "Secondary");
1527 BT_INFO("Charac=> UUID: [%s], Inst_id: [%u]", uuid_str2, char_id->inst_id);
1529 event_gattc_regdereg_notify_t *event = g_new0(event_gattc_regdereg_notify_t, 1);
1530 oal_event_t event_type = (registered == 1 ? OAL_EVENT_GATTC_NOTIFICATION_REGISTERED : OAL_EVENT_GATTC_NOTIFICATION_DEREGISTERED);
1531 event->client_if = client_if;
1532 event->status = convert_to_oal_status(status);
1533 memcpy(&(event->srvc_id), srvc_id, sizeof(oal_gatt_srvc_id_t));
1534 memcpy(&(event->char_id), char_id, sizeof(oal_gatt_id_t));
1536 send_event(event_type, event, sizeof(*event));
1539 static void cb_gattc_notify(int conn_id, btgatt_notify_params_t *p_data)
1542 char uuid_str1[2*BT_UUID_STRING_MAX];
1543 char uuid_str2[2*BT_UUID_STRING_MAX];
1545 BT_INFO("BTGATT Client Notify Callback, conn_id:%d", conn_id);
1546 BT_INFO("Server Address:[%s], is_notify:[%d], len:[%d]",
1547 bdt_bd2str((bt_address_t *)&(p_data->bda), &bdstr), p_data->is_notify, p_data->len);
1549 uuid_to_stringname((oal_uuid_t *)&(p_data->srvc_id.id.uuid), uuid_str1);
1550 uuid_to_stringname((oal_uuid_t *)&(p_data->char_id.uuid), uuid_str2);
1552 BT_INFO("Service=> UUID: [%s], Inst_id: [%u], Type: [%s]",
1553 uuid_str1, p_data->srvc_id.id.inst_id, p_data->srvc_id.is_primary ? "Primary" : "Secondary");
1554 BT_INFO("Charac=> UUID: [%s], Inst_id: [%u]", uuid_str2, p_data->char_id.inst_id);
1556 if (p_data->len > 0) {
1558 data = g_malloc(3*p_data->len+1);
1560 BT_ERR("memory allocation failed");
1564 convert_hex_2_str((unsigned char *)p_data->value, p_data->len, data);
1565 BT_INFO("Notified Data: [%s]", data);
1567 event_gattc_notify_data *event = g_new0(event_gattc_notify_data, 1);
1568 memcpy(event->address.addr, p_data->bda.address, BT_ADDRESS_BYTES_NUM);
1569 event->is_notify = p_data->is_notify;
1570 event->data_len = p_data->len;
1571 memcpy(event->data, p_data->value, event->data_len);
1572 memcpy(&(event->char_id), &(p_data->char_id), sizeof(oal_gatt_id_t));
1573 memcpy(&(event->srvc_id), &(p_data->srvc_id), sizeof(oal_gatt_srvc_id_t));
1575 send_event_bda_trace(OAL_EVENT_GATTC_NOTIFY_DATA, event, sizeof(*event), (bt_address_t *)&p_data->bda);
1581 static void cb_gattc_read_characteristic(int conn_id, int status, btgatt_read_params_t *p_data)
1583 char uuid_str1[2*BT_UUID_STRING_MAX];
1584 char uuid_str2[2*BT_UUID_STRING_MAX];
1585 BT_INFO("BTGATT Client Read Charcateristic Callback, conn_id:%d, read_status:%d", conn_id, status);
1587 event_gattc_read_data *event = g_new0(event_gattc_read_data, 1);
1588 event->uuid_status.conn_status.conn_id = conn_id;
1589 event->uuid_status.conn_status.status = convert_to_oal_status(status);
1590 event->value_type = p_data->value_type;
1591 memcpy(&(event->uuid_status.srvc_id), &(p_data->srvc_id), sizeof(oal_gatt_srvc_id_t));
1592 memcpy(&(event->uuid_status.char_id), &(p_data->char_id), sizeof(oal_gatt_id_t));
1594 uuid_to_stringname((oal_uuid_t *)&(p_data->srvc_id.id.uuid), uuid_str1);
1595 uuid_to_stringname((oal_uuid_t *)&(p_data->char_id.uuid), uuid_str2);
1596 BT_INFO("Service=> UUID: [%s], Inst_id: [%u], Type: [%s]", uuid_str1,
1597 p_data->srvc_id.id.inst_id, p_data->srvc_id.is_primary ? "Primary" : "Secondary");
1598 BT_INFO("Charac=> UUID: [%s], Inst_id: [%u]", uuid_str2, p_data->char_id.inst_id);
1599 BT_INFO("Len: %u, value_type: %u", p_data->value.len, p_data->value_type);
1600 if (p_data->value.len > 0 && event->value_type == GATTC_READ_VALUE_TYPE_VALUE) {
1602 data = g_malloc(3*p_data->value.len+1);
1604 BT_ERR("memory allocation failed");
1608 convert_hex_2_str((unsigned char *)p_data->value.value, p_data->value.len, data);
1609 BT_INFO("Read Data: [%s]", data);
1610 event->data_len = p_data->value.len;
1611 memcpy(&(event->data), &(p_data->value.value), event->data_len);
1615 send_event(OAL_EVENT_GATTC_READ_CHARAC, event, sizeof(*event));
1618 static void cb_gattc_write_characteristic(int conn_id, int status, btgatt_write_params_t *p_data)
1620 char uuid_str1[2*BT_UUID_STRING_MAX];
1621 char uuid_str2[2*BT_UUID_STRING_MAX];
1622 BT_INFO("BTGATT Client Write Charcateristic Callback, conn_id:%d, write_status:%d", conn_id, status);
1624 event_gattc_write_data *event = g_new0(event_gattc_write_data, 1);
1625 event->conn_status.conn_id = conn_id;
1626 event->conn_status.status = convert_to_oal_status(status);
1627 memcpy(&(event->srvc_id), &(p_data->srvc_id), sizeof(oal_gatt_srvc_id_t));
1628 memcpy(&(event->char_id), &(p_data->char_id), sizeof(oal_gatt_id_t));
1630 uuid_to_stringname((oal_uuid_t *)&(p_data->srvc_id.id.uuid), uuid_str1);
1631 uuid_to_stringname((oal_uuid_t *)&(p_data->char_id.uuid), uuid_str2);
1632 BT_INFO("Service=> UUID: [%s], Inst_id: [%u], Type: [%s]", uuid_str1,
1633 p_data->srvc_id.id.inst_id, p_data->srvc_id.is_primary ? "Primary" : "Secondary");
1634 BT_INFO("Charac=> UUID: [%s], Inst_id: [%u]", uuid_str2, p_data->char_id.inst_id);
1636 send_event(OAL_EVENT_GATTC_WRITE_CHARAC, event, sizeof(*event));
1639 static void cb_gattc_write_descriptor(int conn_id, int status, btgatt_write_params_t *p_data)
1641 char uuid_str1[2*BT_UUID_STRING_MAX];
1642 char uuid_str2[2*BT_UUID_STRING_MAX];
1643 char uuid_str3[2*BT_UUID_STRING_MAX];
1644 BT_INFO("BTGATT Client Write Descriptor Callback, conn_id:%d, write_status:%d", conn_id, status);
1646 event_gattc_write_data *event = g_new0(event_gattc_write_data, 1);
1647 event->conn_status.conn_id = conn_id;
1648 event->conn_status.status = convert_to_oal_status(status);
1649 memcpy(&(event->srvc_id), &(p_data->srvc_id), sizeof(oal_gatt_srvc_id_t));
1650 memcpy(&(event->char_id), &(p_data->char_id), sizeof(oal_gatt_id_t));
1651 memcpy(&(event->descr_id), &(p_data->descr_id), sizeof(oal_gatt_id_t));
1653 uuid_to_stringname((oal_uuid_t *)&(p_data->srvc_id.id.uuid), uuid_str1);
1654 uuid_to_stringname((oal_uuid_t *)&(p_data->char_id.uuid), uuid_str2);
1655 uuid_to_stringname((oal_uuid_t *)&(p_data->descr_id.uuid), uuid_str3);
1656 BT_INFO("Service=> UUID: [%s], Inst_id: [%u], Type: [%s]", uuid_str1,
1657 p_data->srvc_id.id.inst_id, p_data->srvc_id.is_primary ? "Primary" : "Secondary");
1658 BT_INFO("Charac=> UUID: [%s], Inst_id: [%u]", uuid_str2, p_data->char_id.inst_id);
1659 BT_INFO("Desc=> UUID: [%s], Inst_id: [%u]", uuid_str3, p_data->descr_id.inst_id);
1661 send_event(OAL_EVENT_GATTC_WRITE_DESCR, event, sizeof(*event));
1666 static void cb_gattc_read_descriptor(int conn_id, int status, btgatt_read_params_t *p_data)
1668 char uuid_str1[2*BT_UUID_STRING_MAX];
1669 char uuid_str2[2*BT_UUID_STRING_MAX];
1670 char uuid_str3[2*BT_UUID_STRING_MAX];
1671 BT_INFO("BTGATT Client Read Descriptor Callback, conn_id:%d, read_status:%d", conn_id, status);
1673 event_gattc_read_data *event = g_new0(event_gattc_read_data, 1);
1674 event->uuid_status.conn_status.conn_id = conn_id;
1675 event->uuid_status.conn_status.status = convert_to_oal_status(status);
1676 event->value_type = p_data->value_type;
1677 memcpy(&(event->uuid_status.srvc_id), &(p_data->srvc_id), sizeof(oal_gatt_srvc_id_t));
1678 memcpy(&(event->uuid_status.char_id), &(p_data->char_id), sizeof(oal_gatt_id_t));
1679 memcpy(&(event->uuid_status.descr_id), &(p_data->descr_id), sizeof(oal_gatt_id_t));
1682 uuid_to_stringname((oal_uuid_t *)&(p_data->srvc_id.id.uuid), uuid_str1);
1683 uuid_to_stringname((oal_uuid_t *)&(p_data->char_id.uuid), uuid_str2);
1684 uuid_to_stringname((oal_uuid_t *)&(p_data->descr_id.uuid), uuid_str3);
1685 BT_INFO("Service=> UUID: [%s], Inst_id: [%u], Type: [%s]", uuid_str1,
1686 p_data->srvc_id.id.inst_id, p_data->srvc_id.is_primary ? "Primary" : "Secondary");
1687 BT_INFO("Charac=> UUID: [%s], Inst_id: [%u]", uuid_str2, p_data->char_id.inst_id);
1688 BT_INFO("Desc=> UUID: [%s], Inst_id: [%u]", uuid_str3, p_data->descr_id.inst_id);
1689 BT_INFO("Len: %u, value_type: %u", p_data->value.len, p_data->value_type);
1690 if (p_data->value.len > 0 && event->value_type == GATTC_READ_VALUE_TYPE_VALUE) {
1692 data = g_malloc(3*p_data->value.len+1);
1694 BT_ERR("memory allocation failed");
1698 convert_hex_2_str((unsigned char *)p_data->value.value, p_data->value.len, data);
1699 BT_INFO("Read Data: [%s]", data);
1700 event->data_len = p_data->value.len;
1701 memcpy(&(event->data), &(p_data->value.value), event->data_len);
1705 send_event(OAL_EVENT_GATTC_READ_DESCR, event, sizeof(*event));
1708 oal_status_t gattc_start_le_discovery(int client_id)
1711 int ret = OAL_STATUS_SUCCESS;
1713 API_TRACE("BTGATT CLIENT SCAN START");
1714 CHECK_OAL_GATT_ENABLED();
1715 CHECK_CLIENT_REGISTRATION(client_id);
1717 ret = gatt_api->client->scan(client_id, 1);
1718 if (ret != BT_STATUS_SUCCESS) {
1719 BT_ERR("Error:Start LE Discovery failed: %s", status2string(ret));
1720 return convert_to_oal_status(ret);
1722 send_event(OAL_EVENT_BLE_DISCOVERY_STARTED, NULL, 0);
1723 return OAL_STATUS_SUCCESS;
1726 oal_status_t gattc_stop_le_discovery(int client_id)
1729 int ret = OAL_STATUS_SUCCESS;
1731 API_TRACE("Scan is stopped");
1732 CHECK_OAL_GATT_ENABLED();
1733 CHECK_CLIENT_REGISTRATION(client_id);
1734 ret = gatt_api->client->scan(client_id, 0);
1735 if (ret != BT_STATUS_SUCCESS) {
1736 BT_ERR("Error:Stop LE Discovery failed: %s", status2string(ret));
1737 return convert_to_oal_status(ret);
1739 send_event(OAL_EVENT_BLE_DISCOVERY_STOPPED, NULL, 0);
1740 return OAL_STATUS_SUCCESS;
1743 oal_status_t gattc_set_le_scan_param(int scan_type, int itv, int win)
1747 API_TRACE("Scan is stopped");
1748 CHECK_OAL_GATT_ENABLED();
1751 ret = gatt_api->client->set_scan_parameters(scan_type, itv, win);
1752 if (ret != BT_STATUS_SUCCESS) {
1753 BT_ERR("Error:Set scan parameters failed: %s", status2string(ret));
1754 return convert_to_oal_status(ret);
1757 ret = gatt_api->client->set_scan_parameters(itv, win);
1758 if (ret != BT_STATUS_SUCCESS) {
1759 BT_ERR("Error:Set scan parameters failed: %s", status2string(ret));
1760 return convert_to_oal_status(ret);
1764 return OAL_STATUS_SUCCESS;
1766 /************************************ GATT Client ***********************************/
1767 oal_status_t gattc_register(oal_uuid_t* client_uuid)
1770 char str[2*BT_UUID_STRING_MAX];
1771 int ret = OAL_STATUS_SUCCESS;
1773 CHECK_OAL_GATT_ENABLED();
1774 uuid_to_stringname(client_uuid, str);
1775 API_TRACE("uuid: [%s]", str);
1776 /* We will perform actual registration in cb_gattc_register_app callback */
1777 ret = gatt_api->client->register_client((bt_uuid_t *)client_uuid);
1778 if (ret != BT_STATUS_SUCCESS) {
1779 BT_ERR("GATT client register failed: %s", status2string(ret));
1780 return convert_to_oal_status(ret);
1782 return OAL_STATUS_SUCCESS;
1785 oal_status_t gattc_deregister(int client_id)
1787 int ret = OAL_STATUS_SUCCESS;
1789 API_TRACE("GATT client deregister");
1790 CHECK_OAL_GATT_ENABLED();
1791 CHECK_CLIENT_REGISTRATION(client_id);
1793 ret = gatt_api->client->unregister_client(client_id);
1794 if (ret != BT_STATUS_SUCCESS) {
1795 BT_ERR("GATT client deregister failed: %s", status2string(ret));
1796 return convert_to_oal_status(ret);
1799 return OAL_STATUS_SUCCESS;
1802 oal_status_t gattc_connect(int client_id, bt_address_t *device_address, int isDirect)
1804 int ret = OAL_STATUS_SUCCESS;
1807 OAL_CHECK_PARAMETER(device_address, return);
1808 API_TRACE("Client Connect: [%s]", bdt_bd2str(device_address, &bdstr));
1809 CHECK_OAL_GATT_ENABLED();
1810 CHECK_CLIENT_REGISTRATION(client_id);
1812 /* Handle the actual connection in cb_gattc_connection callback */
1813 ret = gatt_api->client->connect(client_id, (bt_bdaddr_t *)device_address, isDirect);
1814 if (ret != BT_STATUS_SUCCESS) {
1815 BT_ERR("GATT client connect failed: %s", status2string(ret));
1816 return convert_to_oal_status(ret);
1818 return OAL_STATUS_SUCCESS;
1821 oal_status_t gattc_disconnect(int client_id, bt_address_t *device_address, int conn_id)
1824 int ret = OAL_STATUS_SUCCESS;
1827 OAL_CHECK_PARAMETER(device_address, return);
1828 API_TRACE("Client Disconnect: [%s]", bdt_bd2str(device_address, &bdstr));
1829 CHECK_OAL_GATT_ENABLED();
1830 CHECK_CLIENT_REGISTRATION(client_id);
1831 CHECK_CLIENT_CONNECTION(conn_id);
1833 /* Handle actual disconnection in callback */
1834 ret = gatt_api->client->disconnect(client_id, (bt_bdaddr_t *) device_address, conn_id);
1835 if (ret != BT_STATUS_SUCCESS) {
1836 BT_ERR("GATT client disconnect failed: %s", status2string(ret));
1837 return convert_to_oal_status(ret);
1839 return OAL_STATUS_SUCCESS;
1843 oal_status_t gattc_search_service(int conn_id, oal_uuid_t *service_uuid)
1845 int ret = OAL_STATUS_SUCCESS;
1846 char uuid_str[2*BT_UUID_STRING_MAX];
1849 uuid_to_stringname(service_uuid, uuid_str);
1850 API_TRACE("Client Service Search UUID: [%s]", uuid_str);
1852 API_TRACE("Client Service Search All");
1854 CHECK_OAL_GATT_ENABLED();
1855 CHECK_CLIENT_CONNECTION(conn_id);
1856 ret = gatt_api->client->search_service(conn_id, (bt_uuid_t *)service_uuid);
1858 if (ret != BT_STATUS_SUCCESS) {
1859 BT_ERR("GATT client service search failed: %s", status2string(ret));
1860 return convert_to_oal_status(ret);
1862 return OAL_STATUS_SUCCESS;
1865 oal_status_t gattc_get_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id)
1867 int ret = OAL_STATUS_SUCCESS;
1868 char uuid_str[2*BT_UUID_STRING_MAX];
1870 OAL_CHECK_PARAMETER(srvc_id, return);
1871 uuid_to_stringname(&(srvc_id->id.uuid), uuid_str);
1872 API_TRACE("Client Get Characteristic, Service_uuid: [%s]", uuid_str);
1873 CHECK_OAL_GATT_ENABLED();
1874 CHECK_CLIENT_CONNECTION(conn_id);
1875 ret = gatt_api->client->get_characteristic(conn_id, (btgatt_srvc_id_t *)srvc_id,
1876 (btgatt_gatt_id_t *)char_id);
1877 if (ret != BT_STATUS_SUCCESS) {
1878 BT_ERR("GATT client get characteristic failed: %s", status2string(ret));
1879 return convert_to_oal_status(ret);
1881 return OAL_STATUS_SUCCESS;
1884 oal_status_t gattc_get_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id,
1885 oal_gatt_id_t *char_id, oal_gatt_id_t *desc_id)
1887 int ret = OAL_STATUS_SUCCESS;
1888 char uuid_str1[2*BT_UUID_STRING_MAX];
1889 char uuid_str2[2*BT_UUID_STRING_MAX];
1891 OAL_CHECK_PARAMETER(srvc_id, return);
1892 OAL_CHECK_PARAMETER(char_id, return);
1893 uuid_to_stringname(&(srvc_id->id.uuid), uuid_str1);
1894 uuid_to_stringname(&(char_id->uuid), uuid_str2);
1895 API_TRACE("Client Get Descriptor, Service_uuid: [%s], Char_uuid: [%s]", uuid_str1, uuid_str2);
1896 CHECK_OAL_GATT_ENABLED();
1897 CHECK_CLIENT_CONNECTION(conn_id);
1898 ret = gatt_api->client->get_descriptor(conn_id, (btgatt_srvc_id_t *)srvc_id,
1899 (btgatt_gatt_id_t *)char_id, (btgatt_gatt_id_t *)desc_id);
1900 if (ret != BT_STATUS_SUCCESS) {
1901 BT_ERR("GATT client get descriptor failed: %s", status2string(ret));
1902 return convert_to_oal_status(ret);
1904 return OAL_STATUS_SUCCESS;
1907 oal_status_t gattc_register_for_notification(int client_id, bt_address_t * address,
1908 oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id) {
1909 int ret = OAL_STATUS_SUCCESS;
1910 char uuid_str1[2*BT_UUID_STRING_MAX];
1911 char uuid_str2[2*BT_UUID_STRING_MAX];
1914 OAL_CHECK_PARAMETER(address, return);
1915 OAL_CHECK_PARAMETER(srvc_id, return);
1916 OAL_CHECK_PARAMETER(char_id, return);
1917 uuid_to_stringname(&(srvc_id->id.uuid), uuid_str1);
1918 uuid_to_stringname(&(char_id->uuid), uuid_str2);
1919 API_TRACE("Client Register Notification: [%s], Service_uuid: [%s], Char_uuid: [%s]", bdt_bd2str(address, &bdstr), uuid_str1, uuid_str2);
1920 CHECK_OAL_GATT_ENABLED();
1921 CHECK_CLIENT_REGISTRATION(client_id);
1923 ret = gatt_api->client->register_for_notification(client_id, (bt_bdaddr_t *)address, (btgatt_srvc_id_t *)srvc_id, (btgatt_gatt_id_t *)char_id);
1924 if (ret != BT_STATUS_SUCCESS) {
1925 BT_ERR("GATT client register notification failed: %s", status2string(ret));
1926 return convert_to_oal_status(ret);
1929 return OAL_STATUS_SUCCESS;
1932 oal_status_t gattc_deregister_for_notification(int client_id, bt_address_t * address,
1933 oal_gatt_srvc_id_t *srvc_id, oal_gatt_id_t *char_id) {
1934 int ret = OAL_STATUS_SUCCESS;
1935 char uuid_str1[2*BT_UUID_STRING_MAX];
1936 char uuid_str2[2*BT_UUID_STRING_MAX];
1939 OAL_CHECK_PARAMETER(address, return);
1940 OAL_CHECK_PARAMETER(srvc_id, return);
1941 OAL_CHECK_PARAMETER(char_id, return);
1942 uuid_to_stringname(&(srvc_id->id.uuid), uuid_str1);
1943 uuid_to_stringname(&(char_id->uuid), uuid_str2);
1944 API_TRACE("Client Deregister Notification: [%s], Service_uuid: [%s], Char_uuid: [%s]", bdt_bd2str(address, &bdstr), uuid_str1, uuid_str2);
1945 CHECK_OAL_GATT_ENABLED();
1946 CHECK_CLIENT_REGISTRATION(client_id);
1948 ret = gatt_api->client->deregister_for_notification(client_id, (bt_bdaddr_t *)address, (btgatt_srvc_id_t *)srvc_id, (btgatt_gatt_id_t *)char_id);
1949 if (ret != BT_STATUS_SUCCESS) {
1950 BT_ERR("GATT client deregister notification failed: %s", status2string(ret));
1951 return convert_to_oal_status(ret);
1954 return OAL_STATUS_SUCCESS;
1958 oal_status_t gattc_read_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id,
1959 oal_gatt_id_t *char_id, oal_gatt_auth_req_t auth_req)
1961 int ret = OAL_STATUS_SUCCESS;
1962 char uuid_str1[2*BT_UUID_STRING_MAX];
1963 char uuid_str2[2*BT_UUID_STRING_MAX];
1965 OAL_CHECK_PARAMETER(srvc_id, return);
1966 OAL_CHECK_PARAMETER(char_id, return);
1967 uuid_to_stringname(&(srvc_id->id.uuid), uuid_str1);
1968 uuid_to_stringname(&(char_id->uuid), uuid_str2);
1969 API_TRACE("Client Read Characteristic: Service_uuid: [%s], Char_uuid: [%s]", uuid_str1, uuid_str2);
1970 CHECK_OAL_GATT_ENABLED();
1971 CHECK_CLIENT_CONNECTION(conn_id);
1973 ret = gatt_api->client->read_characteristic(conn_id, (btgatt_srvc_id_t *)srvc_id,
1974 (btgatt_gatt_id_t *)char_id, auth_req);
1975 if (ret != BT_STATUS_SUCCESS) {
1976 BT_ERR("GATT client read characteristic failed: %s", status2string(ret));
1977 return convert_to_oal_status(ret);
1980 return OAL_STATUS_SUCCESS;
1983 oal_status_t gattc_read_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id,
1984 oal_gatt_id_t *char_id, oal_gatt_id_t *desc_id, oal_gatt_auth_req_t auth_req)
1986 int ret = OAL_STATUS_SUCCESS;
1987 char uuid_str1[2*BT_UUID_STRING_MAX];
1988 char uuid_str2[2*BT_UUID_STRING_MAX];
1989 char uuid_str3[2*BT_UUID_STRING_MAX];
1991 OAL_CHECK_PARAMETER(srvc_id, return);
1992 OAL_CHECK_PARAMETER(char_id, return);
1993 OAL_CHECK_PARAMETER(desc_id, return);
1994 uuid_to_stringname(&(srvc_id->id.uuid), uuid_str1);
1995 uuid_to_stringname(&(char_id->uuid), uuid_str2);
1996 uuid_to_stringname(&(desc_id->uuid), uuid_str3);
1997 API_TRACE("Client Read Descriptor: Service_uuid: [%s], Char_uuid: [%s], Desc_uuid: [%s]",
1998 uuid_str1, uuid_str2, uuid_str3);
1999 CHECK_OAL_GATT_ENABLED();
2000 CHECK_CLIENT_CONNECTION(conn_id);
2002 ret = gatt_api->client->read_descriptor(conn_id, (btgatt_srvc_id_t *)srvc_id,
2003 (btgatt_gatt_id_t *)char_id, (btgatt_gatt_id_t *)desc_id, auth_req);
2004 if (ret != BT_STATUS_SUCCESS) {
2005 BT_ERR("GATT client read descriptor failed: %s", status2string(ret));
2006 return convert_to_oal_status(ret);
2009 return OAL_STATUS_SUCCESS;
2012 oal_status_t gattc_acquire_notify(int conn_id, oal_gatt_srvc_id_t *srvc_id,
2013 oal_gatt_id_t *char_id, int *fd, int *mtu)
2015 int ret = OAL_STATUS_SUCCESS;
2016 char uuid_str1[2*BT_UUID_STRING_MAX];
2017 char uuid_str2[2*BT_UUID_STRING_MAX];
2018 OAL_CHECK_PARAMETER(srvc_id, return);
2019 OAL_CHECK_PARAMETER(char_id, return);
2020 uuid_to_stringname(&(srvc_id->id.uuid), uuid_str1);
2021 uuid_to_stringname(&(char_id->uuid), uuid_str2);
2022 API_TRACE("Client Write Characteristic: Service_uuid: [%s], Char_uuid: [%s]", uuid_str1, uuid_str2);
2023 CHECK_OAL_GATT_ENABLED();
2024 CHECK_CLIENT_CONNECTION(conn_id);
2026 ret = gatt_api->client->acquire_notify(conn_id, (btgatt_srvc_id_t *)srvc_id,
2027 (btgatt_gatt_id_t *)char_id, fd, mtu);
2028 if (ret != BT_STATUS_SUCCESS) {
2029 BT_ERR("GATT client write characteristic failed: %s", status2string(ret));
2030 return convert_to_oal_status(ret);
2033 return OAL_STATUS_SUCCESS;
2036 oal_status_t gattc_acquire_write(int conn_id, oal_gatt_srvc_id_t *srvc_id,
2037 oal_gatt_id_t *char_id, oal_gatt_auth_req_t auth_req , int *fd, int*mtu)
2039 int ret = OAL_STATUS_SUCCESS;
2040 char uuid_str1[2*BT_UUID_STRING_MAX];
2041 char uuid_str2[2*BT_UUID_STRING_MAX];
2042 OAL_CHECK_PARAMETER(srvc_id, return);
2043 OAL_CHECK_PARAMETER(char_id, return);
2044 uuid_to_stringname(&(srvc_id->id.uuid), uuid_str1);
2045 uuid_to_stringname(&(char_id->uuid), uuid_str2);
2046 API_TRACE("Client Write Characteristic: Service_uuid: [%s], Char_uuid: [%s]", uuid_str1, uuid_str2);
2047 CHECK_OAL_GATT_ENABLED();
2048 CHECK_CLIENT_CONNECTION(conn_id);
2050 ret = gatt_api->client->acquire_write(conn_id, (btgatt_srvc_id_t *)srvc_id,
2051 (btgatt_gatt_id_t *)char_id, auth_req, fd, mtu);
2052 if (ret != BT_STATUS_SUCCESS) {
2053 BT_ERR("GATT client write characteristic failed: %s", status2string(ret));
2054 return convert_to_oal_status(ret);
2057 return OAL_STATUS_SUCCESS;
2060 oal_status_t gattc_write_characteristic(int conn_id, oal_gatt_srvc_id_t *srvc_id,
2061 oal_gatt_id_t *char_id, oal_gatt_write_type_t write_type,
2062 int len, oal_gatt_auth_req_t auth_req, char* data)
2064 int ret = OAL_STATUS_SUCCESS;
2065 char uuid_str1[2*BT_UUID_STRING_MAX];
2066 char uuid_str2[2*BT_UUID_STRING_MAX];
2067 OAL_CHECK_PARAMETER(srvc_id, return);
2068 OAL_CHECK_PARAMETER(char_id, return);
2069 OAL_CHECK_PARAMETER(data, return);
2070 uuid_to_stringname(&(srvc_id->id.uuid), uuid_str1);
2071 uuid_to_stringname(&(char_id->uuid), uuid_str2);
2072 API_TRACE("Client Write Characteristic: Service_uuid: [%s], Char_uuid: [%s]", uuid_str1, uuid_str2);
2073 CHECK_OAL_GATT_ENABLED();
2074 CHECK_CLIENT_CONNECTION(conn_id);
2076 ret = gatt_api->client->write_characteristic(conn_id, (btgatt_srvc_id_t *)srvc_id,
2077 (btgatt_gatt_id_t *)char_id, write_type, len, auth_req, data);
2078 if (ret != BT_STATUS_SUCCESS) {
2079 BT_ERR("GATT client write characteristic failed: %s", status2string(ret));
2080 return convert_to_oal_status(ret);
2083 return OAL_STATUS_SUCCESS;
2086 oal_status_t gattc_write_descriptor(int conn_id, oal_gatt_srvc_id_t *srvc_id,
2087 oal_gatt_id_t *char_id, oal_gatt_id_t *desc_id,
2088 oal_gatt_write_type_t write_type, int len, oal_gatt_auth_req_t auth_req, char* data)
2090 int ret = OAL_STATUS_SUCCESS;
2091 char uuid_str1[2*BT_UUID_STRING_MAX];
2092 char uuid_str2[2*BT_UUID_STRING_MAX];
2093 char uuid_str3[2*BT_UUID_STRING_MAX];
2094 OAL_CHECK_PARAMETER(srvc_id, return);
2095 OAL_CHECK_PARAMETER(char_id, return);
2096 OAL_CHECK_PARAMETER(desc_id, return);
2097 OAL_CHECK_PARAMETER(data, return);
2098 uuid_to_stringname(&(srvc_id->id.uuid), uuid_str1);
2099 uuid_to_stringname(&(char_id->uuid), uuid_str2);
2100 uuid_to_stringname(&(desc_id->uuid), uuid_str3);
2101 API_TRACE("Client Write Descriptor: Service_uuid: [%s], Char_uuid: [%s], Desc_uuid: [%s]",
2102 uuid_str1, uuid_str2, uuid_str3);
2103 CHECK_OAL_GATT_ENABLED();
2104 CHECK_CLIENT_CONNECTION(conn_id);
2106 ret = gatt_api->client->write_descriptor(conn_id, (btgatt_srvc_id_t *)srvc_id,
2107 (btgatt_gatt_id_t *)char_id, (btgatt_gatt_id_t *)desc_id, write_type, len, auth_req, data);
2108 if (ret != BT_STATUS_SUCCESS) {
2109 BT_ERR("GATT client write characteristic failed: %s", status2string(ret));
2110 return convert_to_oal_status(ret);
2113 return OAL_STATUS_SUCCESS;
2116 oal_status_t gattc_conn_param_update(bt_address_t * address, int min, int max, int latency, int timeout)
2121 OAL_CHECK_PARAMETER(address, return);
2122 API_TRACE("Conn Param Update: [%s]", bdt_bd2str(address, &bdstr));
2123 CHECK_OAL_GATT_ENABLED();
2125 BT_INFO("[%s] min[%d] max[%d] latency[%d] timeout[%d]", bdt_bd2str(address, &bdstr), min, max, latency, timeout);
2126 ret = gatt_api->client->conn_parameter_update((bt_bdaddr_t *)address, min, max, latency, timeout);
2127 if (ret != BT_STATUS_SUCCESS) {
2128 BT_ERR("error: %s", status2string(ret));
2129 return convert_to_oal_status(ret);
2131 return OAL_STATUS_SUCCESS;