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 "bt_common.h"
32 #include <string.h>
33 #include "port_api.h"
34 #include "sdp_api.h"
35 
36 /*****************************************************************************
37 **  Constants
38 *****************************************************************************/
39 
40 static 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 *******************************************************************************/
BTA_MceEnable(tBTA_MCE_DM_CBACK * p_cback)60 tBTA_MCE_STATUS BTA_MceEnable(tBTA_MCE_DM_CBACK *p_cback)
61 {
62     tBTA_MCE_STATUS status = BTA_MCE_FAILURE;
63 
64     APPL_TRACE_API("%", __func__);
65 
66     if (p_cback && FALSE == bta_sys_is_register(BTA_ID_MCE)) {
67         memset(&bta_mce_cb, 0, sizeof(tBTA_MCE_CB));
68 
69         /* register with BTA system manager */
70         bta_sys_register(BTA_ID_MCE, &bta_mce_reg);
71 
72         if (p_cback) {
73             tBTA_MCE_API_ENABLE *p_buf =
74                 (tBTA_MCE_API_ENABLE *)osi_malloc(sizeof(tBTA_MCE_API_ENABLE));
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 
82     return status;
83 }
84 
85 /*******************************************************************************
86 **
87 ** Function         BTA_MceGetRemoteMasInstances
88 **
89 ** Description      This function performs service discovery for the MAS service
90 **                  by the given peer device. When the operation is completed
91 **                  the tBTA_MCE_DM_CBACK callback function will be  called with
92 **                  a BTA_MCE_MAS_DISCOVERY_COMP_EVT.
93 **
94 ** Returns          BTA_MCE_SUCCESS, if the request is being processed.
95 **                  BTA_MCE_FAILURE, otherwise.
96 **
97 *******************************************************************************/
BTA_MceGetRemoteMasInstances(BD_ADDR bd_addr)98 tBTA_MCE_STATUS BTA_MceGetRemoteMasInstances(BD_ADDR bd_addr)
99 {
100     tBTA_MCE_API_GET_REMOTE_MAS_INSTANCES *p_msg =
101         (tBTA_MCE_API_GET_REMOTE_MAS_INSTANCES *)osi_malloc(sizeof(tBTA_MCE_API_GET_REMOTE_MAS_INSTANCES));
102 
103     APPL_TRACE_API("%s", __func__);
104 
105     p_msg->hdr.event = BTA_MCE_API_GET_REMOTE_MAS_INSTANCES_EVT;
106     bdcpy(p_msg->bd_addr, bd_addr);
107 
108     bta_sys_sendmsg(p_msg);
109 
110     return BTA_MCE_SUCCESS;
111 }
112