From 1ad99f3bd30dfda1f1d3c25ba34069bcf3cdff8c Mon Sep 17 00:00:00 2001
From: Milanka Ringwald <mila@ringwald.ch>
Date: Fri, 27 Nov 2020 17:11:09 +0100
Subject: [PATCH] hid_device: add hid_remote_wake attribute to API

---
 example/hid_keyboard_demo.c   | 10 ++++++++--
 example/hid_mouse_demo.c      |  9 ++++++++-
 src/classic/hid_device.c      |  2 +-
 src/classic/hid_device.h      |  1 +
 test/pts/hid_device_test.c    |  8 +++++---
 test/sdp/sdp_record_builder.c |  2 +-
 6 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/example/hid_keyboard_demo.c b/example/hid_keyboard_demo.c
index f6eed6685..5ead78387 100644
--- a/example/hid_keyboard_demo.c
+++ b/example/hid_keyboard_demo.c
@@ -186,7 +186,6 @@ static enum {
     APP_CONNECTED
 } app_state = APP_BOOTING;
 
-
 // HID Keyboard lookup
 static int lookup_keycode(uint8_t character, const uint8_t * table, int size, uint8_t * keycode){
     int i;
@@ -403,8 +402,15 @@ int btstack_main(int argc, const char * argv[]){
     // SDP Server
     sdp_init();
     memset(hid_service_buffer, 0, sizeof(hid_service_buffer));
+
+    uint8_t hid_virtual_cable = 0;
+    uint8_t hid_remote_wake = 1;
+    uint8_t hid_reconnect_initiate = 1;
+
     // hid sevice subclass 2540 Keyboard, hid counntry code 33 US, hid virtual cable off, hid reconnect initiate off, hid boot device off 
-    hid_create_sdp_record(hid_service_buffer, 0x10001, 0x2540, 33, 0, 0, hid_boot_device, hid_descriptor_keyboard_boot_mode, sizeof(hid_descriptor_keyboard_boot_mode), hid_device_name);
+    hid_create_sdp_record(hid_service_buffer, 0x10001, 0x2540, 33, 
+        hid_virtual_cable, hid_remote_wake, hid_reconnect_initiate, 
+        hid_boot_device, hid_descriptor_keyboard_boot_mode, sizeof(hid_descriptor_keyboard_boot_mode), hid_device_name);
     printf("HID service record size: %u\n", de_get_len( hid_service_buffer));
     sdp_register_service(hid_service_buffer);
 
diff --git a/example/hid_mouse_demo.c b/example/hid_mouse_demo.c
index f270052cc..83759eb9a 100644
--- a/example/hid_mouse_demo.c
+++ b/example/hid_mouse_demo.c
@@ -302,8 +302,15 @@ int btstack_main(int argc, const char * argv[]){
     // SDP Server
     sdp_init();
     memset(hid_service_buffer, 0, sizeof(hid_service_buffer));
+    
+    uint8_t hid_virtual_cable = 0;
+    uint8_t hid_remote_wake = 1;
+    uint8_t hid_reconnect_initiate = 1;
+
     // hid sevice subclass 2540 Keyboard, hid counntry code 33 US, hid virtual cable off, hid reconnect initiate off, hid boot device off
-    hid_create_sdp_record(hid_service_buffer, 0x10001, 0x2540, 33, 0, 0, hid_boot_device, hid_descriptor_mouse_boot_mode, sizeof(hid_descriptor_mouse_boot_mode), hid_device_name);
+    hid_create_sdp_record(hid_service_buffer, 0x10001, 0x2540, 33,
+        hid_virtual_cable, hid_remote_wake, hid_reconnect_initiate, 
+        hid_boot_device, hid_descriptor_mouse_boot_mode, sizeof(hid_descriptor_mouse_boot_mode), hid_device_name);
     printf("SDP service record size: %u\n", de_get_len( hid_service_buffer));
     sdp_register_service(hid_service_buffer);
 
diff --git a/src/classic/hid_device.c b/src/classic/hid_device.c
index 0845bb410..9effc54cf 100644
--- a/src/classic/hid_device.c
+++ b/src/classic/hid_device.c
@@ -161,6 +161,7 @@ void hid_create_sdp_record(
     uint16_t hid_device_subclass,
     uint8_t  hid_country_code,
     uint8_t  hid_virtual_cable,
+    uint8_t  hid_remote_wake,
     uint8_t  hid_reconnect_initiate,
     uint8_t  hid_boot_device,
     const uint8_t * descriptor, uint16_t descriptor_size,
@@ -289,7 +290,6 @@ void hid_create_sdp_record(
     }
     de_pop_sequence(service, attribute);
 
-    uint8_t hid_remote_wake = 1;
     de_add_number(service,  DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_REMOTE_WAKE); 
     de_add_number(service,  DE_BOOL, DE_SIZE_8,  hid_remote_wake);
 
diff --git a/src/classic/hid_device.h b/src/classic/hid_device.h
index 49b49f15f..8f60c6517 100644
--- a/src/classic/hid_device.h
+++ b/src/classic/hid_device.h
@@ -71,6 +71,7 @@ void hid_create_sdp_record(
     uint16_t        hid_device_subclass,
     uint8_t         hid_country_code,
     uint8_t         hid_virtual_cable,
+    uint8_t         hid_remote_wake,
     uint8_t         hid_reconnect_initiate,
     uint8_t         hid_boot_device,
     const uint8_t * hid_descriptor,
diff --git a/test/pts/hid_device_test.c b/test/pts/hid_device_test.c
index c3889dccc..8e241af60 100644
--- a/test/pts/hid_device_test.c
+++ b/test/pts/hid_device_test.c
@@ -490,12 +490,14 @@ int btstack_main(int argc, const char * argv[]){
     sdp_init();
     memset(hid_service_buffer, 0, sizeof(hid_service_buffer));
 
+    uint8_t hid_virtual_cable = 0;
+    uint8_t hid_remote_wake = 1;
     uint8_t hid_reconnect_initiate = 1;
-    uint8_t hid_virtual_cable = 1;
+    
     // hid sevice subclass 2540 Keyboard, hid counntry code 33 US, hid virtual cable on, hid reconnect initiate on, hid boot device off 
     hid_create_sdp_record(hid_service_buffer, 0x10001, 0x2540, 33, 
-        hid_virtual_cable, hid_reconnect_initiate, hid_boot_device, 
-        hid_descriptor_keyboard_boot_mode, sizeof(hid_descriptor_keyboard_boot_mode), hid_device_name);
+        hid_virtual_cable, hid_remote_wake, hid_reconnect_initiate, 
+        hid_boot_device, hid_descriptor_keyboard_boot_mode, sizeof(hid_descriptor_keyboard_boot_mode), hid_device_name);
 
     printf("HID service record size: %u\n", de_get_len( hid_service_buffer));
     sdp_register_service(hid_service_buffer);
diff --git a/test/sdp/sdp_record_builder.c b/test/sdp/sdp_record_builder.c
index 6a463a93b..3174c96b5 100644
--- a/test/sdp/sdp_record_builder.c
+++ b/test/sdp/sdp_record_builder.c
@@ -217,7 +217,7 @@ TEST(SDPRecordBuilder, HID_DEVICE){
     name = "";
     descriptor_size = 0;
     expected_len = hid_device_record_size(descriptor_size, name);
-    hid_create_sdp_record(service_buffer, 0, 0, 0, 0, 0, 0, NULL, descriptor_size, name);
+    hid_create_sdp_record(service_buffer, 0x0001, 0, 0, 0, 0, 0, 0, NULL, descriptor_size, name);
     CHECK_EQUAL(de_get_len(service_buffer), expected_len);
 }