Return-Path: From: Jerzy Kasenberg To: CC: Jerzy Kasenberg Subject: [PATCH 2/3] android: Add calls to hidhost interface to haltest Date: Tue, 22 Oct 2013 13:02:26 +0200 Message-ID: <1382439747-13864-3-git-send-email-jerzy.kasenberg@tieto.com> In-Reply-To: <1382439747-13864-1-git-send-email-jerzy.kasenberg@tieto.com> References: <1382439747-13864-1-git-send-email-jerzy.kasenberg@tieto.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-bluetooth-owner@vger.kernel.org List-ID: This patch adds code so hidhost interface can be tested. --- Makefile.android | 2 + android/Android.mk | 1 + android/client/haltest.c | 1 + android/client/if-bt.c | 2 +- android/client/if-hh.c | 365 ++++++++++++++++++++++++++++++++++++++++++++++ android/client/if-main.h | 2 + 6 files changed, 372 insertions(+), 1 deletion(-) create mode 100644 android/client/if-hh.c diff --git a/Makefile.android b/Makefile.android index aebc715..720df69 100644 --- a/Makefile.android +++ b/Makefile.android @@ -48,6 +48,7 @@ android_haltest_SOURCES = android/client/haltest.c \ android/client/textconv.c \ android/client/tabcompletion.c \ android/client/if-bt.c \ + android/client/if-hh.c \ android/client/hwmodule.c android_haltest_LDADD = android/libhal-internal.la @@ -73,6 +74,7 @@ EXTRA_DIST += android/client/terminal.c \ android/client/pollhandler.c \ android/client/history.c \ android/client/if-bt.c \ + android/client/if-hh.c \ android/client/textconv.c \ android/client/tabcompletion.c \ android/client/textconv.h \ diff --git a/android/Android.mk b/android/Android.mk index 679c12b..c4b0621 100644 --- a/android/Android.mk +++ b/android/Android.mk @@ -83,6 +83,7 @@ LOCAL_SRC_FILES := \ client/textconv.c \ client/tabcompletion.c \ client/if-bt.c \ + client/if-hh.c \ LOCAL_SHARED_LIBRARIES := libhardware diff --git a/android/client/haltest.c b/android/client/haltest.c index 4864de1..2894565 100644 --- a/android/client/haltest.c +++ b/android/client/haltest.c @@ -31,6 +31,7 @@ const struct interface *interfaces[] = { &bluetooth_if, + &hh_if, NULL }; diff --git a/android/client/if-bt.c b/android/client/if-bt.c index f65e5f0..5f88a64 100644 --- a/android/client/if-bt.c +++ b/android/client/if-bt.c @@ -805,7 +805,7 @@ static void get_profile_interface_p(int argc, const char **argv) else if (strcmp(BT_PROFILE_SOCKETS_ID, id) == 0) pif = &dummy; /* TODO: change when if_sock is there */ else if (strcmp(BT_PROFILE_HIDHOST_ID, id) == 0) - pif = &dummy; /* TODO: change when if_hh is there */ + pif = (const void **)&if_hh; else if (strcmp(BT_PROFILE_PAN_ID, id) == 0) pif = &dummy; /* TODO: change when if_pan is there */ else if (strcmp(BT_PROFILE_AV_RC_ID, id) == 0) diff --git a/android/client/if-hh.c b/android/client/if-hh.c new file mode 100644 index 0000000..09eaf9c --- /dev/null +++ b/android/client/if-hh.c @@ -0,0 +1,365 @@ +/* + * Copyright (C) 2013 Intel 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. + * + */ + +#include +#include + +#include +#include + +#include "if-main.h" +#include "pollhandler.h" + +const bthh_interface_t *if_hh = NULL; + +SINTMAP(bthh_protocol_mode_t, -1, "(unknown)") + DELEMENT(BTHH_REPORT_MODE), + DELEMENT(BTHH_BOOT_MODE), + DELEMENT(BTHH_UNSUPPORTED_MODE), +ENDMAP + +SINTMAP(bthh_report_type_t, -1, "(unknown)") + DELEMENT(BTHH_INPUT_REPORT), + DELEMENT(BTHH_OUTPUT_REPORT), + DELEMENT(BTHH_FEATURE_REPORT), +ENDMAP + +SINTMAP(bthh_connection_state_t, -1, "(unknown)") + DELEMENT(BTHH_CONN_STATE_CONNECTED), + DELEMENT(BTHH_CONN_STATE_CONNECTING), + DELEMENT(BTHH_CONN_STATE_DISCONNECTED), + DELEMENT(BTHH_CONN_STATE_DISCONNECTING), + DELEMENT(BTHH_CONN_STATE_FAILED_MOUSE_FROM_HOST), + DELEMENT(BTHH_CONN_STATE_FAILED_KBD_FROM_HOST), + DELEMENT(BTHH_CONN_STATE_FAILED_TOO_MANY_DEVICES), + DELEMENT(BTHH_CONN_STATE_FAILED_NO_BTHID_DRIVER), + DELEMENT(BTHH_CONN_STATE_FAILED_GENERIC), + DELEMENT(BTHH_CONN_STATE_UNKNOWN), +ENDMAP + +SINTMAP(bthh_status_t, -1, "(unknown)") + DELEMENT(BTHH_OK), + DELEMENT(BTHH_HS_HID_NOT_READY), + DELEMENT(BTHH_HS_INVALID_RPT_ID), + DELEMENT(BTHH_HS_TRANS_NOT_SPT), + DELEMENT(BTHH_HS_INVALID_PARAM), + DELEMENT(BTHH_HS_ERROR), + DELEMENT(BTHH_ERR), + DELEMENT(BTHH_ERR_SDP), + DELEMENT(BTHH_ERR_PROTO), + DELEMENT(BTHH_ERR_DB_FULL), + DELEMENT(BTHH_ERR_TOD_UNSPT), + DELEMENT(BTHH_ERR_NO_RES), + DELEMENT(BTHH_ERR_AUTH_FAILED), + DELEMENT(BTHH_ERR_HDL), +ENDMAP + +/* + * Callback for connection state change. + * state will have one of the values from bthh_connection_state_t + */ +static void connection_state_cb(bt_bdaddr_t *bd_addr, + bthh_connection_state_t state) +{ + char addr[MAX_ADDR_STR_LEN]; + + haltest_info("%s: bd_addr=%s connection_state=%s\n", __func__, + bt_bdaddr_t2str(bd_addr, addr), + bthh_connection_state_t2str(state)); +} + +/* + * Callback for virtual unplug api. + * the status of the virtual unplug + */ +static void virtual_unplug_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status) +{ + char addr[MAX_ADDR_STR_LEN]; + + haltest_info("%s: bd_addr=%s hh_status=%s\n", __func__, + bt_bdaddr_t2str(bd_addr, addr), + bthh_status_t2str(hh_status)); +} + +/* + * Callback for get hid info + * hid_info will contain attr_mask, sub_class, app_id, vendor_id, product_id, + * version, ctry_code, len + */ +static void hid_info_cb(bt_bdaddr_t *bd_addr, bthh_hid_info_t hid_info) +{ + char addr[MAX_ADDR_STR_LEN]; + + /* TODO: print actual hid_info */ + haltest_info("%s: bd_addr=%s\n", __func__, + bt_bdaddr_t2str(bd_addr, addr)); +} + +/* + * Callback for get/set protocol api. + * the protocol mode is one of the value from bthh_protocol_mode_t + */ +static void protocol_mode_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, + bthh_protocol_mode_t mode) +{ + char addr[MAX_ADDR_STR_LEN]; + + haltest_info("%s: bd_addr=%s hh_status=%s mode=%s\n", __func__, + bt_bdaddr_t2str(bd_addr, addr), + bthh_status_t2str(hh_status), + bthh_protocol_mode_t2str(mode)); +} + +/* + * Callback for get/set_idle_time api. + */ +static void idle_time_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, + int idle_rate) +{ + char addr[MAX_ADDR_STR_LEN]; + + haltest_info("%s: bd_addr=%s hh_status=%s idle_rate=%d\n", __func__, + bt_bdaddr_t2str(bd_addr, addr), + bthh_status_t2str(hh_status), idle_rate); +} + + +/* + * Callback for get report api. + * if status is ok rpt_data contains the report data + */ +static void get_report_cb(bt_bdaddr_t *bd_addr, bthh_status_t hh_status, + uint8_t *rpt_data, int rpt_size) +{ + char addr[MAX_ADDR_STR_LEN]; + + /* TODO: print actual report */ + haltest_info("%s: bd_addr=%s hh_status=%s rpt_size=%d\n", __func__, + bt_bdaddr_t2str(bd_addr, addr), + bthh_status_t2str(hh_status), rpt_size); +} + +static bthh_callbacks_t bthh_callbacks = { + .size = sizeof(bthh_callbacks), + .connection_state_cb = connection_state_cb, + .hid_info_cb = hid_info_cb, + .protocol_mode_cb = protocol_mode_cb, + .idle_time_cb = idle_time_cb, + .get_report_cb = get_report_cb, + .virtual_unplug_cb = virtual_unplug_cb +}; + +/* init */ + +static void init_p(int argc, const char **argv) +{ + RETURN_IF_NULL(if_hh); + + EXEC(if_hh->init, &bthh_callbacks); +} + +/* connect */ + +static void connect_p(int argc, const char **argv) +{ + bt_bdaddr_t addr; + + RETURN_IF_NULL(if_hh); + VERIFY_ADDR_ARG(2, &addr); + + EXEC(if_hh->connect, &addr); +} + +/* disconnect */ + +static void disconnect_p(int argc, const char **argv) +{ + bt_bdaddr_t addr; + + RETURN_IF_NULL(if_hh); + VERIFY_ADDR_ARG(2, &addr); + + EXEC(if_hh->disconnect, &addr); +} + +/* virtual_unplug */ + +static void virtual_unplug_p(int argc, const char **argv) +{ + bt_bdaddr_t addr; + + RETURN_IF_NULL(if_hh); + VERIFY_ADDR_ARG(2, &addr); + + EXEC(if_hh->virtual_unplug, &addr); +} + +/* set_info */ + +static void set_info_p(int argc, const char **argv) +{ + bt_bdaddr_t addr; + bthh_hid_info_t hid_info; + + RETURN_IF_NULL(if_hh); + VERIFY_ADDR_ARG(2, &addr); + /* TODO: not implemented yet */ + + EXEC(if_hh->set_info, &addr, hid_info); +} + +/* get_protocol */ + +static void get_protocol_p(int argc, const char **argv) +{ + bt_bdaddr_t addr; + bthh_protocol_mode_t protocolMode; + + RETURN_IF_NULL(if_hh); + VERIFY_ADDR_ARG(2, &addr); + + if (argc < 4) { + haltest_error("No protocol mode specified\n"); + return; + } + protocolMode = str2bthh_protocol_mode_t(argv[3]); + + EXEC(if_hh->get_protocol, &addr, protocolMode); +} + +/* set_protocol */ + +static void set_protocol_p(int argc, const char **argv) +{ + bt_bdaddr_t addr; + bthh_protocol_mode_t protocolMode; + + RETURN_IF_NULL(if_hh); + VERIFY_ADDR_ARG(2, &addr); + + if (argc < 4) { + haltest_error("No protocol mode specified\n"); + return; + } + protocolMode = str2bthh_protocol_mode_t(argv[3]); + + EXEC(if_hh->set_protocol, &addr, protocolMode); +} + +/* get_report */ + +static void get_report_p(int argc, const char **argv) +{ + bt_bdaddr_t addr; + bthh_report_type_t reportType; + uint8_t reportId; + int bufferSize; + + RETURN_IF_NULL(if_hh); + VERIFY_ADDR_ARG(2, &addr); + + if (argc < 4) { + haltest_error("No report type specified\n"); + return; + } + reportType = str2bthh_report_type_t(argv[3]); + + if (argc < 5) { + haltest_error("No reportId specified\n"); + return; + } + reportId = (uint8_t) atoi(argv[4]); + + if (argc < 6) { + haltest_error("No bufferSize specified\n"); + return; + } + bufferSize = atoi(argv[5]); + + EXEC(if_hh->get_report, &addr, reportType, reportId, bufferSize); +} + +/* set_report */ + +static void set_report_p(int argc, const char **argv) +{ + bt_bdaddr_t addr; + bthh_report_type_t reportType; + + RETURN_IF_NULL(if_hh); + VERIFY_ADDR_ARG(2, &addr); + + if (argc <= 3) { + haltest_error("No report type specified\n"); + return; + } + reportType = str2bthh_report_type_t(argv[3]); + + if (argc <= 4) { + haltest_error("No report specified\n"); + return; + } + + EXEC(if_hh->set_report, &addr, reportType, (char *) argv[4]); +} + +/* send_data */ + +static void send_data_p(int argc, const char **argv) +{ + bt_bdaddr_t addr; + + RETURN_IF_NULL(if_hh); + VERIFY_ADDR_ARG(2, &addr); + + if (argc <= 3) { + haltest_error("No data to send specified\n"); + return; + } + + EXEC(if_hh->send_data, &addr, (char *) argv[3]); +} + +/* cleanup */ + +static void cleanup_p(int argc, const char **argv) +{ + RETURN_IF_NULL(if_hh); + + EXECV(if_hh->cleanup); +} + +/* Methods available in bthh_interface_t */ +static struct method methods[] = { + STD_METHOD(init), + STD_METHOD(connect), + STD_METHOD(disconnect), + STD_METHOD(virtual_unplug), + STD_METHOD(set_info), + STD_METHOD(get_protocol), + STD_METHOD(set_protocol), + STD_METHOD(get_report), + STD_METHOD(set_report), + STD_METHOD(send_data), + STD_METHOD(cleanup), + END_METHOD +}; + +const struct interface hh_if = { + .name = "hidhost", + .methods = methods +}; diff --git a/android/client/if-main.h b/android/client/if-main.h index 6d2b0cb..f8430cf 100644 --- a/android/client/if-main.h +++ b/android/client/if-main.h @@ -41,6 +41,7 @@ /* Interfaces from hal that can be populated during application lifetime */ extern const bt_interface_t *if_bluetooth; +extern const bthh_interface_t *if_hh; /* * Structure defines top level interfaces that can be used in test tool @@ -52,6 +53,7 @@ struct interface { }; extern const struct interface bluetooth_if; +extern const struct interface hh_if; /* Interfaces that will show up in tool (first part of command line) */ extern const struct interface *interfaces[]; -- 1.7.9.5