You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by GitBox <gi...@apache.org> on 2018/05/28 12:19:18 UTC

[GitHub] sjanc closed pull request #37: [RFC][WIP] ble service: HID service

sjanc closed pull request #37: [RFC][WIP] ble service: HID service
URL: https://github.com/apache/mynewt-nimble/pull/37
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/nimble/host/services/hid/include/services/hid/ble_svc_hid.h b/nimble/host/services/hid/include/services/hid/ble_svc_hid.h
new file mode 100644
index 00000000..f73ee987
--- /dev/null
+++ b/nimble/host/services/hid/include/services/hid/ble_svc_hid.h
@@ -0,0 +1,92 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+#ifndef H_BLE_SVC_HID_
+#define H_BLE_SVC_HID_
+
+
+
+/* 16 Bit Human Interface Device Service UUID */
+#define BLE_SVC_HID_UUID16                                 0x1812
+
+/* 16 Bit HID Service Characteristic UUIDs */
+#define BLE_SVC_HID_CHR_UUID16_PROTOCOL_MODE               0x2A4E
+#define BLE_SVC_HID_CHR_UUID16_REPORT                      0x2A4D
+#define BLE_SVC_HID_CHR_UUID16_REPORT_MAP                  0x2A4B
+#define BLE_SVC_HID_CHR_UUID16_BOOT_KEYBOARD_INPUT_REPORT  0x2A22
+#define BLE_SVC_HID_CHR_UUID16_BOOT_KEYBOARD_OUTPUT_REPORT 0x2A32
+#define BLE_SVC_HID_CHR_UUID16_BOOT_MOUSE_INPUT_REPORT     0x2A33
+#define BLE_SVC_HID_CHR_UUID16_HID_INFORMATION             0x2A4A
+#define BLE_SVC_HID_CHR_UUID16_HID_CONTROL_POINT           0x2A4C
+
+/* HID Service Protocol Mode enum
+ * The protocol mode of the HID Service
+ * Format: uint8
+ *   key="0" value="Boot Protocol Mode"
+ *   key="1" value="Report Protocol Mode"
+ *   key="2-255" ReservedForFutureUse
+ */
+
+typedef enum __attribute__((packed)) {
+    BLE_SVC_HID_PROTOCOL_MODE_BOOT,
+    BLE_SVC_HID_PROTOCOL_MODE_REPORT
+} ble_svc_hid_protocol_mode_value_t ;
+
+/* HID Service USB HID version
+ * Format: uint16
+ */
+#define USB_HID_VERSION_1_11    (0x0111)
+
+/* HID Service HID Information Flags
+ * Format: 8-bit BitField
+ * Note:The fields are in the order of LSO to MSO
+ *   index="0" size="1" name="RemoteWake"
+ *   index="1" size="1" name="NormallyConnectable"
+ *   index="2" size="6" ReservedForFutureUse
+ */
+#define BLE_SVC_HID_HID_INFO_FLAG_REMOTE_WAKE  0x01
+#define BLE_SVC_HID_HID_INFO_FLAG_NORMALLY_CONNECTABLE  0x02
+
+/* HID Service HID Information structure
+ * https://www.bluetooth.com/api/gatt/XmlFile?xmlFileName=org.bluetooth.characteristic.hid_information.xml
+ */
+typedef struct __attribute__((packed)) {
+    uint16_t hidver;
+    uint8_t countrycode;
+    uint8_t flags;
+} ble_svc_hid_hid_information_t;
+
+/* HID Service HID Control Point Command enum
+ * The HID Control Point characteristic is a control-point attribute that defines the following HID Commands when written: 
+ * Format: uint8
+ *   key="0" value="Suspend"
+ *   key="1" value="Exit Suspend"
+ *   key="2-255" ReservedForFutureUse
+ */
+
+typedef enum __attribute__((packed)) {
+    BLE_SVC_HID_HID_CONTROL_POINT_SUSPEND,
+    BLE_SVC_HID_HID_CONTROL_POINT_EXIT_SUSPEND
+} ble_svc_hid_hid_control_point_value_t;
+
+/* Functions */
+
+void ble_svc_hid_init(void);
+
+#endif
diff --git a/nimble/host/services/hid/pkg.yml b/nimble/host/services/hid/pkg.yml
new file mode 100644
index 00000000..28429b4e
--- /dev/null
+++ b/nimble/host/services/hid/pkg.yml
@@ -0,0 +1,34 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you 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.
+#
+
+pkg.name: nimble/host/services/hid
+pkg.description: Implements the Human Interface Device Service
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
+    - ble
+    - bluetooth
+    - nimble
+    - hid
+
+pkg.deps:
+    - nimble/host
+
+pkg.init:
+    ble_svc_hid_init: 303
diff --git a/nimble/host/services/hid/src/ble_svc_hid.c b/nimble/host/services/hid/src/ble_svc_hid.c
new file mode 100644
index 00000000..bf5f8e80
--- /dev/null
+++ b/nimble/host/services/hid/src/ble_svc_hid.c
@@ -0,0 +1,209 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 <assert.h>
+
+#include "services/hid/ble_svc_hid.h"
+
+#include "sysinit/sysinit.h"
+#include "syscfg/syscfg.h"
+#include "host/ble_hs.h"
+
+
+/* TODO: Multiple HID instances */
+uint16_t ble_svc_hid_val_handle;
+
+/* HID information */
+static ble_svc_hid_hid_information_t ble_svc_hid_hid_info = {
+    .hidver = USB_HID_VERSION_1_11;
+    .countrycode = 0x00;
+    .flags = BLE_SVC_HID_HID_INFO_FLAG_REMOTE_WAKE|BLE_SVC_HID_HID_INFO_FLAG_NORMALLY_CONNECTABLE
+}
+
+/* Access function */
+static int
+ble_svc_hid_access(uint16_t conn_handle, uint16_t attr_handle,
+                   struct ble_gatt_access_ctxt *ctxt, void *arg);
+
+/* Service and characteristics definition */
+/* TODO: Confirm details of characteristic `Report` */
+static const struct ble_gatt_svc_def ble_svc_hid_defs[] = {
+    {
+        /*** Service: Tx Power Service. */
+        .type = BLE_GATT_SVC_TYPE_PRIMARY,
+        .uuid = BLE_UUID16_DECLARE(BLE_SVC_HID_UUID16),
+        .characteristics = (struct ble_gatt_chr_def[]) { {
+            /*** Characteristic: Protocol Mode. */
+            .uuid = BLE_UUID16_DECLARE(BLE_SVC_HID_CHR_UUID16_PROTOCOL_MODE),
+            .access_cb = ble_svc_hid_access,
+            .val_handle = &ble_svc_hid_val_handle,
+            .flags = BLE_GATT_CHR_F_READ|BLE_GATT_CHR_F_WRITE_NO_RSP,
+        }, {
+            /*** Characteristic: Report. */
+            .uuid = BLE_UUID16_DECLARE(BLE_SVC_HID_CHR_UUID16_REPORT),
+            .access_cb = ble_svc_hid_access,
+            .val_handle = &ble_svc_hid_val_handle,
+            .flags = BLE_GATT_CHR_F_READ|BLE_GATT_CHR_F_NOTIFY,
+        }, {
+            /*** Characteristic: Report Map. */
+            .uuid = BLE_UUID16_DECLARE(BLE_SVC_HID_CHR_UUID16_REPORT_MAP),
+            .access_cb = ble_svc_hid_access,
+            .val_handle = &ble_svc_hid_val_handle,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            /*** Characteristic: Boot Keyboard Input Report. */
+            .uuid = BLE_UUID16_DECLARE(BLE_SVC_HID_CHR_UUID16_BOOT_KEYBOARD_INPUT_REPORT),
+            .access_cb = ble_svc_hid_access,
+            .val_handle = &ble_svc_hid_val_handle,
+            .flags = BLE_GATT_CHR_F_READ|BLE_GATT_CHR_F_NOTIFY,
+        }, {
+            /*** Characteristic: Boot Keyboard Output Report. */
+            .uuid = BLE_UUID16_DECLARE(BLE_SVC_HID_CHR_UUID16_BOOT_KEYBOARD_OUTPUT_REPORT),
+            .access_cb = ble_svc_hid_access,
+            .val_handle = &ble_svc_hid_val_handle,
+            .flags = BLE_GATT_CHR_F_READ|BLE_GATT_CHR_F_WRITE|BLE_GATT_CHR_F_WRITE_NO_RSP,
+        }, {
+            /*** Characteristic: Boot Mouse Input Report. */
+            .uuid = BLE_UUID16_DECLARE(BLE_SVC_HID_CHR_UUID16_BOOT_MOUSE_INPUT_REPORT),
+            .access_cb = ble_svc_hid_access,
+            .val_handle = &ble_svc_hid_val_handle,
+            .flags = BLE_GATT_CHR_F_READ|BLE_GATT_CHR_F_NOTIFY,
+        }, {
+            /*** Characteristic: Hid Information. */
+            .uuid = BLE_UUID16_DECLARE(BLE_SVC_HID_CHR_UUID16_HID_INFORMATION),
+            .access_cb = ble_svc_hid_access,
+            .val_handle = &ble_svc_hid_val_handle,
+            .flags = BLE_GATT_CHR_F_READ,
+        }, {
+            /*** Characteristic: Hid Control Point. */
+            .uuid = BLE_UUID16_DECLARE(BLE_SVC_HID_CHR_UUID16_HID_CONTROL_POINT),
+            .access_cb = ble_svc_hid_access,
+            .val_handle = &ble_svc_hid_val_handle,
+            .flags = BLE_GATT_CHR_F_WRITE_NO_RSP,
+        }, {
+            0, /* No more characteristics in this service. */
+        } },
+    },
+
+    {
+        0, /* No more services. */
+    },
+};
+
+/*
+ * Service API
+ */
+
+/*
+ *  Set HID Information
+ */
+int
+ble_svc_hid_set_hid_info(uint16_t ver,uint8_t cc, uint8_t flags) {
+    int rc = 0;
+
+    ble_svc_hid_hid_info.hidver=ver;
+    ble_svc_hid_hid_info.countrycode= cc;
+    ble_svc_hid_hid_info.flags = flags
+
+    return rc;
+}
+
+/**
+ * HID access function
+ */
+static int
+ble_svc_hid_access(uint16_t conn_handle, uint16_t attr_handle,
+                          struct ble_gatt_access_ctxt *ctxt,
+                          void *arg)
+{
+    uint16_t uuid16;
+    int rc=0;
+
+    uuid16 = ble_uuid_u16(ctxt->chr->uuid);
+    assert(uuid16 != 0);
+
+    switch (uuid16) {
+    case BLE_SVC_HID_CHR_UUID16_PROTOCOL_MODE:
+        if (ctxt->op == BLE_GATT_CHR_F_READ) {
+        } else if (ctxt->op == BLE_GATT_CHR_F_WRITE_NO_RSP) {
+        }
+        return rc;
+
+    case BLE_SVC_HID_CHR_UUID16_REPORT:
+        if (ctxt->op == BLE_GATT_CHR_F_READ) {
+        } else if (ctxt->op == BLE_GATT_CHR_F_NOTIFY) {
+        }
+        return rc;
+
+    case BLE_SVC_HID_CHR_UUID16_REPORT_MAP:
+        assert(ctxt->op == BLE_GATT_CHR_F_READ);
+        return rc;
+
+    case BLE_SVC_HID_CHR_UUID16_BOOT_KEYBOARD_INPUT_REPORT:
+        if (ctxt->op == BLE_GATT_CHR_F_READ) {
+        } else if (ctxt->op == BLE_GATT_CHR_F_NOTIFY) {
+        }
+        return rc;
+
+    case BLE_SVC_HID_CHR_UUID16_BOOT_KEYBOARD_OUTPUT_REPORT:
+        if (ctxt->op == BLE_GATT_CHR_F_READ) {
+        } else if (ctxt->op == BLE_GATT_CHR_F_WRITE) {
+        } else if (ctxt->op == BLE_GATT_CHR_F_WRITE_NO_RSP) {
+        }
+        return rc;
+
+    case BLE_SVC_HID_CHR_UUID16_BOOT_MOUSE_INPUT_REPORT:
+        if (ctxt->op == BLE_GATT_CHR_F_READ) {
+        } else if (ctxt->op == BLE_GATT_CHR_F_NOTIFY) {
+        }
+        return rc;
+
+    case BLE_SVC_HID_CHR_UUID16_HID_INFORMATION:
+        assert(ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR);
+        rc = os_mbuf_append(ctxt->om, &ble_svc_hid_hid_info,
+                            sizeof(ble_svc_hid_hid_info));
+        return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES;
+
+    case BLE_SVC_HID_CHR_UUID16_HID_CONTROL_POINT:
+        assert(ctxt->op == BLE_GATT_CHR_F_WRITE_NO_RSP);
+        return rc;
+
+    default:
+        assert(0);
+        return BLE_ATT_ERR_UNLIKELY;
+    }
+}
+
+/**
+ * Initialize the HID service
+ */
+void
+ble_svc_hid_init(void)
+{
+    int rc;
+
+    /* Ensure this function only gets called by sysinit. */
+    SYSINIT_ASSERT_ACTIVE();
+
+    rc = ble_gatts_count_cfg(ble_svc_hid_defs);
+    SYSINIT_PANIC_ASSERT(rc == 0);
+
+    rc = ble_gatts_add_svcs(ble_svc_hid_defs);
+    SYSINIT_PANIC_ASSERT(rc == 0);
+}
diff --git a/nimble/host/services/hid/syscfg.yml b/nimble/host/services/hid/syscfg.yml
new file mode 100644
index 00000000..e69de29b


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services