2016-09-26 09:37:39 -04:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003-2012 Broadcom Corporation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at:
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* This file contains the GATT server main functions and state machine.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "common/bt_target.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
|
2017-04-20 07:18:05 -04:00
|
|
|
#if defined(GATTS_INCLUDED) && (GATTS_INCLUDED == TRUE)
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "bta_gatts_int.h"
|
2018-04-08 00:10:50 -04:00
|
|
|
#include "osi/allocator.h"
|
2016-09-26 09:37:39 -04:00
|
|
|
|
|
|
|
/* type for service building action functions */
|
|
|
|
typedef void (*tBTA_GATTS_SRVC_ACT)(tBTA_GATTS_SRVC_CB *p_rcb, tBTA_GATTS_DATA *p_data);
|
|
|
|
|
|
|
|
/* service building action function list */
|
2016-11-24 13:10:15 -05:00
|
|
|
const tBTA_GATTS_SRVC_ACT bta_gatts_srvc_build_act[] = {
|
2016-09-26 09:37:39 -04:00
|
|
|
bta_gatts_add_include_srvc,
|
|
|
|
bta_gatts_add_char,
|
|
|
|
bta_gatts_add_char_descr,
|
|
|
|
bta_gatts_delete_service,
|
|
|
|
bta_gatts_start_service,
|
|
|
|
bta_gatts_stop_service,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* GATTS control block */
|
|
|
|
#if BTA_DYNAMIC_MEMORY == FALSE
|
|
|
|
tBTA_GATTS_CB bta_gatts_cb;
|
2017-10-18 03:34:43 -04:00
|
|
|
#else
|
|
|
|
tBTA_GATTS_CB *bta_gatts_cb_ptr;
|
2016-09-26 09:37:39 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
**
|
|
|
|
** Function bta_gatts_hdl_event
|
|
|
|
**
|
|
|
|
** Description BTA GATT server main event handling function.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** Returns void
|
|
|
|
**
|
|
|
|
*******************************************************************************/
|
|
|
|
BOOLEAN bta_gatts_hdl_event(BT_HDR *p_msg)
|
|
|
|
{
|
|
|
|
tBTA_GATTS_CB *p_cb = &bta_gatts_cb;
|
|
|
|
tBTA_GATTS_SRVC_CB *p_srvc_cb = NULL;
|
|
|
|
|
2016-11-24 13:10:15 -05:00
|
|
|
switch (p_msg->event) {
|
|
|
|
case BTA_GATTS_API_DISABLE_EVT:
|
|
|
|
bta_gatts_api_disable(p_cb);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTA_GATTS_API_REG_EVT:
|
|
|
|
bta_gatts_register(p_cb, (tBTA_GATTS_DATA *) p_msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTA_GATTS_INT_START_IF_EVT:
|
|
|
|
bta_gatts_start_if(p_cb, (tBTA_GATTS_DATA *) p_msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTA_GATTS_API_DEREG_EVT:
|
|
|
|
bta_gatts_deregister(p_cb, (tBTA_GATTS_DATA *) p_msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTA_GATTS_API_CREATE_SRVC_EVT:
|
|
|
|
bta_gatts_create_srvc(p_cb, (tBTA_GATTS_DATA *) p_msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTA_GATTS_API_INDICATION_EVT:
|
|
|
|
bta_gatts_indicate_handle(p_cb, (tBTA_GATTS_DATA *) p_msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTA_GATTS_API_OPEN_EVT:
|
|
|
|
bta_gatts_open(p_cb, (tBTA_GATTS_DATA *) p_msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTA_GATTS_API_CANCEL_OPEN_EVT:
|
|
|
|
bta_gatts_cancel_open(p_cb, (tBTA_GATTS_DATA *) p_msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTA_GATTS_API_CLOSE_EVT:
|
|
|
|
bta_gatts_close(p_cb, (tBTA_GATTS_DATA *) p_msg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BTA_GATTS_API_RSP_EVT:
|
|
|
|
bta_gatts_send_rsp(p_cb, (tBTA_GATTS_DATA *) p_msg);
|
|
|
|
break;
|
2016-12-23 11:28:47 -05:00
|
|
|
case BTA_GATTS_API_SET_ATTR_VAL_EVT:{
|
|
|
|
UINT16 attr_id = ((tBTA_GATTS_DATA *) p_msg)->api_set_val.hdr.layer_specific;
|
|
|
|
p_srvc_cb = bta_gatts_find_srvc_cb_by_attr_id(p_cb, attr_id);
|
|
|
|
bta_gatts_set_attr_value(p_srvc_cb, (tBTA_GATTS_DATA *) p_msg);
|
|
|
|
break;
|
|
|
|
}
|
2016-11-24 13:10:15 -05:00
|
|
|
case BTA_GATTS_API_LISTEN_EVT:
|
|
|
|
bta_gatts_listen(p_cb, (tBTA_GATTS_DATA *) p_msg);
|
|
|
|
break;
|
|
|
|
case BTA_GATTS_API_ADD_INCL_SRVC_EVT:
|
|
|
|
case BTA_GATTS_API_ADD_CHAR_EVT:
|
|
|
|
case BTA_GATTS_API_ADD_DESCR_EVT:
|
|
|
|
case BTA_GATTS_API_DEL_SRVC_EVT:
|
|
|
|
case BTA_GATTS_API_START_SRVC_EVT:
|
|
|
|
case BTA_GATTS_API_STOP_SRVC_EVT:
|
|
|
|
p_srvc_cb = bta_gatts_find_srvc_cb_by_srvc_id(p_cb,
|
|
|
|
((tBTA_GATTS_DATA *)p_msg)->api_add_incl_srvc.hdr.layer_specific);
|
|
|
|
|
|
|
|
if (p_srvc_cb != NULL) {
|
|
|
|
bta_gatts_srvc_build_act[p_msg->event - BTA_GATTS_API_ADD_INCL_SRVC_EVT](p_srvc_cb, (tBTA_GATTS_DATA *) p_msg);
|
|
|
|
} else {
|
2016-12-23 11:28:47 -05:00
|
|
|
APPL_TRACE_ERROR("service not created\n");
|
2016-11-24 13:10:15 -05:00
|
|
|
}
|
|
|
|
break;
|
2018-09-18 04:20:13 -04:00
|
|
|
case BTA_GATTS_API_SEND_SERVICE_CHANGE_EVT:
|
|
|
|
bta_gatts_send_service_change_indication((tBTA_GATTS_DATA *) p_msg);
|
|
|
|
break;
|
2023-04-23 05:13:04 -04:00
|
|
|
case BTA_GATTS_API_SHOW_LOCAL_DATABASE_EVT:
|
|
|
|
bta_gatts_show_local_database();
|
|
|
|
break;
|
2016-11-24 13:10:15 -05:00
|
|
|
default:
|
|
|
|
break;
|
2016-09-26 09:37:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return (TRUE);
|
|
|
|
}
|
|
|
|
|
2017-10-18 03:34:43 -04:00
|
|
|
void bta_gatts_deinit(void)
|
|
|
|
{
|
|
|
|
memset(&bta_gatts_cb, 0, sizeof(tBTA_GATTS_CB));
|
|
|
|
#if BTA_DYNAMIC_MEMORY
|
|
|
|
FREE_AND_RESET(bta_gatts_cb_ptr);
|
|
|
|
#endif /* #if BTA_DYNAMIC_MEMORY */
|
|
|
|
}
|
|
|
|
|
2024-01-15 21:48:48 -05:00
|
|
|
uint8_t bta_gatts_srvc_active_count(void)
|
|
|
|
{
|
|
|
|
uint8_t count = 0;
|
|
|
|
|
|
|
|
for (uint8_t i = 0; i < BTA_GATTS_MAX_SRVC_NUM; i ++) {
|
|
|
|
if (bta_gatts_cb.srvc_cb[i].in_use) {
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2017-04-20 07:18:05 -04:00
|
|
|
#endif /* GATTS_INCLUDED */
|