1 /****************************************************************************** 2 * 3 * Copyright (C) 2003-2012 Broadcom Corporation 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 /****************************************************************************** 20 * 21 * This file contains the GATT server main functions and state machine. 22 * 23 ******************************************************************************/ 24 25 #include "bt_target.h" 26 27 #include <string.h> 28 29 #include "bt_common.h" 30 #include "bta_gatts_int.h" 31 32 /* GATTS control block */ 33 tBTA_GATTS_CB bta_gatts_cb; 34 35 /******************************************************************************* 36 * 37 * Function bta_gatts_hdl_event 38 * 39 * Description BTA GATT server main event handling function. 40 * 41 * 42 * Returns void 43 * 44 ******************************************************************************/ 45 bool bta_gatts_hdl_event(BT_HDR* p_msg) { 46 tBTA_GATTS_CB* p_cb = &bta_gatts_cb; 47 48 switch (p_msg->event) { 49 case BTA_GATTS_API_DISABLE_EVT: 50 bta_gatts_api_disable(p_cb); 51 break; 52 53 case BTA_GATTS_API_REG_EVT: 54 bta_gatts_register(p_cb, (tBTA_GATTS_DATA*)p_msg); 55 break; 56 57 case BTA_GATTS_INT_START_IF_EVT: 58 bta_gatts_start_if(p_cb, (tBTA_GATTS_DATA*)p_msg); 59 break; 60 61 case BTA_GATTS_API_DEREG_EVT: 62 bta_gatts_deregister(p_cb, (tBTA_GATTS_DATA*)p_msg); 63 break; 64 65 case BTA_GATTS_API_INDICATION_EVT: 66 bta_gatts_indicate_handle(p_cb, (tBTA_GATTS_DATA*)p_msg); 67 break; 68 69 case BTA_GATTS_API_OPEN_EVT: 70 bta_gatts_open(p_cb, (tBTA_GATTS_DATA*)p_msg); 71 break; 72 73 case BTA_GATTS_API_CANCEL_OPEN_EVT: 74 bta_gatts_cancel_open(p_cb, (tBTA_GATTS_DATA*)p_msg); 75 break; 76 77 case BTA_GATTS_API_CLOSE_EVT: 78 bta_gatts_close(p_cb, (tBTA_GATTS_DATA*)p_msg); 79 break; 80 81 case BTA_GATTS_API_RSP_EVT: 82 bta_gatts_send_rsp(p_cb, (tBTA_GATTS_DATA*)p_msg); 83 break; 84 85 case BTA_GATTS_API_DEL_SRVC_EVT: { 86 tBTA_GATTS_SRVC_CB* p_srvc_cb = bta_gatts_find_srvc_cb_by_srvc_id( 87 p_cb, ((tBTA_GATTS_DATA*)p_msg)->api_add_service.hdr.layer_specific); 88 89 if (p_srvc_cb != NULL) 90 bta_gatts_delete_service(p_srvc_cb, (tBTA_GATTS_DATA*)p_msg); 91 else 92 APPL_TRACE_ERROR("%s: can't delete service - no srvc_cb found", 93 __func__); 94 95 break; 96 } 97 98 case BTA_GATTS_API_STOP_SRVC_EVT: { 99 tBTA_GATTS_SRVC_CB* p_srvc_cb = bta_gatts_find_srvc_cb_by_srvc_id( 100 p_cb, ((tBTA_GATTS_DATA*)p_msg)->api_add_service.hdr.layer_specific); 101 102 if (p_srvc_cb != NULL) 103 bta_gatts_stop_service(p_srvc_cb, (tBTA_GATTS_DATA*)p_msg); 104 else 105 APPL_TRACE_ERROR("%s: can't stop service - no srvc_cb found", __func__); 106 107 break; 108 } 109 110 default: 111 break; 112 } 113 114 return (true); 115 } 116