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