summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSrinu Jella <sjella@codeaurora.org>2015-05-29 18:57:56 +0530
committerLinux Build Service Account <lnxbuild@localhost>2015-10-06 03:21:48 -0600
commit222865ee3d43beae7a2928c19ca77b6ab22089d6 (patch)
tree7b688595036e2745e7dd20f0d3c9a718d8ee3cac
parent8884317d8e0eb1f9de1f69115aeff9b22c60ebe2 (diff)
downloadandroid_system_bt-222865ee3d43beae7a2928c19ca77b6ab22089d6.tar.gz
android_system_bt-222865ee3d43beae7a2928c19ca77b6ab22089d6.tar.bz2
android_system_bt-222865ee3d43beae7a2928c19ca77b6ab22089d6.zip
Mcap test tool for mcap protocol certification.
- Interface provided from BT-If layer to interact with mcap - This tool covers all mcap PTS test cases. Change-Id: I07f1eb8dc3d98c95b82ee67554c1a846e71c4bfc
-rw-r--r--btif/src/bluetooth.c3
-rw-r--r--btif/src/btif_mcap.c221
-rw-r--r--include/bt_testapp.h32
-rw-r--r--main/Android.mk3
-rw-r--r--test/mcap_tool/Android.mk39
-rw-r--r--test/mcap_tool/mcap_tool.c552
6 files changed, 698 insertions, 152 deletions
diff --git a/btif/src/bluetooth.c b/btif/src/bluetooth.c
index a6b676b45..2ba295685 100644
--- a/btif/src/bluetooth.c
+++ b/btif/src/bluetooth.c
@@ -122,6 +122,7 @@ extern btsdp_interface_t *btif_sdp_get_interface();
#if TEST_APP_INTERFACE == TRUE
extern const btrfcomm_interface_t *btif_rfcomm_get_interface(void);
+extern const btmcap_interface_t *btif_mcap_get_interface(void);
#endif
/************************************************************************************
@@ -404,6 +405,8 @@ static const void* get_testapp_interface(int test_app_profile)
switch(test_app_profile) {
case TEST_APP_RFCOMM:
return btif_rfcomm_get_interface();
+ case TEST_APP_MCAP:
+ return btif_mcap_get_interface();
default:
return NULL;
}
diff --git a/btif/src/btif_mcap.c b/btif/src/btif_mcap.c
new file mode 100644
index 000000000..343439f2f
--- /dev/null
+++ b/btif/src/btif_mcap.c
@@ -0,0 +1,221 @@
+/*
+ *Copyright (c) 2015, The Linux Foundation. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the followin conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the followin disclaimer.
+ * * Redistributions in binary form must reproduce the above copyriht
+ * notice, this list of conditions and the followin disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of The Linux Foundation nor
+ * the names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <hardware/bluetooth.h>
+
+
+#define LOG_NDDEBUG 0
+#define LOG_TAG "bluedroid"
+
+#include "gki.h"
+#include "btif_api.h"
+#include "bt_utils.h"
+#include "bt_testapp.h"
+#include "btm_api.h"
+#include "btu.h"
+#include "btm_api.h"
+#include "mca_api.h"
+
+#ifdef TEST_APP_INTERFACE
+
+static void McaInit(void)
+{
+ MCA_Init();
+}
+
+static tMCA_HANDLE McaRegister(tMCA_REG *p_reg, tMCA_CTRL_CBACK *p_cback)
+{
+ tMCA_HANDLE Ret = 0;
+ BTM_SetConnectability (1, 0, 0);
+ Ret = MCA_Register(p_reg, p_cback);
+ ALOGI("McaRegister");
+ return Ret;
+}
+
+static void Mca_Deregister(tMCA_HANDLE handle)
+{
+ MCA_Deregister(handle);
+ ALOGI("McaRegister");
+}
+
+static tMCA_RESULT Mca_CreateDep(tMCA_HANDLE handle, tMCA_DEP *p_dep, tMCA_CS *p_cs)
+{
+ tMCA_RESULT Ret = 0;
+ ALOGI("Mca_CreateDep Enter");
+ Ret = MCA_CreateDep(handle, p_dep, p_cs);
+ ALOGI("Mca_CreateDep Exit");
+ return Ret;
+}
+
+static tMCA_RESULT Mca_DeleteDep(tMCA_HANDLE handle, tMCA_DEP dep)
+{
+ tMCA_RESULT Ret = 0;
+ Ret = MCA_DeleteDep(handle, dep);
+ ALOGI("MCA_DeleteDep Exit");
+ return Ret;
+}
+
+
+static tMCA_RESULT Mca_ConnectReq(tMCA_HANDLE handle, BD_ADDR bd_addr, UINT16 ctrl_psm, UINT16 sec_mask)
+{
+ tMCA_RESULT Ret = 0;
+ Ret = MCA_ConnectReq(handle, bd_addr, ctrl_psm, sec_mask);
+ ALOGI("MCA_ConnectReq");
+ return Ret;
+}
+
+static tMCA_RESULT Mca_DisconnectReq(tMCA_CL mcl)
+{
+ tMCA_RESULT Ret = 0;
+ Ret = MCA_DisconnectReq(mcl);
+ ALOGI("Mca_DisconnectReq");
+ return Ret;
+}
+
+
+static tMCA_RESULT Mca_CreateMdl(tMCA_CL mcl, tMCA_DEP dep, UINT16 data_psm,
+ UINT16 mdl_id, UINT8 peer_dep_id,
+ UINT8 cfg, const tMCA_CHNL_CFG *p_chnl_cfg)
+{
+ tMCA_RESULT Ret = 0;
+ Ret = MCA_CreateMdl(mcl, dep, data_psm, mdl_id, peer_dep_id, cfg, p_chnl_cfg);
+ ALOGI("MCA_CreateMdl");
+ return Ret;
+}
+
+
+static tMCA_RESULT Mca_CreateMdlRsp(tMCA_CL mcl, tMCA_DEP dep, UINT16 mdl_id, UINT8 cfg, UINT8 rsp_code, const tMCA_CHNL_CFG *p_chnl_cfg)
+{
+ tMCA_RESULT Ret = 0;
+ Ret = MCA_CreateMdlRsp(mcl, dep, mdl_id, cfg, rsp_code, p_chnl_cfg);
+ ALOGI("Mca_CreateMdlRsp");
+ return Ret;
+}
+
+
+static tMCA_RESULT Mca_CloseReq(tMCA_DL mdl)
+{
+ tMCA_RESULT Ret = 0;
+ Ret = MCA_CloseReq(mdl);
+ ALOGI("Mca_CloseReq");
+ return Ret;
+}
+
+static tMCA_RESULT Mca_ReconnectMdl(tMCA_CL mcl, tMCA_DEP dep, UINT16 data_psm, UINT16 mdl_id, const tMCA_CHNL_CFG *p_chnl_cfg)
+{
+ tMCA_RESULT Ret = 0;
+ Ret = MCA_ReconnectMdl(mcl, dep, data_psm, mdl_id, p_chnl_cfg);
+ ALOGI("Mca_ReconnectMdl");
+ return Ret;
+}
+
+static tMCA_RESULT Mca_ReconnectMdlRsp(tMCA_CL mcl, tMCA_DEP dep, UINT16 mdl_id, UINT8 rsp_code, const tMCA_CHNL_CFG *p_chnl_cfg)
+{
+ tMCA_RESULT Ret = 0;
+ Ret = MCA_ReconnectMdlRsp(mcl, dep, mdl_id, rsp_code, p_chnl_cfg);
+ ALOGI("Mca_ReconnectMdl");
+ return Ret;
+}
+
+static tMCA_RESULT Mca_DataChnlCfg(tMCA_CL mcl, const tMCA_CHNL_CFG *p_chnl_cfg)
+{
+ tMCA_RESULT Ret = 0;
+ Ret = MCA_DataChnlCfg(mcl, p_chnl_cfg);
+ ALOGI("Mca_DataChnlCfg");
+ return Ret;
+}
+
+static tMCA_RESULT Mca_Abort(tMCA_CL mcl)
+{
+ tMCA_RESULT Ret = 0;
+ Ret = MCA_Abort(mcl);
+ ALOGI("MCA_Abort");
+ return Ret;
+}
+
+
+static tMCA_RESULT Mca_Delete(tMCA_CL mcl, UINT16 mdl_id)
+{
+ tMCA_RESULT Ret = 0;
+ Ret = MCA_Delete(mcl, mdl_id);
+ ALOGI("Mca_Delete");
+ return Ret;
+}
+
+static tMCA_RESULT Mca_WriteReq(tMCA_DL mdl, BT_HDR *p_pkt)
+{
+ tMCA_RESULT Ret = 0;
+ Ret = MCA_WriteReq(mdl, p_pkt);
+ ALOGI("Mca_Delete");
+ return Ret;
+}
+
+static UINT16 Mca_GetL2CapChannel (tMCA_DL mdl)
+{
+ UINT16 Ret = 0;
+ Ret = MCA_GetL2CapChannel(mdl);
+ ALOGI("Mca_GetL2CapChannel");
+ return Ret;
+}
+
+static const btmcap_interface_t btmcaInterface = {
+ sizeof(btmcap_interface_t),
+ McaInit,
+ McaRegister,
+ Mca_Deregister,
+ Mca_CreateDep,
+ Mca_DeleteDep,
+ Mca_ConnectReq,
+ Mca_DisconnectReq,
+ Mca_CreateMdl,
+ Mca_CreateMdlRsp,
+ Mca_CloseReq,
+ Mca_ReconnectMdl,
+ Mca_ReconnectMdlRsp,
+ Mca_DataChnlCfg,
+ Mca_Abort,
+ Mca_Delete,
+ Mca_WriteReq,
+ Mca_GetL2CapChannel
+};
+
+
+const btmcap_interface_t *btif_mcap_get_interface(void)
+{
+ //BTIF_TRACE_EVENT1("%s", __FUNCTION__);
+ //printf("\n%s\n", __FUNCTION__);
+ return &btmcaInterface;
+}
+
+
+#endif
diff --git a/include/bt_testapp.h b/include/bt_testapp.h
index 3dee39e59..dde597488 100644
--- a/include/bt_testapp.h
+++ b/include/bt_testapp.h
@@ -76,8 +76,40 @@ typedef enum {
}profileName;
typedef enum {
TEST_APP_RFCOMM,
+ TEST_APP_MCAP
} test_app_profile;
+typedef struct
+{
+ size_t size;
+ void (*Init)(void);
+ tMCA_HANDLE (*Register)(tMCA_REG *p_reg, tMCA_CTRL_CBACK *p_cback);
+ void (*Deregister)(tMCA_HANDLE handle);
+ tMCA_RESULT (*CreateDep)(tMCA_HANDLE handle, tMCA_DEP *p_dep, tMCA_CS *p_cs);
+ tMCA_RESULT (*DeleteDep)(tMCA_HANDLE handle, tMCA_DEP dep);
+ tMCA_RESULT (*ConnectReq)(tMCA_HANDLE handle, BD_ADDR bd_addr,
+ UINT16 ctrl_psm,
+ UINT16 sec_mask);
+ tMCA_RESULT (*DisconnectReq)(tMCA_CL mcl);
+ tMCA_RESULT (*CreateMdl)(tMCA_CL mcl, tMCA_DEP dep, UINT16 data_psm,
+ UINT16 mdl_id, UINT8 peer_dep_id,
+ UINT8 cfg, const tMCA_CHNL_CFG *p_chnl_cfg);
+ tMCA_RESULT (*CreateMdlRsp)(tMCA_CL mcl, tMCA_DEP dep,
+ UINT16 mdl_id, UINT8 cfg, UINT8 rsp_code,
+ const tMCA_CHNL_CFG *p_chnl_cfg);
+ tMCA_RESULT (*CloseReq)(tMCA_DL mdl);
+ tMCA_RESULT (*ReconnectMdl)(tMCA_CL mcl, tMCA_DEP dep, UINT16 data_psm,
+ UINT16 mdl_id, const tMCA_CHNL_CFG *p_chnl_cfg);
+ tMCA_RESULT (*ReconnectMdlRsp)(tMCA_CL mcl, tMCA_DEP dep,
+ UINT16 mdl_id, UINT8 rsp_code,
+ const tMCA_CHNL_CFG *p_chnl_cfg);
+ tMCA_RESULT (*DataChnlCfg)(tMCA_CL mcl, const tMCA_CHNL_CFG *p_chnl_cfg);
+ tMCA_RESULT (*Abort)(tMCA_CL mcl);
+ tMCA_RESULT (*Delete)(tMCA_CL mcl, UINT16 mdl_id);
+ tMCA_RESULT (*WriteReq)(tMCA_DL mdl, BT_HDR *p_pkt);
+ UINT16 (*GetL2CapChannel) (tMCA_DL mdl);
+}btmcap_interface_t;
+
/** Bluetooth RFC tool commands */
typedef enum {
RFC_TEST_CLIENT =1,
diff --git a/main/Android.mk b/main/Android.mk
index bbbb351d5..8e227d444 100644
--- a/main/Android.mk
+++ b/main/Android.mk
@@ -56,7 +56,8 @@ LOCAL_SRC_FILES += \
../btif/src/btif_storage.c \
../btif/src/btif_util.c \
../btif/src/stack_manager.c \
- ../btif/src/btif_rfcomm.c
+ ../btif/src/btif_rfcomm.c \
+ ../btif/src/btif_mcap.c
ifeq ($(BOARD_USES_WIPOWER), true)
LOCAL_SRC_FILES += \
diff --git a/test/mcap_tool/Android.mk b/test/mcap_tool/Android.mk
new file mode 100644
index 000000000..f0da81f9c
--- /dev/null
+++ b/test/mcap_tool/Android.mk
@@ -0,0 +1,39 @@
+#
+#
+
+LOCAL_PATH:= $(call my-dir)
+
+include $(CLEAR_VARS)
+
+
+LOCAL_SRC_FILES:= mcap_tool.c
+
+LOCAL_C_INCLUDES += . \
+ $(LOCAL_PATH)/../../stack/include \
+ $(LOCAL_PATH)/../../include \
+ $(LOCAL_PATH)/../../stack/l2cap \
+ $(LOCAL_PATH)/../../gki/ulinux \
+ $(LOCAL_PATH)/../../gki/common \
+ $(LOCAL_PATH)/../../utils/include \
+ $(LOCAL_PATH)/btif/include \
+ $(bdroid_C_INCLUDES)
+
+LOCAL_CFLAGS += $(bdroid_CFLAGS)
+LOCAL_MODULE_PATH := $(TARGET_OUT_EXECUTABLES)
+LOCAL_MODULE_TAGS := debug optional
+
+LOCAL_MODULE:= mcap_tool
+
+
+LOCAL_SHARED_LIBRARIES += libcutils \
+ libutils \
+ libhardware \
+ libhardware_legacy
+
+
+
+
+LOCAL_MULTILIB := 32
+
+
+include $(BUILD_EXECUTABLE)
diff --git a/test/mcap_tool/mcap_tool.c b/test/mcap_tool/mcap_tool.c
index 38a289e00..80d6de71c 100644
--- a/test/mcap_tool/mcap_tool.c
+++ b/test/mcap_tool/mcap_tool.c
@@ -1,5 +1,9 @@
/******************************************************************************
*
+ * Copyright (C) 2015, The linux Foundation. All rights reserved.
+ *
+ * Not a Contribution.
+ *
* Copyright (C) 2009-2012 Broadcom Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,9 +22,9 @@
/************************************************************************************
*
- * Filename: bluedroidtest.c
+ * Filename: mcap_tool.c
*
- * Description: Bluedroid Test application
+ * Description: Bluedroid MCAP TOOL application
*
***********************************************************************************/
@@ -35,6 +39,7 @@
#include <fcntl.h>
#include <sys/prctl.h>
#include <sys/capability.h>
+#include "l2c_api.h"
#include <arpa/inet.h>
#include <netinet/in.h>
@@ -45,25 +50,32 @@
#include <hardware/hardware.h>
#include <hardware/bluetooth.h>
+#include "bt_testapp.h"
+#include "mca_defs.h"
+#include "mca_api.h"
+
/************************************************************************************
** Constants & Macros
************************************************************************************/
+//#define TRUE 1
+//#define FALSE 0
#define PID_FILE "/data/.bdt_pid"
-#define DEVICE_DISCOVERY_TIMEOUT 20
#ifndef MAX
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#endif
#define CASE_RETURN_STR(const) case const: return #const;
-
-#define UNUSED __attribute__((unused))
+#define TRANSPORT_BREDR 1 //Add tranport parameter to create bond
/************************************************************************************
** Local type definitions
************************************************************************************/
+static void register_client_cb(int status, int client_if, bt_uuid_t *app_uuid);
+static void scan_result_cb(bt_bdaddr_t* remote_bd_addr, int rssi, uint8_t* adv_data);
+
/************************************************************************************
** Static variables
@@ -83,10 +95,54 @@ static gid_t groups[] = { AID_NET_BT, AID_INET, AID_NET_BT_ADMIN,
/* Set to 1 when the Bluedroid stack is enabled */
static unsigned char bt_enabled = 0;
-static int deviceCount;
-static int wantMore = 0;
-pthread_mutex_t deviceCount_mutex;
-pthread_cond_t deviceCount_cond;
+
+
+
+
+enum {
+ DISCONNECT,
+ CONNECTING,
+ CONNECTED,
+ DISCONNECTING
+};
+static int g_ConnectionState = DISCONNECT;
+static int g_AdapterState = BT_STATE_OFF;
+static int g_PairState = BT_BOND_STATE_NONE;
+
+btmcap_interface_t *sMcapIface = NULL;
+tMCA_HANDLE g_Mcap_Handle = 0;
+tMCA_DEP g_Mcap_Dep = 0;
+tL2CAP_FCR_OPTS g_fcr_opts = {
+ L2CAP_FCR_ERTM_MODE,
+ MCA_FCR_OPT_TX_WINDOW_SIZE, /* Tx window size */
+ MCA_FCR_OPT_MAX_TX_B4_DISCNT, /* Maximum transmissions before disconnecting */
+ MCA_FCR_OPT_RETX_TOUT, /* Retransmission timeout (2 secs) */
+ MCA_FCR_OPT_MONITOR_TOUT, /* Monitor timeout (12 secs) */
+ MCA_FCR_OPT_MPS_SIZE /* MPS segment size */
+};
+
+tMCA_CHNL_CFG g_chnl_cfg = {
+ {
+ L2CAP_FCR_ERTM_MODE,
+ MCA_FCR_OPT_TX_WINDOW_SIZE, /* Tx window size */
+ MCA_FCR_OPT_MAX_TX_B4_DISCNT, /* Maximum transmissions before disconnecting */
+ MCA_FCR_OPT_RETX_TOUT, /* Retransmission timeout (2 secs) */
+ MCA_FCR_OPT_MONITOR_TOUT, /* Monitor timeout (12 secs) */
+ MCA_FCR_OPT_MPS_SIZE /* MPS segment size */
+ },
+ HCI_ACL_POOL_ID,
+ HCI_ACL_POOL_ID,
+ L2CAP_FCR_RX_POOL_ID,
+ L2CAP_FCR_TX_POOL_ID,
+ MCA_FCS_NONE,
+ 572
+};
+
+UINT16 g_Peer_Mtu = 0;
+UINT16 g_Mdl_Id = 0;
+tMCA_DL g_Mdl = 0;
+tMCA_CL g_Mcl = 0;
+
/************************************************************************************
** Static functions
@@ -95,16 +151,83 @@ pthread_cond_t deviceCount_cond;
static void process_cmd(char *p, unsigned char is_job);
static void job_handler(void *param);
static void bdt_log(const char *fmt_str, ...);
-static void discover_device(void *arg);
+int GetBdAddr(char *p, bt_bdaddr_t *pbd_addr);
+
+static int str2bd(char *str, bt_bdaddr_t *addr)
+{
+ int32_t i = 0;
+
+ for (i = 0; i < 6; i++)
+ {
+ addr->address[i] = (uint8_t) strtoul(str, (char **)&str, 16);
+ str++;
+ }
+ return 0;
+}
/************************************************************************************
** Externs
************************************************************************************/
/************************************************************************************
-** Functions
+** MCAP Callbacks
************************************************************************************/
+static void mcap_ctrl_cb(tMCA_HANDLE handle, tMCA_CL mcl, UINT8 event, tMCA_CTRL *p_data)
+{
+ tMCA_RESULT Ret;
+ //printf("%s:: handle=%d, mcl=%d, event=0x%x, g_Mdl=%d, g_Mdl_Id=%d \n", __FUNCTION__, handle, mcl, event, g_Mdl, g_Mdl_Id);
+ switch(event)
+ {
+ case MCA_CREATE_IND_EVT:
+ //printf("%s::Create_ind::Mdl_Id=%d, OpCode=%d, dep_id=%d, cfg=%d \n", __FUNCTION__, p_data->create_ind.mdl_id,
+ //p_data->create_ind.op_code, p_data->create_ind.dep_id, p_data->create_ind.cfg);
+ g_Mdl = p_data->create_ind.mdl_id;
+ Ret = sMcapIface->CreateMdlRsp(mcl, p_data->create_ind.dep_id,
+ g_Mdl, p_data->create_ind.cfg, MCA_SUCCESS, &g_chnl_cfg);
+ break;
+
+ case MCA_CONNECT_IND_EVT:
+ //printf("%s::Connect_Ind:: peer_mtu=%d \n", __FUNCTION__, p_data->connect_ind.mtu);
+ g_Mcl = mcl;
+ break;
+
+ case MCA_DISCONNECT_IND_EVT:
+ g_Mcl = 0;
+ break;
+
+ case MCA_OPEN_IND_EVT:
+ case MCA_OPEN_CFM_EVT:
+ g_Mdl_Id = p_data->open_ind.mdl_id;
+ g_Mdl = p_data->open_ind.mdl;
+ g_Peer_Mtu = p_data->open_ind.mtu;
+ break;
+
+ case MCA_RECONNECT_IND_EVT:
+ //printf("%s::Reconnect Ind:: Mdl_Id=%d, g_Mdl_Id=%d\n", __FUNCTION__, p_data->reconnect_ind.mdl_id, g_Mdl_Id);
+ Ret = sMcapIface->ReconnectMdlRsp(mcl, g_Mcap_Dep, p_data->reconnect_ind.mdl_id, (g_Mdl_Id==p_data->reconnect_ind.mdl_id) ?MCA_RSP_SUCCESS :MCA_RSP_BAD_MDL, &g_chnl_cfg);
+ break;
+
+ case MCA_DELETE_IND_EVT:
+ //printf("%s::Delete Ind:: Mdl_Id=%d\n", __FUNCTION__, p_data->delete_ind.mdl_id);
+ if((0xffff==p_data->delete_ind.mdl_id)||(g_Mdl_Id == p_data->delete_ind.mdl_id)) g_Mdl_Id = 0;
+ break;
+
+ case MCA_SYNC_CAP_IND_EVT:
+ //printf("%s::Sync Cap Ind::\n", __FUNCTION__);
+ break;
+
+ case MCA_ABORT_IND_EVT:
+ //printf("%s::Abort_Ind::Mdl_Id=%d, opCode=%d \n", __FUNCTION__, p_data->abort_ind.mdl_id, p_data->abort_ind.op_code);
+ break;
+ }
+}
+
+static void mcap_data_cb(tMCA_DL mdl, BT_HDR *p_pkt)
+{
+ //printf("%s:: mdl=%d, event=%d, len=%d, offset=%d, layer_specific=%d\n", __FUNCTION__, mdl, p_pkt->event, p_pkt->len, p_pkt->offset, p_pkt->layer_specific);
+}
+
/************************************************************************************
@@ -207,7 +330,7 @@ static void hex_dump(char *msg, void *data, int size, int trunc)
if (n%16 == 1) {
/* store address for this line */
snprintf(addrstr, sizeof(addrstr), "%.4x",
- (unsigned int)((uintptr_t)p-(uintptr_t)data) );
+ ((unsigned int)p-(unsigned int)data) );
}
c = *p;
@@ -314,17 +437,18 @@ void get_str(char **p, char *Buffer)
*Buffer = 0;
}
-uint32_t get_hex(char **p, int DefaultValue)
+uint32_t get_hex_any(char **p, int DefaultValue, unsigned int NumOfNibble)
{
uint32_t Value = 0;
unsigned char UseDefault;
+ //unsigned char NumOfNibble = 8; //Since we are returning uint32, max allowed is 4 bytes(8 nibbles).
UseDefault = 1;
skip_blanks(p);
- while ( ((**p)<= '9' && (**p)>= '0') ||
+ while ((NumOfNibble) && (((**p)<= '9' && (**p)>= '0') ||
((**p)<= 'f' && (**p)>= 'a') ||
- ((**p)<= 'F' && (**p)>= 'A') )
+ ((**p)<= 'F' && (**p)>= 'A')) )
{
if (**p >= 'a')
Value = Value * 16 + (**p) - 'a' + 10;
@@ -334,6 +458,7 @@ uint32_t get_hex(char **p, int DefaultValue)
Value = Value * 16 + (**p) - '0';
UseDefault = 0;
(*p)++;
+ NumOfNibble--;
}
if (UseDefault)
@@ -341,6 +466,15 @@ uint32_t get_hex(char **p, int DefaultValue)
else
return Value;
}
+uint32_t get_hex(char **p, int DefaultValue)
+{
+ //unsigned char NumOfNibble = 8; //Since we are returning uint32, max allowed is 4 bytes(8 nibbles).
+ return (get_hex_any(p, DefaultValue, 8));
+}
+uint32_t get_hex_byte(char **p, int DefaultValue)
+{
+ return (get_hex_any(p, DefaultValue, 2));
+}
void get_bdaddr(const char *str, bt_bdaddr_t *bd) {
char *d = ((char *)bd), *endp;
@@ -390,18 +524,12 @@ static int create_cmdjob(char *cmd)
char *job_cmd;
job_cmd = malloc(strlen(cmd)+1); /* freed in job handler */
- if (job_cmd)
- {
- strcpy(job_cmd, cmd);
+ strlcpy(job_cmd, cmd, strlen(cmd)+1);
+
+ if (pthread_create(&thread_id, NULL,
+ (void*)cmdjob_handler, (void*)job_cmd)!=0)
+ perror("pthread_create");
- if (pthread_create(&thread_id, NULL,
- (void*)cmdjob_handler, (void*)job_cmd)!=0)
- perror("pthread_create");
- }
- else
- {
- perror("create_cmdjob(): Failed to allocate memory");
- }
return 0;
}
@@ -475,68 +603,119 @@ void check_return_status(bt_status_t status)
static void adapter_state_changed(bt_state_t state)
{
- bdt_log("ADAPTER STATE UPDATED : %s", (state == BT_STATE_OFF)?"OFF":"ON");
+ int V1 = 1000, V2=2;
+ bt_property_t property = {9 /*BT_PROPERTY_DISCOVERY_TIMEOUT*/, 4, &V1};
+ bt_property_t property1 = {7 /*SCAN*/, 2, &V2};
+ bt_property_t property2 ={1,6,"Bluedroid"};
+
+ g_AdapterState = state;
+
if (state == BT_STATE_ON) {
bt_enabled = 1;
- } else {
- bt_enabled = 0;
+ status = sBtInterface->set_adapter_property(&property1);
+ status = sBtInterface->set_adapter_property(&property);
+ status = sBtInterface->set_adapter_property(&property2);
+ }
+ else {
+ bt_enabled = 0;
}
}
-static void dut_mode_recv(uint16_t UNUSED opcode, uint8_t UNUSED *buf, uint8_t UNUSED len)
+static void adapter_properties_changed(bt_status_t status, int num_properties, bt_property_t *properties)
{
- bdt_log("DUT MODE RECV : NOT IMPLEMENTED");
+ char Bd_addr[15] = {0};
+ if(NULL == properties)
+ {
+ printf("properties is null\n");
+ return;
+ }
+ switch(properties->type)
+ {
+ case BT_PROPERTY_BDADDR:
+ memcpy(Bd_addr, properties->val, properties->len);
+ printf("Local Bd Addr = %02x:%02x:%02x:%02x:%02x:%02x\n", Bd_addr[0], Bd_addr[1], Bd_addr[2], Bd_addr[3], Bd_addr[4], Bd_addr[5]);
+ break;
+ default :
+ break;
+ }
+ return;
}
-static void le_test_mode(bt_status_t status, uint16_t packet_count)
+static void discovery_state_changed(bt_discovery_state_t state)
{
- bdt_log("LE TEST MODE END status:%s number_of_packets:%d", dump_bt_status(status), packet_count);
+ printf("Discovery State Updated : %s\n", (state == BT_DISCOVERY_STOPPED)?"STOPPED":"STARTED");
}
-static void device_found_cb(int num_properties, bt_property_t *properties)
+
+static void pin_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name, uint32_t cod, uint8_t secure)
{
- int i;
- for (i = 0; i < num_properties; i++)
+ int ret = 0;
+ bt_pin_code_t pincode = {{ 0x31, 0x32, 0x33, 0x34}};
+ printf("%s:: %s, Pin=1234, cod=0x%x, secure=%d\n", __FUNCTION__, bd_name->name, cod, secure);
+
+ if(BT_STATUS_SUCCESS != sBtInterface->pin_reply(remote_bd_addr, TRUE, 4, &pincode))
{
- if (properties[i].type == BT_PROPERTY_BDNAME)
- {
- pthread_mutex_lock(&deviceCount_mutex);
- deviceCount++;
- bdt_log("Device name is : %s\n",
- (char*)properties[i].val);
- if (deviceCount > 0 && wantMore == 0)
- {
- pthread_cond_signal(&deviceCount_cond);
- }
- pthread_mutex_unlock(&deviceCount_mutex);
- }
+ printf("Pin Reply failed\n");
+ }
+}
+
+static void ssp_request_cb(bt_bdaddr_t *remote_bd_addr, bt_bdname_t *bd_name,
+ uint32_t cod, bt_ssp_variant_t pairing_variant, uint32_t pass_key)
+{
+ printf("ssp_request_cb : %s %d %u\n", bd_name->name, pairing_variant, pass_key);
+ if(BT_STATUS_SUCCESS != sBtInterface->ssp_reply(remote_bd_addr, pairing_variant, TRUE, pass_key))
+ {
+ printf("SSP Reply failed\n");
}
}
+static void bond_state_changed_cb(bt_status_t status, bt_bdaddr_t *remote_bd_addr, bt_bond_state_t state)
+{
+ printf("Bond State Changed = %d\n", state);
+ g_PairState = state;
+}
+
+static void acl_state_changed(bt_status_t status, bt_bdaddr_t *remote_bd_addr, bt_acl_state_t state)
+{
+ printf("acl_state_changed : remote_bd_addr=%02x:%02x:%02x:%02x:%02x:%02x, acl status=%s \n",
+ remote_bd_addr->address[0], remote_bd_addr->address[1], remote_bd_addr->address[2],
+ remote_bd_addr->address[3], remote_bd_addr->address[4], remote_bd_addr->address[5],
+ (state == BT_ACL_STATE_CONNECTED)?"ACL Connected" :"ACL Disconnected"
+ );
+}
+
+
+static void dut_mode_recv(uint16_t opcode, uint8_t *buf, uint8_t len)
+{
+ bdt_log("DUT MODE RECV : NOT IMPLEMENTED");
+}
+
+static void le_test_mode(bt_status_t status, uint16_t packet_count)
+{
+ bdt_log("LE TEST MODE END status:%s number_of_packets:%d", dump_bt_status(status), packet_count);
+}
+
static bt_callbacks_t bt_callbacks = {
sizeof(bt_callbacks_t),
adapter_state_changed,
- NULL, /* adapter_properties_cb */
+ adapter_properties_changed, /*adapter_properties_cb */
NULL, /* remote_device_properties_cb */
- device_found_cb, /* device_found_cb */
- NULL, /* discovery_state_changed_cb */
- NULL, /* pin_request_cb */
- NULL, /* ssp_request_cb */
- NULL, /* bond_state_changed_cb */
- NULL, /* acl_state_changed_cb */
+ NULL, /* device_found_cb */
+ discovery_state_changed, /* discovery_state_changed_cb */
+ pin_request_cb, /* pin_request_cb */
+ ssp_request_cb, /* ssp_request_cb */
+ bond_state_changed_cb, /*bond_state_changed_cb */
+ acl_state_changed, /* acl_state_changed_cb */
NULL, /* thread_evt_cb */
- dut_mode_recv, /* dut_mode_recv_cb */
+ dut_mode_recv, /*dut_mode_recv_cb */
+
+ // NULL, /*authorize_request_cb */
#if BLE_INCLUDED == TRUE
le_test_mode, /* le_test_mode_cb */
#else
- NULL, /* le_test_mode_cb */
+ NULL,
#endif
- NULL, /* energy_info_cb */
- NULL, /*le_lpp_write_rssi_thresh_cb*/
- NULL, /*le_lpp_read_rssi_thresh_cb*/
- NULL, /*le_lpp_enable_rssi_monitor_cb*/
- NULL, /*le_lpp_rssi_threshold_evt_cb*/
- NULL /* hci_event_recv_cb */
+ NULL
};
static bool set_wake_alarm(uint64_t delay_millis, bool should_wake, alarm_cb cb, void *data) {
@@ -582,11 +761,9 @@ void bdt_init(void)
{
bdt_log("INIT BT ");
status = sBtInterface->init(&bt_callbacks);
-
- if (status == BT_STATUS_SUCCESS) {
+ if (status == BT_STATUS_SUCCESS) {
status = sBtInterface->set_os_callouts(&callouts);
}
-
check_return_status(status);
}
@@ -694,7 +871,7 @@ void bdt_cleanup(void)
** Console commands
*******************************************************************************/
-void do_help(char UNUSED *p)
+void do_help(char *p)
{
int i = 0;
int max = 0;
@@ -709,7 +886,7 @@ void do_help(char UNUSED *p)
}
}
-void do_quit(char UNUSED *p)
+void do_quit(char *p)
{
bdt_shutdown();
}
@@ -722,33 +899,119 @@ void do_quit(char UNUSED *p)
*
*/
-void do_init(char UNUSED *p)
+void do_init(char *p)
{
bdt_init();
}
-void do_enable(char UNUSED *p)
+void do_enable(char *p)
{
bdt_enable();
}
-void do_disable(char UNUSED *p)
+void do_disable(char *p)
{
bdt_disable();
}
-void do_dut_mode_configure(char *p)
+
+void do_cleanup(char *p)
{
- bdt_dut_mode_configure(p);
+ bdt_cleanup();
}
-void do_le_test_mode(char *p)
+
+/*******************************************************************************
+ ** MCAP API commands
+ *******************************************************************************/
+void do_mcap_register(char *p)
{
- bdt_le_test_mode(p);
+ tMCA_REG Mca_Reg;
+ Mca_Reg.rsp_tout = 5000; //Need to check if we have to give in msec or seconds
+ Mca_Reg.ctrl_psm = get_hex(&p, -1); // arg1
+ Mca_Reg.data_psm = get_hex(&p, -1); // arg2
+ Mca_Reg.sec_mask = get_int(&p, -1); // arg3
+ g_Mcap_Handle = sMcapIface->Register(&Mca_Reg, mcap_ctrl_cb);
+ printf("%s:: Ret=%d \n", __FUNCTION__, g_Mcap_Handle);
}
-void do_cleanup(char UNUSED *p)
+void do_mcap_deregister(char *p)
{
- bdt_cleanup();
+ sMcapIface->Deregister(g_Mcap_Handle);
+ printf("%s:: Handle=%d \n", __FUNCTION__, g_Mcap_Handle);
+}
+
+void do_mcap_create_dep(char *p)
+{
+ tMCA_RESULT Ret = 0;
+ int type = 0;
+ tMCA_CS Mca_cs = {0};
+ type = get_int(&p, -1); // arg1
+ Mca_cs.type = (0 == type) ? MCA_TDEP_ECHO :MCA_TDEP_DATA;
+ Mca_cs.max_mdl = MCA_NUM_MDLS;
+ Mca_cs.p_data_cback = mcap_data_cb;
+
+ Ret = sMcapIface->CreateDep(g_Mcap_Handle, &g_Mcap_Dep, &Mca_cs);
+ printf("%s:: Ret=%d \n", __FUNCTION__, Ret);
+}
+
+static void do_mcap_delete_dep(char *p)
+{
+ tMCA_RESULT Ret = 0;
+ Ret = sMcapIface->DeleteDep(g_Mcap_Handle, g_Mcap_Dep);
+ printf("%s:: Ret=%d \n", __FUNCTION__, Ret);
+}
+
+static void do_mcap_connect(char *p)
+{
+ tMCA_RESULT Ret = 0;
+ bt_bdaddr_t bd_addr = {{0}};
+ UINT16 ctrl_psm = 0;
+ UINT16 sec_mask = 0;
+ char buf[64];
+
+ get_str(&p, buf);
+ str2bd(buf, &bd_addr);
+ ctrl_psm = get_hex(&p, -1);// arg2
+ sec_mask = get_int(&p, -1);// arg3
+ printf("ctrl_psm=%d, secMask=%d \n", ctrl_psm, sec_mask);
+ Ret = sMcapIface->ConnectReq(g_Mcap_Handle, bd_addr.address, ctrl_psm, sec_mask);
+ printf("%s:: Ret=%d \n", __FUNCTION__, Ret);
+}
+
+static void do_mcap_disconnect(char *p)
+{
+ tMCA_RESULT Ret = 0;
+ Ret = sMcapIface->DisconnectReq(g_Mcl);
+ printf("%s:: Ret=%d \n", __FUNCTION__, Ret);
+}
+
+static void do_mcap_create_mdl(char *p)
+{
+ tMCA_RESULT Ret = 0;
+ UINT16 data_psm = 0;
+ data_psm = get_hex(&p, -1); // arg1
+ Ret = sMcapIface->CreateMdl(g_Mcl, g_Mcap_Dep, data_psm, 1, 1, 1, &g_chnl_cfg);
+ printf("%s:: Ret=%d \n", __FUNCTION__, Ret);
+}
+
+static void do_mcap_close(char *p)
+{
+ tMCA_RESULT Ret = 0;
+ Ret = sMcapIface->CloseReq(g_Mdl);
+ printf("%s:: Ret=%d \n", __FUNCTION__, Ret);
+}
+
+static void do_pairing(char *p)
+{
+ bt_bdaddr_t bd_addr = {{0}};
+
+ if(FALSE == GetBdAddr(p, &bd_addr))
+ return; // arg1
+ if(BT_STATUS_SUCCESS != sBtInterface->create_bond(&bd_addr, TRANSPORT_BREDR))
+ {
+ printf("Failed to Initiate Pairing \n");
+ return;
+ }
}
/*******************************************************************
@@ -773,12 +1036,15 @@ const t_cmd console_cmd_list[] =
/* Init and Cleanup shall be called automatically */
{ "enable", do_enable, ":: enables bluetooth", 0 },
{ "disable", do_disable, ":: disables bluetooth", 0 },
- { "dut_mode_configure", do_dut_mode_configure, ":: DUT mode - 1 to enter,0 to exit", 0 },
- { "le_test_mode", do_le_test_mode, ":: LE Test Mode - RxTest - 1 <rx_freq>, \n\t \
- TxTest - 2 <tx_freq> <test_data_len> <payload_pattern>, \n\t \
- End Test - 3 <no_args>", 0 },
- /* add here */
-
+ { "pair", do_pairing, ":: BdAddr<00112233445566>", 0 },
+ { "register", do_mcap_register, "::Ctrl_Psm<hex>, Data_Psm<hex>, Security<0-10>", 0 },
+ { "deregister", do_mcap_deregister, "::", 0 },
+ { "create_data_endpoint", do_mcap_create_dep, "::Type<0-Echo, 1-NormalData>", 0 },
+ { "delete_data_endpoint", do_mcap_delete_dep, "::", 0 },
+ { "connect", do_mcap_connect, ":: BdAddr<00112233445566>, Ctrl_Psm<hex>, SecMask<int>", 0 },
+ { "disconnect", do_mcap_disconnect, ":: BdAddr<00112233445566>", 0 },
+ { "create_mdl", do_mcap_create_mdl, ":: Data_Psm<hex>", 0 },
+ { "close_data_channel", do_mcap_close, "::", 0 },
/* last entry */
{NULL, NULL, "", 0},
};
@@ -789,7 +1055,7 @@ const t_cmd console_cmd_list[] =
static void process_cmd(char *p, unsigned char is_job)
{
- char cmd[64];
+ char cmd[2048];
int i = 0;
char *p_saved = p;
@@ -814,37 +1080,12 @@ static void process_cmd(char *p, unsigned char is_job)
do_help(NULL);
}
-static void discover_device(void *arg)
-{
- struct timespec ts = {0, 0};
- ts.tv_sec = time(NULL) + DEVICE_DISCOVERY_TIMEOUT;
-
- sBtInterface->start_discovery();
- pthread_mutex_lock(&deviceCount_mutex);
- pthread_cond_timedwait(&deviceCount_cond, &deviceCount_mutex, &ts);
- if (deviceCount == 0)
- {
- bdt_log("No device found\n");
- }
- else
- {
- deviceCount = 0;
- }
- pthread_mutex_unlock(&deviceCount_mutex);
- wantMore = 0;
- bdt_log("Cancelling discovery\n");
- sBtInterface->cancel_discovery();
- pthread_exit(0);
-}
-
-int main (int UNUSED argc, char UNUSED *argv[])
+int main (int argc, char * argv[])
{
int opt;
- char cmd[128];
+ char cmd[2048];
int args_processed = 0;
int pid = -1;
- int enable_wait_count = 0;
- pthread_t discoveryThread;
config_permissions();
bdt_log("\n:::::::::::::::::::::::::::::::::::::::::::::::::::");
@@ -857,51 +1098,27 @@ int main (int UNUSED argc, char UNUSED *argv[])
}
setup_test_env();
- pthread_mutex_init(&deviceCount_mutex, NULL);
- pthread_cond_init (&deviceCount_cond, NULL);
/* Automatically perform the init */
bdt_init();
- if (argc > 1)
- {
- bdt_log("Command line mode\n");
- if (strncmp(argv[1],"get_ap_list",11) == 0) {
- wantMore = 1;
- } else if (strncmp(argv[1],"get_a_device",12) == 0) {
- wantMore = 0;
- } else {
- bdt_log("Unrecognised command");
- goto cleanup;
- }
- bdt_log("Enabling BT for 45 seconds\n");
- bdt_enable();
- do {
- if (bt_enabled)
- break;
- bdt_log("Waiting for bt_enabled to become true\n");
- sleep(2);
- } while(enable_wait_count++ < 10);
-
- if (bt_enabled) {
- pthread_create(&discoveryThread, NULL, (void*)discover_device, NULL);
- pthread_join(discoveryThread, NULL);
- } else {
- bdt_log("Failed to enable BT\n");
- goto cleanup;
- }
- bdt_log("Disabling BT\n");
- bdt_disable();
- goto cleanup;
- }
+ sleep(5);
+ bdt_enable();
+ sleep(5);
+
+ sMcapIface = (btmcap_interface_t *)sBtInterface->get_testapp_interface(TEST_APP_MCAP);
+ //sSmpIface = sBtInterface->get_testapp_interface(TEST_APP_SMP);
+ sleep(1);
+ sMcapIface->Init();
+
while(!main_done)
{
- char line[128];
+ char line[2048];
/* command prompt */
printf( ">" );
fflush(stdout);
- fgets (line, 128, stdin);
+ fgets (line, 2048, stdin);
if (line[0]!= '\0')
{
@@ -909,19 +1126,52 @@ int main (int UNUSED argc, char UNUSED *argv[])
line[strlen(line)-1] = 0;
process_cmd(line, 0);
- memset(line, '\0', 128);
+ memset(line, '\0', 2048);
}
}
/* FIXME: Commenting this out as for some reason, the application does not exit otherwise*/
//bdt_cleanup();
-cleanup:
- HAL_unload();
- pthread_mutex_destroy(&deviceCount_mutex);
- pthread_cond_destroy(&deviceCount_cond);
+ HAL_unload();
bdt_log(":: Bluedroid test app terminating");
return 0;
}
+
+
+int GetBdAddr(char *p, bt_bdaddr_t *pbd_addr)
+{
+ char Arr[13] = {0};
+ char *pszAddr = NULL;
+ UINT8 k1 = 0;
+ UINT8 k2 = 0;
+ int i;
+ char *t = NULL;
+
+ if(12 != strlen(p))
+ {
+ printf("\nInvalid Bd Address. Format[112233445566]\n");
+ return FALSE;
+ }
+ strlcpy(Arr, p, sizeof(Arr));
+ for(i=0; i<12; i++)
+ {
+ Arr[i] = tolower(Arr[i]);
+ }
+ pszAddr = &Arr[0];
+ for(i=0; i<6; i++)
+ {
+ k1 = (UINT8) ( (*pszAddr >= 'a') ? ( 10 + (UINT8)( *pszAddr - 'a' )) : (*pszAddr - '0') );
+ pszAddr++;
+ k2 = (UINT8) ( (*pszAddr >= 'a') ? ( 10 + (UINT8)( *pszAddr - 'a' )) : (*pszAddr - '0') );
+ pszAddr++;
+ if ( (k1>15)||(k2>15) )
+ {
+ return FALSE;
+ }
+ pbd_addr->address[i] = (k1<<4 | k2);
+ }
+ return TRUE;
+}