OSDN Git Service

android: Add calls to hidhost interface to haltest
authorJerzy Kasenberg <jerzy.kasenberg@tieto.com>
Tue, 22 Oct 2013 11:02:26 +0000 (13:02 +0200)
committerJohan Hedberg <johan.hedberg@intel.com>
Tue, 22 Oct 2013 11:11:38 +0000 (14:11 +0300)
This patch adds code so hidhost interface can be tested.

Makefile.android
android/Android.mk
android/client/haltest.c
android/client/if-bt.c
android/client/if-hh.c [new file with mode: 0644]
android/client/if-main.h

index aebc715..720df69 100644 (file)
@@ -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 \
index 679c12b..c4b0621 100644 (file)
@@ -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
 
index 4864de1..2894565 100644 (file)
@@ -31,6 +31,7 @@
 
 const struct interface *interfaces[] = {
        &bluetooth_if,
+       &hh_if,
        NULL
 };
 
index f65e5f0..5f88a64 100644 (file)
@@ -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 (file)
index 0000000..09eaf9c
--- /dev/null
@@ -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 <stdio.h>
+#include <ctype.h>
+
+#include <hardware/bluetooth.h>
+#include <hardware/bt_hh.h>
+
+#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
+};
index 6d2b0cb..f8430cf 100644 (file)
@@ -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[];