/* * 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 #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); }