Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d0ecdbb8 authored by Hemant Gupta's avatar Hemant Gupta Committed by Mike Lockwood
Browse files

Bluetooth: Support MAP Client role on Bluedroid.

Implementation changes from BTA and BTIF layer to support
MCE role on Bluedroid stack.

Change-Id: I8547b0f28338e83edabae969121872ca23fdcb36
parent 8da49f99
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -73,6 +73,10 @@ LOCAL_SRC_FILES:= \
    ./hl/bta_hl_utils.c \
    ./hl/bta_hl_sdp.c \
    ./hl/bta_hl_ci.c \
    ./mce/bta_mce_api.c \
    ./mce/bta_mce_main.c \
    ./mce/bta_mce_act.c \
    ./mce/bta_mce_cfg.c \
    ./sys/bta_sys_main.c \
    ./sys/bta_sys_ci.c \
    ./sys/bta_sys_conn.c \
+132 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2014 The Android Open Source Project
 *  Copyright (C) 2006-2012 Broadcom Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

/******************************************************************************
 *
 *  This is the public interface file the BTA MCE I/F
 *
 ******************************************************************************/
#ifndef BTA_MCE_API_H
#define BTA_MCE_API_H

#include "data_types.h"
#include "bt_target.h"
#include "bt_types.h"
#include "bta_api.h"
#include "btm_api.h"

/*****************************************************************************
**  Constants and data types
*****************************************************************************/
/* status values */
#define BTA_MCE_SUCCESS             0            /* Successful operation. */
#define BTA_MCE_FAILURE             1            /* Generic failure. */
#define BTA_MCE_BUSY                2            /* Temporarily can not handle this request. */

typedef UINT8 tBTA_MCE_STATUS;

/* MCE I/F callback events */
/* events received by tBTA_MCE_DM_CBACK */
#define BTA_MCE_ENABLE_EVT               0  /* MCE enabled */
#define BTA_MCE_MAS_DISCOVERY_COMP_EVT   1  /* SDP MAS discovery complete */
#define BTA_MCE_MAX_EVT                  2  /* max number of MCE events */

#define BTA_MCE_MAX_MAS_INSTANCES 12

typedef UINT16 tBTA_MCE_EVT;

typedef struct
{
    UINT8   scn;
    char    *p_srv_name;
    UINT16  srv_name_len;
    UINT8   instance_id;
    UINT8   msg_type;
} tBTA_MCE_MAS_INFO;

/* data associated with BTA_MCE_MAS_DISCOVERY_COMP_EVT */
typedef struct
{
    tBTA_MCE_STATUS    status;
    BD_ADDR            remote_addr;
    int                num_mas;
    tBTA_MCE_MAS_INFO  mas[BTA_MCE_MAX_MAS_INSTANCES];
} tBTA_MCE_MAS_DISCOVERY_COMP;

/* union of data associated with MCE callback */
typedef union
{
    tBTA_MCE_STATUS              status;         /* BTA_MCE_ENABLE_EVT */
    tBTA_MCE_MAS_DISCOVERY_COMP  mas_disc_comp;  /* BTA_MCE_MAS_DISCOVERY_COMP_EVT */
} tBTA_MCE;

/* MCE DM Interface callback */
typedef void (tBTA_MCE_DM_CBACK)(tBTA_MCE_EVT event, tBTA_MCE *p_data, void * user_data);

/* MCE configuration structure */
typedef struct
{
    UINT16  sdp_db_size;            /* The size of p_sdp_db */
    tSDP_DISCOVERY_DB   *p_sdp_db;  /* The data buffer to keep SDP database */
} tBTA_MCE_CFG;

/*****************************************************************************
**  External Function Declarations
*****************************************************************************/
#ifdef __cplusplus
extern "C"
{
#endif

/*******************************************************************************
**
** Function         BTA_MceEnable
**
** Description      Enable the MCE I/F service. When the enable
**                  operation is complete the callback function will be
**                  called with a BTA_MCE_ENABLE_EVT. This function must
**                  be called before other functions in the MCE API are
**                  called.
**
** Returns          BTA_MCE_SUCCESS if successful.
**                  BTA_MCE_FAIL if internal failure.
**
*******************************************************************************/
BTA_API extern tBTA_MCE_STATUS BTA_MceEnable(tBTA_MCE_DM_CBACK *p_cback);

/*******************************************************************************
**
** Function         BTA_MceGetRemoteMasInstances
**
** Description      This function performs service discovery for the MAS service
**                  by the given peer device. When the operation is completed
**                  the tBTA_MCE_DM_CBACK callback function will be  called with
**                  a BTA_MCE_MAS_DISCOVERY_COMP_EVT.
**
** Returns          BTA_MCE_SUCCESS, if the request is being processed.
**                  BTA_MCE_FAILURE, otherwise.
**
*******************************************************************************/
BTA_API extern tBTA_MCE_STATUS BTA_MceGetRemoteMasInstances(BD_ADDR bd_addr);

#ifdef __cplusplus
}
#endif

#endif /* BTA_MCE_API_H */
+2 −1
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2014 The Android Open Source Project
 *  Copyright (C) 2004-2012 Broadcom Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
@@ -42,7 +43,7 @@
 * p_bta_jv_cfg->p_sdp_raw_data can be allocated before calling BTA_JvStartDiscovery
 * it can be de-allocated after the last call to access the database */
static UINT8 bta_jv_sdp_raw_data[BTA_JV_SDP_RAW_DATA_SIZE];
static UINT8 bta_jv_sdp_db_data[BTA_JV_SDP_DB_SIZE];
static UINT8 __attribute__ ((aligned(4))) bta_jv_sdp_db_data[BTA_JV_SDP_DB_SIZE];

/* JV configuration structure */
const tBTA_JV_CFG bta_jv_cfg =
+186 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2014 The Android Open Source Project
 *  Copyright (C) 2003-2012 Broadcom Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

/******************************************************************************
 *
 *  This file contains action functions for MCE.
 *
 ******************************************************************************/

#include <hardware/bluetooth.h>
#include <arpa/inet.h>

#include "bt_types.h"
#include "gki.h"
#include "bd.h"
#include "utl.h"
#include "bta_sys.h"
#include "bta_api.h"
#include "bta_mce_api.h"
#include "bta_mce_int.h"
#include "btm_api.h"
#include "btm_int.h"
#include "sdp_api.h"
#include <string.h>

/*****************************************************************************
**  Constants
*****************************************************************************/

static const tBT_UUID bta_mce_mas_uuid = {
    .len = 2,
    .uu.uuid16 = UUID_SERVCLASS_MESSAGE_ACCESS
};

/*******************************************************************************
**
** Function     bta_mce_search_cback
**
** Description  Callback from btm after search is completed
**
** Returns      void
**
*******************************************************************************/

static void bta_mce_search_cback(UINT16 result, void * user_data)
{
    tSDP_DISC_REC *p_rec = NULL;
    tBTA_MCE_MAS_DISCOVERY_COMP evt_data;
    int found = 0;

    APPL_TRACE_DEBUG("bta_mce_start_discovery_cback res: 0x%x", result);

    bta_mce_cb.sdp_active = BTA_MCE_SDP_ACT_NONE;

    if (bta_mce_cb.p_dm_cback == NULL) return;

    evt_data.status = BTA_MCE_FAILURE;
    bdcpy(evt_data.remote_addr, bta_mce_cb.remote_addr);
    evt_data.num_mas = 0;

    if (result == SDP_SUCCESS || result == SDP_DB_FULL)
    {
        do
        {
            tSDP_DISC_ATTR *p_attr;
            tSDP_PROTOCOL_ELEM pe;

            p_rec = SDP_FindServiceUUIDInDb(p_bta_mce_cfg->p_sdp_db, (tBT_UUID*) &bta_mce_mas_uuid, p_rec);

            APPL_TRACE_DEBUG("p_rec:%p", p_rec);

            if (p_rec == NULL)
                break;

            if (!SDP_FindProtocolListElemInRec(p_rec, UUID_PROTOCOL_RFCOMM, &pe))
                continue;

            evt_data.mas[found].scn = pe.params[0];

            if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SERVICE_NAME)) == NULL)
                continue;

            evt_data.mas[found].p_srv_name = (char *) p_attr->attr_value.v.array;
            evt_data.mas[found].srv_name_len= SDP_DISC_ATTR_LEN(p_attr->attr_len_type);

            if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_MAS_INSTANCE_ID)) == NULL)
                break;

                 evt_data.mas[found].instance_id = p_attr->attr_value.v.u8;

            if ((p_attr = SDP_FindAttributeInRec(p_rec, ATTR_ID_SUPPORTED_MSG_TYPE)) == NULL)
                break;

            evt_data.mas[found].msg_type = p_attr->attr_value.v.u8;

            found++;
        } while (p_rec != NULL && found < BTA_MCE_MAX_MAS_INSTANCES);

        evt_data.num_mas = found;
        evt_data.status = BTA_MCE_SUCCESS;
    }

    bta_mce_cb.p_dm_cback(BTA_MCE_MAS_DISCOVERY_COMP_EVT, (tBTA_MCE*) &evt_data, user_data);
}

/*******************************************************************************
**
** Function     bta_mce_enable
**
** Description  Initializes the MCE I/F
**
** Returns      void
**
*******************************************************************************/
void bta_mce_enable(tBTA_MCE_MSG *p_data)
{
    tBTA_MCE_STATUS status = BTA_MCE_SUCCESS;
    bta_mce_cb.p_dm_cback = p_data->enable.p_cback;
    bta_mce_cb.p_dm_cback(BTA_MCE_ENABLE_EVT, (tBTA_MCE *)&status, NULL);
}

/*******************************************************************************
**
** Function     bta_mce_get_remote_mas_instances
**
** Description  Discovers MAS instances on remote device
**
** Returns      void
**
*******************************************************************************/
void bta_mce_get_remote_mas_instances(tBTA_MCE_MSG *p_data)
{
    if(p_data == NULL)
    {
    APPL_TRACE_DEBUG("MCE control block handle is null");
    return;
    }
    tBTA_MCE_STATUS status = BTA_MCE_FAILURE;

    APPL_TRACE_DEBUG("%s in, sdp_active:%d", __FUNCTION__, bta_mce_cb.sdp_active);

    if (bta_mce_cb.sdp_active != BTA_MCE_SDP_ACT_NONE)
    {
        /* SDP is still in progress */
        status = BTA_MCE_BUSY;
        if(bta_mce_cb.p_dm_cback)
            bta_mce_cb.p_dm_cback(BTA_MCE_MAS_DISCOVERY_COMP_EVT, (tBTA_MCE *)&status, NULL);

        return;
    }

    bta_mce_cb.sdp_active = BTA_MCE_SDP_ACT_YES;
    bdcpy(bta_mce_cb.remote_addr, p_data->get_rmt_mas.bd_addr);

    SDP_InitDiscoveryDb (p_bta_mce_cfg->p_sdp_db, p_bta_mce_cfg->sdp_db_size, 1,
                                (tBT_UUID*) &bta_mce_mas_uuid, 0, NULL);

    if (!SDP_ServiceSearchAttributeRequest2(p_data->get_rmt_mas.bd_addr, p_bta_mce_cfg->p_sdp_db,
                                                bta_mce_search_cback, NULL))
    {
        bta_mce_cb.sdp_active = BTA_MCE_SDP_ACT_NONE;

        /* failed to start SDP. report the failure right away */
        if (bta_mce_cb.p_dm_cback)
            bta_mce_cb.p_dm_cback(BTA_MCE_MAS_DISCOVERY_COMP_EVT, (tBTA_MCE *)&status, NULL);
    }
    /*
    else report the result when the cback is called
    */
}
+112 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright (C) 2014 The Android Open Source Project
 *  Copyright (C) 2003-2012 Broadcom Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

/******************************************************************************
 *
 *  This is the implementation of the API for MCE subsystem
 *
 ******************************************************************************/

#include "bta_api.h"
#include "bd.h"
#include "bta_sys.h"
#include "bta_mce_api.h"
#include "bta_mce_int.h"
#include "gki.h"
#include <string.h>
#include "port_api.h"
#include "sdp_api.h"

/*****************************************************************************
**  Constants
*****************************************************************************/

static const tBTA_SYS_REG bta_mce_reg =
{
    bta_mce_sm_execute,
    NULL
};

/*******************************************************************************
**
** Function         BTA_MceEnable
**
** Description      Enable the MCE I/F service. When the enable
**                  operation is complete the callback function will be
**                  called with a BTA_MCE_ENABLE_EVT. This function must
**                  be called before other functions in the MCE API are
**                  called.
**
** Returns          BTA_MCE_SUCCESS if successful.
**                  BTA_MCE_FAIL if internal failure.
**
*******************************************************************************/
tBTA_MCE_STATUS BTA_MceEnable(tBTA_MCE_DM_CBACK *p_cback)
{
    tBTA_MCE_STATUS status = BTA_MCE_FAILURE;
    tBTA_MCE_API_ENABLE  *p_buf;

    APPL_TRACE_API(__FUNCTION__);
    if(p_cback && FALSE == bta_sys_is_register(BTA_ID_MCE))
    {
        memset(&bta_mce_cb, 0, sizeof(tBTA_MCE_CB));

        /* register with BTA system manager */
        bta_sys_register(BTA_ID_MCE, &bta_mce_reg);

        if (p_cback && (p_buf = (tBTA_MCE_API_ENABLE *) GKI_getbuf(sizeof(tBTA_MCE_API_ENABLE))) != NULL)
        {
            p_buf->hdr.event = BTA_MCE_API_ENABLE_EVT;
            p_buf->p_cback = p_cback;
            bta_sys_sendmsg(p_buf);
            status = BTA_MCE_SUCCESS;
        }
    }
    return(status);
}

/*******************************************************************************
**
** Function         BTA_MceGetRemoteMasInstances
**
** Description      This function performs service discovery for the MAS service
**                  by the given peer device. When the operation is completed
**                  the tBTA_MCE_DM_CBACK callback function will be  called with
**                  a BTA_MCE_MAS_DISCOVERY_COMP_EVT.
**
** Returns          BTA_MCE_SUCCESS, if the request is being processed.
**                  BTA_MCE_FAILURE, otherwise.
**
*******************************************************************************/
tBTA_MCE_STATUS BTA_MceGetRemoteMasInstances(BD_ADDR bd_addr)
{
    tBTA_MCE_STATUS ret = BTA_MCE_FAILURE;
    tBTA_MCE_API_GET_REMOTE_MAS_INSTANCES *p_msg;

    APPL_TRACE_API(__FUNCTION__);
    if ((p_msg = (tBTA_MCE_API_GET_REMOTE_MAS_INSTANCES *)GKI_getbuf(sizeof(tBTA_MCE_API_GET_REMOTE_MAS_INSTANCES))) != NULL)
    {
        p_msg->hdr.event = BTA_MCE_API_GET_REMOTE_MAS_INSTANCES_EVT;
        bdcpy(p_msg->bd_addr, bd_addr);
        bta_sys_sendmsg(p_msg);
        ret = BTA_MCE_SUCCESS;
    }

    return(ret);
}
Loading