1/******************************************************************************
2 *
3 *  Copyright (C) 2014 The Android Open Source Project
4 *  Copyright (C) 2003-2012 Broadcom Corporation
5 *
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:
9 *
10 *  http://www.apache.org/licenses/LICENSE-2.0
11 *
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.
17 *
18 ******************************************************************************/
19
20/******************************************************************************
21 *
22 *  This is the implementation of the API for MCE subsystem
23 *
24 ******************************************************************************/
25
26#include "bta_api.h"
27#include "bt_types.h"
28#include "bta_sys.h"
29#include "bta_mce_api.h"
30#include "bta_mce_int.h"
31#include "gki.h"
32#include <string.h>
33#include "port_api.h"
34#include "sdp_api.h"
35
36/*****************************************************************************
37**  Constants
38*****************************************************************************/
39
40static const tBTA_SYS_REG bta_mce_reg =
41{
42    bta_mce_sm_execute,
43    NULL
44};
45
46/*******************************************************************************
47**
48** Function         BTA_MceEnable
49**
50** Description      Enable the MCE I/F service. When the enable
51**                  operation is complete the callback function will be
52**                  called with a BTA_MCE_ENABLE_EVT. This function must
53**                  be called before other functions in the MCE API are
54**                  called.
55**
56** Returns          BTA_MCE_SUCCESS if successful.
57**                  BTA_MCE_FAIL if internal failure.
58**
59*******************************************************************************/
60tBTA_MCE_STATUS BTA_MceEnable(tBTA_MCE_DM_CBACK *p_cback)
61{
62    tBTA_MCE_STATUS status = BTA_MCE_FAILURE;
63    tBTA_MCE_API_ENABLE  *p_buf;
64
65    APPL_TRACE_API(__FUNCTION__);
66    if(p_cback && FALSE == bta_sys_is_register(BTA_ID_MCE))
67    {
68        memset(&bta_mce_cb, 0, sizeof(tBTA_MCE_CB));
69
70        /* register with BTA system manager */
71        bta_sys_register(BTA_ID_MCE, &bta_mce_reg);
72
73        if (p_cback && (p_buf = (tBTA_MCE_API_ENABLE *) GKI_getbuf(sizeof(tBTA_MCE_API_ENABLE))) != NULL)
74        {
75            p_buf->hdr.event = BTA_MCE_API_ENABLE_EVT;
76            p_buf->p_cback = p_cback;
77            bta_sys_sendmsg(p_buf);
78            status = BTA_MCE_SUCCESS;
79        }
80    }
81    return(status);
82}
83
84/*******************************************************************************
85**
86** Function         BTA_MceGetRemoteMasInstances
87**
88** Description      This function performs service discovery for the MAS service
89**                  by the given peer device. When the operation is completed
90**                  the tBTA_MCE_DM_CBACK callback function will be  called with
91**                  a BTA_MCE_MAS_DISCOVERY_COMP_EVT.
92**
93** Returns          BTA_MCE_SUCCESS, if the request is being processed.
94**                  BTA_MCE_FAILURE, otherwise.
95**
96*******************************************************************************/
97tBTA_MCE_STATUS BTA_MceGetRemoteMasInstances(BD_ADDR bd_addr)
98{
99    tBTA_MCE_STATUS ret = BTA_MCE_FAILURE;
100    tBTA_MCE_API_GET_REMOTE_MAS_INSTANCES *p_msg;
101
102    APPL_TRACE_API(__FUNCTION__);
103    if ((p_msg = (tBTA_MCE_API_GET_REMOTE_MAS_INSTANCES *)GKI_getbuf(sizeof(tBTA_MCE_API_GET_REMOTE_MAS_INSTANCES))) != NULL)
104    {
105        p_msg->hdr.event = BTA_MCE_API_GET_REMOTE_MAS_INSTANCES_EVT;
106        bdcpy(p_msg->bd_addr, bd_addr);
107        bta_sys_sendmsg(p_msg);
108        ret = BTA_MCE_SUCCESS;
109    }
110
111    return(ret);
112}
113