hid_device: move hid_create_sdp_record into classic/hid_device.h

This commit is contained in:
Matthias Ringwald 2017-04-27 11:39:25 +02:00
parent 6518788a7f
commit d40c9ac6cf
4 changed files with 238 additions and 139 deletions

View File

@ -122,7 +122,6 @@ const uint8_t hid_descriptor_keyboard_boot_mode[] = {
};
//
#define CHAR_ILLEGAL 0xff
#define CHAR_RETURN '\n'
#define CHAR_ESCAPE 27
@ -172,143 +171,6 @@ static const uint8_t keytable_us_shift[] = {
'6', '7', '8', '9', '0', '.', 0xb1, /* 97-100 */
};
void hid_create_sdp_record(
uint8_t *service,
uint32_t service_record_handle,
uint16_t hid_device_subclass,
uint8_t hid_country_code,
uint8_t hid_virtual_cable,
uint8_t hid_reconnect_initiate,
uint8_t hid_boot_device,
const uint8_t * hid_descriptor, uint16_t hid_descriptor_size,
const char *device_name);
void hid_create_sdp_record(
uint8_t *service,
uint32_t service_record_handle,
uint16_t hid_device_subclass,
uint8_t hid_country_code,
uint8_t hid_virtual_cable,
uint8_t hid_reconnect_initiate,
uint8_t hid_boot_device,
const uint8_t * hid_descriptor, uint16_t hid_descriptor_size,
const char *device_name){
uint8_t * attribute;
de_create_sequence(service);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_SERVICE_RECORD_HANDLE);
de_add_number(service, DE_UINT, DE_SIZE_32, service_record_handle);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_SERVICE_CLASS_ID_LIST);
attribute = de_push_sequence(service);
{
de_add_number(attribute, DE_UUID, DE_SIZE_16, BLUETOOTH_SERVICE_CLASS_HUMAN_INTERFACE_DEVICE_SERVICE);
}
de_pop_sequence(service, attribute);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST);
attribute = de_push_sequence(service);
{
uint8_t * l2cpProtocol = de_push_sequence(attribute);
{
de_add_number(l2cpProtocol, DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_L2CAP);
de_add_number(l2cpProtocol, DE_UINT, DE_SIZE_16, PSM_HID_CONTROL);
}
de_pop_sequence(attribute, l2cpProtocol);
uint8_t * hidProtocol = de_push_sequence(attribute);
{
de_add_number(hidProtocol, DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_HIDP);
}
de_pop_sequence(attribute, hidProtocol);
}
de_pop_sequence(service, attribute);
// TODO?
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_LANGUAGE_BASE_ATTRIBUTE_ID_LIST);
attribute = de_push_sequence(service);
{
de_add_number(attribute, DE_UINT, DE_SIZE_16, 0x656e);
de_add_number(attribute, DE_UINT, DE_SIZE_16, 0x006a);
de_add_number(attribute, DE_UINT, DE_SIZE_16, 0x0100);
}
de_pop_sequence(service, attribute);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_ADDITIONAL_PROTOCOL_DESCRIPTOR_LISTS);
attribute = de_push_sequence(service);
{
uint8_t * additionalDescriptorAttribute = de_push_sequence(attribute);
{
uint8_t * l2cpProtocol = de_push_sequence(additionalDescriptorAttribute);
{
de_add_number(l2cpProtocol, DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_L2CAP);
de_add_number(l2cpProtocol, DE_UINT, DE_SIZE_16, PSM_HID_INTERRUPT);
}
de_pop_sequence(additionalDescriptorAttribute, l2cpProtocol);
uint8_t * hidProtocol = de_push_sequence(attribute);
{
de_add_number(hidProtocol, DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_HIDP);
}
de_pop_sequence(attribute, hidProtocol);
}
de_pop_sequence(attribute, additionalDescriptorAttribute);
}
de_pop_sequence(service, attribute);
// 0x0100 "ServiceName"
de_add_number(service, DE_UINT, DE_SIZE_16, 0x0100);
de_add_data(service, DE_STRING, strlen(device_name), (uint8_t *) device_name);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_BLUETOOTH_PROFILE_DESCRIPTOR_LIST);
attribute = de_push_sequence(service);
{
uint8_t * hidProfile = de_push_sequence(attribute);
{
de_add_number(hidProfile, DE_UUID, DE_SIZE_16, BLUETOOTH_SERVICE_CLASS_HUMAN_INTERFACE_DEVICE_SERVICE);
de_add_number(hidProfile, DE_UINT, DE_SIZE_16, 0x0101); // Version 1.1
}
de_pop_sequence(attribute, hidProfile);
}
de_pop_sequence(service, attribute);
// Deprecated in v1.1.1
// de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_DEVICE_RELEASE_NUMBER);
// de_add_number(service, DE_UINT, DE_SIZE_16, 0x0101);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_PARSER_VERSION);
de_add_number(service, DE_UINT, DE_SIZE_16, 0x0111); // v1.1.1
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_DEVICE_SUBCLASS);
de_add_number(service, DE_UINT, DE_SIZE_16, hid_device_subclass);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_COUNTRY_CODE);
de_add_number(service, DE_UINT, DE_SIZE_16, hid_country_code);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_VIRTUAL_CABLE);
de_add_number(service, DE_BOOL, DE_SIZE_8, hid_virtual_cable);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_RECONNECT_INITIATE);
de_add_number(service, DE_BOOL, DE_SIZE_8, hid_reconnect_initiate);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_DESCRIPTOR_LIST);
attribute = de_push_sequence(service);
{
uint8_t* hidDescriptor = de_push_sequence(attribute);
{
de_add_number(hidDescriptor, DE_UINT, DE_SIZE_8, 0x22); // Report Descriptor
de_add_data(hidDescriptor, DE_STRING, hid_descriptor_size, (uint8_t *) hid_descriptor);
}
de_pop_sequence(attribute, hidDescriptor);
}
de_pop_sequence(service, attribute);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_BOOT_DEVICE);
de_add_number(service, DE_BOOL, DE_SIZE_8, hid_boot_device);
}
// HID Keyboard lookup
static int lookup_keycode(uint8_t character, const uint8_t * table, int size, uint8_t * keycode){
int i;

View File

@ -80,13 +80,14 @@
#include "ble/sm.h"
#endif
// #ifdef HAVE_CLASSIC
// #ifdef ENABLE_CLASSIC
#include "classic/bnep.h"
#include "classic/btstack_link_key_db.h"
#include "classic/device_id_server.h"
#include "classic/hfp.h"
#include "classic/hfp_ag.h"
#include "classic/hfp_hf.h"
#include "classic/hid_device.h"
#include "classic/hsp_ag.h"
#include "classic/hsp_hs.h"
#include "classic/pan.h"

170
src/classic/hid_device.c Normal file
View File

@ -0,0 +1,170 @@
/*
* Copyright (C) 2014 BlueKitchen GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* 4. Any redistribution, use, or modification is done solely for
* personal benefit and not for any commercial purpose or for
* monetary gain.
*
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
* RINGWALD 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.
*
* Please inquire about commercial licensing options at
* contact@bluekitchen-gmbh.com
*
*/
#define __BTSTACK_FILE__ "hid_device.c"
#include <string.h>
#include "classic/hid_device.h"
#include "classic/sdp_util.h"
#include "bluetooth.h"
#include "bluetooth_sdp.h"
void hid_create_sdp_record(
uint8_t *service,
uint32_t service_record_handle,
uint16_t hid_device_subclass,
uint8_t hid_country_code,
uint8_t hid_virtual_cable,
uint8_t hid_reconnect_initiate,
uint8_t hid_boot_device,
const uint8_t * hid_descriptor, uint16_t hid_descriptor_size,
const char *device_name){
uint8_t * attribute;
de_create_sequence(service);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_SERVICE_RECORD_HANDLE);
de_add_number(service, DE_UINT, DE_SIZE_32, service_record_handle);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_SERVICE_CLASS_ID_LIST);
attribute = de_push_sequence(service);
{
de_add_number(attribute, DE_UUID, DE_SIZE_16, BLUETOOTH_SERVICE_CLASS_HUMAN_INTERFACE_DEVICE_SERVICE);
}
de_pop_sequence(service, attribute);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_PROTOCOL_DESCRIPTOR_LIST);
attribute = de_push_sequence(service);
{
uint8_t * l2cpProtocol = de_push_sequence(attribute);
{
de_add_number(l2cpProtocol, DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_L2CAP);
de_add_number(l2cpProtocol, DE_UINT, DE_SIZE_16, PSM_HID_CONTROL);
}
de_pop_sequence(attribute, l2cpProtocol);
uint8_t * hidProtocol = de_push_sequence(attribute);
{
de_add_number(hidProtocol, DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_HIDP);
}
de_pop_sequence(attribute, hidProtocol);
}
de_pop_sequence(service, attribute);
// TODO?
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_LANGUAGE_BASE_ATTRIBUTE_ID_LIST);
attribute = de_push_sequence(service);
{
de_add_number(attribute, DE_UINT, DE_SIZE_16, 0x656e);
de_add_number(attribute, DE_UINT, DE_SIZE_16, 0x006a);
de_add_number(attribute, DE_UINT, DE_SIZE_16, 0x0100);
}
de_pop_sequence(service, attribute);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_ADDITIONAL_PROTOCOL_DESCRIPTOR_LISTS);
attribute = de_push_sequence(service);
{
uint8_t * additionalDescriptorAttribute = de_push_sequence(attribute);
{
uint8_t * l2cpProtocol = de_push_sequence(additionalDescriptorAttribute);
{
de_add_number(l2cpProtocol, DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_L2CAP);
de_add_number(l2cpProtocol, DE_UINT, DE_SIZE_16, PSM_HID_INTERRUPT);
}
de_pop_sequence(additionalDescriptorAttribute, l2cpProtocol);
uint8_t * hidProtocol = de_push_sequence(attribute);
{
de_add_number(hidProtocol, DE_UUID, DE_SIZE_16, BLUETOOTH_PROTOCOL_HIDP);
}
de_pop_sequence(attribute, hidProtocol);
}
de_pop_sequence(attribute, additionalDescriptorAttribute);
}
de_pop_sequence(service, attribute);
// 0x0100 "ServiceName"
de_add_number(service, DE_UINT, DE_SIZE_16, 0x0100);
de_add_data(service, DE_STRING, strlen(device_name), (uint8_t *) device_name);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_BLUETOOTH_PROFILE_DESCRIPTOR_LIST);
attribute = de_push_sequence(service);
{
uint8_t * hidProfile = de_push_sequence(attribute);
{
de_add_number(hidProfile, DE_UUID, DE_SIZE_16, BLUETOOTH_SERVICE_CLASS_HUMAN_INTERFACE_DEVICE_SERVICE);
de_add_number(hidProfile, DE_UINT, DE_SIZE_16, 0x0101); // Version 1.1
}
de_pop_sequence(attribute, hidProfile);
}
de_pop_sequence(service, attribute);
// Deprecated in v1.1.1
// de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_DEVICE_RELEASE_NUMBER);
// de_add_number(service, DE_UINT, DE_SIZE_16, 0x0101);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_PARSER_VERSION);
de_add_number(service, DE_UINT, DE_SIZE_16, 0x0111); // v1.1.1
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_DEVICE_SUBCLASS);
de_add_number(service, DE_UINT, DE_SIZE_16, hid_device_subclass);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_COUNTRY_CODE);
de_add_number(service, DE_UINT, DE_SIZE_16, hid_country_code);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_VIRTUAL_CABLE);
de_add_number(service, DE_BOOL, DE_SIZE_8, hid_virtual_cable);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_RECONNECT_INITIATE);
de_add_number(service, DE_BOOL, DE_SIZE_8, hid_reconnect_initiate);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_DESCRIPTOR_LIST);
attribute = de_push_sequence(service);
{
uint8_t* hidDescriptor = de_push_sequence(attribute);
{
de_add_number(hidDescriptor, DE_UINT, DE_SIZE_8, 0x22); // Report Descriptor
de_add_data(hidDescriptor, DE_STRING, hid_descriptor_size, (uint8_t *) hid_descriptor);
}
de_pop_sequence(attribute, hidDescriptor);
}
de_pop_sequence(service, attribute);
de_add_number(service, DE_UINT, DE_SIZE_16, BLUETOOTH_ATTRIBUTE_HID_BOOT_DEVICE);
de_add_number(service, DE_BOOL, DE_SIZE_8, hid_boot_device);
}

66
src/classic/hid_device.h Normal file
View File

@ -0,0 +1,66 @@
/*
* Copyright (C) 2014 BlueKitchen GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* 4. Any redistribution, use, or modification is done solely for
* personal benefit and not for any commercial purpose or for
* monetary gain.
*
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
* RINGWALD 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.
*
* Please inquire about commercial licensing options at
* contact@bluekitchen-gmbh.com
*
*/
#include <stdint.h>
/**
* @brief Create HID Device SDP service record.
* @param service Empty buffer in which a new service record will be stored.
* @param have_remote_audio_control
* @param service
* @param service_record_handle
* @param hid_device_subclass
* @param hid_country_code
* @param hid_virtual_cable
* @param hid_reconnect_initiate
* @param hid_boot_device
* @param hid_descriptor
* @param hid_descriptor_size size of hid_descriptor
* @param device_name
*/
void hid_create_sdp_record(
uint8_t * service,
uint32_t service_record_handle,
uint16_t hid_device_subclass,
uint8_t hid_country_code,
uint8_t hid_virtual_cable,
uint8_t hid_reconnect_initiate,
uint8_t hid_boot_device,
const uint8_t * hid_descriptor,
uint16_t hid_descriptor_size,
const char * device_name);