btif_gatt.c revision ead3cde4bac0c3e32cd31f149093f004eef8ceeb
1b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org/******************************************************************************
2b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *
3b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  Copyright (C) 2009-2013 Broadcom Corporation
4b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *
5b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  Licensed under the Apache License, Version 2.0 (the "License");
6b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  you may not use this file except in compliance with the License.
7b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  You may obtain a copy of the License at:
8b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *
9b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  http://www.apache.org/licenses/LICENSE-2.0
10b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *
1199199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com *  Unless required by applicable law or agreed to in writing, software
1299199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com *  distributed under the License is distributed on an "AS IS" BASIS,
13b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14a557f436b9d694d5a0a045e0295e1794f2df48eapbos@webrtc.org *  See the License for the specific language governing permissions and
157b2147f8975308f753380cf0248b84a733970a10agalusza@google.com *  limitations under the License.
16a557f436b9d694d5a0a045e0295e1794f2df48eapbos@webrtc.org *
17a557f436b9d694d5a0a045e0295e1794f2df48eapbos@webrtc.org ******************************************************************************/
18a557f436b9d694d5a0a045e0295e1794f2df48eapbos@webrtc.org
19a557f436b9d694d5a0a045e0295e1794f2df48eapbos@webrtc.org
20b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org/*******************************************************************************
2199199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com *
2299199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com *  Filename:      btif_gatt.c
2399199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com *
2499199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com *  Description:   GATT Profile Bluetooth Interface
2599199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com *
2699199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com *******************************************************************************/
2799199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com
2899199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com#include <hardware/bluetooth.h>
2999199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com#include <hardware/bt_gatt.h>
3099199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com#include <stdio.h>
3199199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com#include <stdlib.h>
3299199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com#include <errno.h>
3399199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com#include <string.h>
347b2147f8975308f753380cf0248b84a733970a10agalusza@google.com
3599199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com#define LOG_TAG "BtGatt.btif"
3699199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com
3799199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com#include "btif_common.h"
3899199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com#include "btif_util.h"
3999199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com
4099199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com#if (defined(BLE_INCLUDED) && (BLE_INCLUDED == TRUE))
4199199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com
4299199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com#include "bta_api.h"
4399199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com#include "bta_gatt_api.h"
4499199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com#include "bd.h"
4599199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com#include "btif_storage.h"
4699199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com
4799199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com#include "btif_gatt.h"
4899199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com#include "btif_gatt_util.h"
4999199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com
5099199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.comconst btgatt_callbacks_t *bt_gatt_callbacks = NULL;
5199199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com
5299199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.comextern btgatt_client_interface_t btgattClientInterface;
5399199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.comextern btgatt_server_interface_t btgattServerInterface;
5499199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com
5599199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com/*******************************************************************************
5699199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com**
5799199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com** Function         btif_gatt_init
5899199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com**
5999199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com** Description      Initializes the GATT interface
6099199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com**
6199199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com** Returns    s      bt_status_t
6299199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com**
6399199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com*******************************************************************************/
6499199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.comstatic bt_status_t btif_gatt_init( const btgatt_callbacks_t* callbacks )
6599199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com{
6699199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com    bt_gatt_callbacks = callbacks;
6799199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com
6899199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com    BTA_GATTC_Init();
6999199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com    BTA_GATTS_Init();
7099199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com
7199199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com    return BT_STATUS_SUCCESS;
7299199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com}
7399199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com
7499199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com/*******************************************************************************
7599199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com**
7699199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com** Function         btif_gatt_cleanup
7799199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com**
7899199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com** Description      Closes the GATT interface
7999199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com**
80098704346096e90c689fbebb2224ea5dd184fb46mikhal@webrtc.org** Returns          void
81098704346096e90c689fbebb2224ea5dd184fb46mikhal@webrtc.org**
82098704346096e90c689fbebb2224ea5dd184fb46mikhal@webrtc.org*******************************************************************************/
837b0ab2addc0fb6e22515fc949b727cba5636fa64agalusza@google.comstatic void  btif_gatt_cleanup( void )
8499199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com{
8599199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com    if (bt_gatt_callbacks)
8699199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com        bt_gatt_callbacks = NULL;
8799199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com}
8899199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com
8999199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.comstatic const btgatt_interface_t btgattInterface = {
9099199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com    sizeof(btgattInterface),
9199199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com
92b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org    btif_gatt_init,
93b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org    btif_gatt_cleanup,
943b89e10f31160da35b408fd00cb8f89d2b08862dpbos@webrtc.org
95b015cbede88899f67a53fbbe581b02ce8e32794andrew@webrtc.org    &btgattClientInterface,
9699199e5b490cc99936d798ca5958cf9eb26228e0agalusza@google.com    &btgattServerInterface,
97};
98
99/*******************************************************************************
100**
101** Function         btif_gatt_get_interface
102**
103** Description      Get the gatt callback interface
104**
105** Returns          btgatt_interface_t
106**
107*******************************************************************************/
108const btgatt_interface_t *btif_gatt_get_interface()
109{
110    return &btgattInterface;
111}
112
113#endif
114