/* * dosdpregistration - Care for the proper SDP record sent to the "sdpd" * so that other BT devices can discover the HID service * Parameters: none; Return value: 0 = OK, >0 = failure */ int dosdpregistration ( void ) { sdp_record_t record; sdp_session_t *session; sdp_list_t *svclass_id, *pfseq, *apseq, *root; uuid_t root_uuid, hidkb_uuid, l2cap_uuid, hidp_uuid; sdp_profile_desc_t profile[1]; sdp_list_t *aproto, *proto[3]; sdp_data_t *psm, *lang_lst, *lang_lst2, *hid_spec_lst, *hid_spec_lst2; void *dtds[2], *values[2], *dtds2[2], *values2[2]; int i, leng[2]; uint8_t dtd=SDP_UINT16, dtd2=SDP_UINT8, dtd_data=SDP_TEXT_STR8, hid_spec_type=0x22; uint16_t hid_attr_lang[]={0x409, 0x100}, ctrl=PSMHIDCTL, intr=PSMHIDINT, hid_attr[]={0x100, 0x111, 0x40, 0x00, 0x01, 0x01}, // Assigned to SDP 0x200...0x205 - see HID SPEC for // details. Those values seem to work fine... // "it\'s a kind of magic" numbers. hid_attr2[]={0x100, 0x0}; // Connect to SDP server on localhost, to publish service information session = sdp_connect ( BDADDR_ANY, BDADDR_LOCAL, 0 ); if ( ! session ) { fprintf ( stderr, "Failed to connect to SDP server: %s\n", strerror ( errno ) ); return 1; } memset(&record, 0, sizeof(sdp_record_t)); record.handle = 0xffffffff; // With 0xffffffff, we get assigned the first free record >= 0x10000 // Make HID service visible (add to PUBLIC BROWSE GROUP) sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); root = sdp_list_append(0, &root_uuid); sdp_set_browse_groups(&record, root); // Language Information to be added add_lang_attr(&record); // The descriptor for the keyboard sdp_uuid16_create(&hidkb_uuid, HID_SVCLASS_ID); svclass_id = sdp_list_append(0, &hidkb_uuid); sdp_set_service_classes(&record, svclass_id); // And information about the HID profile used sdp_uuid16_create(&profile[0].uuid, HIDP_UUID /*HID_PROFILE_ID*/); profile[0].version = 0x0100; pfseq = sdp_list_append(0, profile); sdp_set_profile_descs(&record, pfseq); // We are using L2CAP, so add an info about that sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); proto[1] = sdp_list_append(0, &l2cap_uuid); psm = sdp_data_alloc(SDP_UINT16, &ctrl); proto[1] = sdp_list_append(proto[1], psm); apseq = sdp_list_append(0, proto[1]); // And about our purpose, the HID protocol data transfer sdp_uuid16_create(&hidp_uuid, HIDP_UUID); proto[2] = sdp_list_append(0, &hidp_uuid); apseq = sdp_list_append(apseq, proto[2]); aproto = sdp_list_append(0, apseq); sdp_set_access_protos(&record, aproto); proto[1] = sdp_list_append(0, &l2cap_uuid); psm = sdp_data_alloc(SDP_UINT16, &intr); proto[1] = sdp_list_append(proto[1], psm); apseq = sdp_list_append(0, proto[1]); sdp_uuid16_create(&hidp_uuid, HIDP_UUID); proto[2] = sdp_list_append(0, &hidp_uuid); apseq = sdp_list_append(apseq, proto[2]); aproto = sdp_list_append(0, apseq); sdp_set_add_access_protos(&record, aproto); // Set service name, description sdp_set_info_attr(&record, HIDINFO_NAME, HIDINFO_PROV, HIDINFO_DESC); // Add a few HID-specifid pieces of information // See the HID spec for details what those codes 0x200+something // are good for... we send a fixed set of info that seems to work sdp_attr_add_new(&record, SDP_ATTR_HID_DEVICE_RELEASE_NUMBER, SDP_UINT16, &hid_attr[0]); /* Opt */ sdp_attr_add_new(&record, SDP_ATTR_HID_PARSER_VERSION, SDP_UINT16, &hid_attr[1]); /* Mand */ sdp_attr_add_new(&record, SDP_ATTR_HID_DEVICE_SUBCLASS, SDP_UINT8, &hid_attr[2]); /* Mand */ sdp_attr_add_new(&record, SDP_ATTR_HID_COUNTRY_CODE, SDP_UINT8, &hid_attr[3]); /* Mand */ sdp_attr_add_new(&record, SDP_ATTR_HID_VIRTUAL_CABLE, SDP_BOOL, &hid_attr[4]); /* Mand */ sdp_attr_add_new(&record, SDP_ATTR_HID_RECONNECT_INITIATE, SDP_BOOL, &hid_attr[5]); /* Mand */ // Add the HID descriptor (describing the virtual device) as code // SDP_ATTR_HID_DESCRIPTOR_LIST (0x206 IIRC) dtds[0] = &dtd2; values[0] = &hid_spec_type; dtd_data= SDPRECORD_BYTES <= 255 ? SDP_TEXT_STR8 : SDP_TEXT_STR16 ; dtds[1] = &dtd_data; values[1] = (uint8_t *) SDPRECORD; leng[0] = 0; leng[1] = SDPRECORD_BYTES; hid_spec_lst = sdp_seq_alloc_with_length(dtds, values, leng, 2); hid_spec_lst2 = sdp_data_alloc(SDP_SEQ8, hid_spec_lst); sdp_attr_add(&record, SDP_ATTR_HID_DESCRIPTOR_LIST, hid_spec_lst2); // and continue adding further data bytes for 0x206+x values for (i = 0; i < sizeof(hid_attr_lang) / 2; i++) { dtds2[i] = &dtd; values2[i] = &hid_attr_lang[i]; } lang_lst = sdp_seq_alloc(dtds2, values2, sizeof(hid_attr_lang) / 2); lang_lst2 = sdp_data_alloc(SDP_SEQ8, lang_lst); sdp_attr_add(&record, SDP_ATTR_HID_LANG_ID_BASE_LIST, lang_lst2); sdp_attr_add_new ( &record, SDP_ATTR_HID_PROFILE_VERSION, SDP_UINT16, &hid_attr2[0] ); sdp_attr_add_new ( &record, SDP_ATTR_HID_BOOT_DEVICE, SDP_UINT16, &hid_attr2[1] ); // Submit our IDEA of a SDP record to the "sdpd" if (sdp_record_register(session, &record, SDP_RECORD_PERSIST) < 0) { fprintf ( stderr, "Service Record registration failed\n" ); return -1; } // Store the service handle retrieved from there for reference (i.e., // deleting the service info when this program terminates) sdphandle = record.handle; fprintf ( stdout, "HID keyboard/mouse service registered\n" ); return 0; }
static gboolean register_service_additional_protocols( struct hdp_adapter *adapter, sdp_record_t *sdp_record) { gboolean ret = TRUE; uuid_t l2cap_uuid, mcap_d_uuid; sdp_list_t *l2cap_list, *proto_list = NULL, *mcap_list = NULL; sdp_list_t *access_proto_list = NULL; sdp_data_t *psm = NULL; /* set l2cap information */ sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); l2cap_list = sdp_list_append(NULL, &l2cap_uuid); if (l2cap_list == NULL) { ret = FALSE; goto end; } psm = sdp_data_alloc(SDP_UINT16, &adapter->dcpsm); if (psm == NULL) { ret = FALSE; goto end; } if (sdp_list_append(l2cap_list, psm) == NULL) { ret = FALSE; goto end; } proto_list = sdp_list_append(NULL, l2cap_list); if (proto_list == NULL) { ret = FALSE; goto end; } /* set mcap information */ sdp_uuid16_create(&mcap_d_uuid, MCAP_DATA_UUID); mcap_list = sdp_list_append(NULL, &mcap_d_uuid); if (mcap_list == NULL) { ret = FALSE; goto end; } if (sdp_list_append(proto_list, mcap_list) == NULL) { ret = FALSE; goto end; } /* attach protocol information to service record */ access_proto_list = sdp_list_append(NULL, proto_list); if (access_proto_list == NULL) { ret = FALSE; goto end; } sdp_set_add_access_protos(sdp_record, access_proto_list); end: if (l2cap_list != NULL) sdp_list_free(l2cap_list, NULL); if (mcap_list != NULL) sdp_list_free(mcap_list, NULL); if (proto_list != NULL) sdp_list_free(proto_list, NULL); if (access_proto_list != NULL) sdp_list_free(access_proto_list, NULL); if (psm != NULL) sdp_data_free(psm); return ret; }
/** * Creates the SDP record for HID emulation. Works well with many different * clients: windows, linux (ubuntu), PS3, and motorola android devices. */ static sdp_record_t *create_hid_generic_record() { sdp_record_t *sdp_record; sdp_list_t *svclass_id, *pfseq, *apseq, *root; uuid_t root_uuid, hidkb_uuid, l2cap_uuid, hidp_uuid; sdp_profile_desc_t profile[1]; sdp_list_t *aproto, *proto[3]; sdp_data_t *channel, *lang_lst, *lang_lst2, *hid_spec_lst, *hid_spec_lst2; int i; uint8_t dtd = SDP_UINT16; uint8_t dtd2 = SDP_UINT8; uint8_t dtd_data = SDP_TEXT_STR8; void *dtds[2]; void *values[2]; void *dtds2[2]; void *values2[2]; int leng[2]; uint8_t hid_spec_type = 0x22; uint16_t hid_attr_lang[] = {0x409,0x100}; uint16_t value_int = 0; static const uint16_t ctrl = 0x11; static const uint16_t intr = 0x13; static const uint16_t hid_release_num = 0x100; static const uint16_t hid_parser_version = 0x111; static const uint8_t hid_dev_subclass = 0x40; static const uint8_t hid_country_code = 0x4; static const uint8_t hid_virtual_cable = 0x0; static const uint8_t hid_reconn_initiate = 0x1; static const uint8_t hid_sdp_disable = 0x0; static const uint8_t hid_batt_power = 0x1; static const uint8_t hid_remote_wake = 0x0; static const uint16_t hid_profile_version = 0x100; static const uint16_t hid_superv_timeout = 0x1f40; static const uint8_t hid_normally_connectable = 0x0; static const uint8_t hid_boot_device = 0x1; static const uint8_t hid_spec[] = { /* Generic keyboard */ 0x05, 0x01, /* Usage Page (Desktop), */ 0x09, 0x06, /* Usage (Keyboard), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x01, /* Report ID (1), */ 0x05, 0x07, /* Usage Page (Keyboard), */ 0x19, 0xE0, /* Usage Minimum (KB Leftcontrol), */ 0x29, 0xE7, /* Usage Maximum (KB Right GUI), */ 0x15, 0x00, /* Logical Minimum (0), */ 0x25, 0x01, /* Logical Maximum (1), */ 0x75, 0x01, /* Report Size (1), */ 0x95, 0x08, /* Report Count (8), */ 0x81, 0x02, /* Input (Variable), */ 0x95, 0x01, /* Report Count (1), */ 0x75, 0x08, /* Report Size (8), */ 0x81, 0x01, /* Input (Constant), */ 0x95, 0x05, /* Report Count (5), */ 0x75, 0x01, /* Report Size (1), */ 0x05, 0x08, /* Usage Page (LED), */ 0x19, 0x01, /* Usage Minimum (01h), */ 0x29, 0x05, /* Usage Maximum (05h), */ 0x91, 0x02, /* Output (Variable), */ 0x95, 0x01, /* Report Count (1), */ 0x75, 0x03, /* Report Size (3), */ 0x91, 0x01, /* Output (Constant), */ 0x95, 0x06, /* Report Count (6), */ 0x75, 0x08, /* Report Size (8), */ 0x15, 0x00, /* Logical Minimum (0), */ 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ 0x05, 0x07, /* Usage Page (Keyboard), */ 0x19, 0x00, /* Usage Minimum (None), */ 0x29, 0xE7, /* Usage Maximum (KB Right GUI), */ 0x81, 0x00, /* Input, */ /* Consumer specific - volume / mute */ 0xC0, /* End Collection, */ 0x05, 0x0C, /* Usage Page (Consumer), */ 0x09, 0x01, /* Usage (Consumer Control), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x01, /* Report ID (1), */ 0x09, 0xE0, /* Usage (Volume), */ 0x15, 0xE8, /* Logical Minimum (-24), */ 0x25, 0x18, /* Logical Maximum (24), */ 0x75, 0x07, /* Report Size (7), */ 0x95, 0x01, /* Report Count (1), */ 0x81, 0x06, /* Input (Variable, Relative), */ 0x15, 0x00, /* Logical Minimum (0), */ 0x25, 0x01, /* Logical Maximum (1), */ 0x75, 0x01, /* Report Size (1), */ 0x09, 0xE2, /* Usage (Mute), */ 0x81, 0x06, /* Input (Variable, Relative), */ 0xC0, /* End Collection, */ /* Consumer specific - media controls */ 0x05, 0x0C, /* Usage Page (Consumer), */ 0x09, 0x01, /* Usage (Consumer Control), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x03, /* Report ID (3), */ 0x15, 0x00, /* Logical Minimum (0), */ 0x25, 0x01, /* Logical Maximum (1), */ 0x75, 0x01, /* Report Size (1), */ 0x95, 0x01, /* Report Count (1), */ 0x0A, 0x27, 0x02, /* Usage (AC Refresh), */ 0x81, 0x06, /* Input (Variable, Relative), */ 0x0A, 0x94, 0x01, /* Usage (AL Local Machine Brwsr), */ 0x81, 0x06, /* Input (Variable, Relative), */ 0x0A, 0x23, 0x02, /* Usage (AC Home), */ 0x81, 0x06, /* Input (Variable, Relative), */ 0x0A, 0x8A, 0x01, /* Usage (AL Email Reader), */ 0x81, 0x06, /* Input (Variable, Relative), */ 0x0A, 0x92, 0x01, /* Usage (AL Calculator), */ 0x81, 0x06, /* Input (Variable, Relative), */ 0x0A, 0x26, 0x02, /* Usage (AC Stop), */ 0x81, 0x06, /* Input (Variable, Relative), */ 0x0A, 0x25, 0x02, /* Usage (AC Forward), */ 0x81, 0x06, /* Input (Variable, Relative), */ 0x0A, 0x24, 0x02, /* Usage (AC Back), */ 0x81, 0x06, /* Input (Variable, Relative), */ 0x09, 0xB5, /* Usage (Scan Next Track), */ 0x81, 0x06, /* Input (Variable, Relative), */ 0x09, 0xB6, /* Usage (Scan Previous Track), */ 0x81, 0x06, /* Input (Variable, Relative), */ 0x09, 0xCD, /* Usage (Play Pause), */ 0x81, 0x06, /* Input (Variable, Relative), */ 0x09, 0xB7, /* Usage (Stop), */ 0x81, 0x06, /* Input (Variable, Relative), */ 0x0A, 0x83, 0x01, /* Usage (AL Consumer Control Config), */ 0x81, 0x06, /* Input (Variable, Relative), */ 0x95, 0x0B, /* Report Count (11), */ 0x81, 0x01, /* Input (Constant), */ 0xC0, /* End Collection */ /* Generic mouse pointer */ 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ 0x09, 0x02, /* USAGE (Mouse) */ 0xa1, 0x01, /* COLLECTION (Application) */ 0x85, 0x02, /* Report ID (2), */ 0x09, 0x01, /* USAGE (Pointer) */ 0xa1, 0x00, /* COLLECTION (Physical) */ 0x05, 0x09, /* USAGE_PAGE (Button) */ 0x19, 0x01, /* USAGE_MINIMUM (Button 1) */ 0x29, 0x03, /* USAGE_MAXIMUM (Button 3) */ 0x15, 0x00, /* LOGICAL_MINIMUM (0) */ 0x25, 0x01, /* LOGICAL_MAXIMUM (1) */ 0x95, 0x03, /* REPORT_COUNT (3) */ 0x75, 0x01, /* REPORT_SIZE (1) */ 0x81, 0x02, /* INPUT (Data,Var,Abs) */ 0x95, 0x01, /* REPORT_COUNT (1) */ 0x75, 0x05, /* REPORT_SIZE (5) */ 0x81, 0x03, /* INPUT (Cnst,Var,Abs) */ 0x05, 0x01, /* USAGE_PAGE (Generic Desktop) */ 0x09, 0x30, /* USAGE (X) */ 0x09, 0x31, /* USAGE (Y) */ 0x15, 0x81, /* LOGICAL_MINIMUM (-127) */ 0x25, 0x7f, /* LOGICAL_MAXIMUM (127) */ 0x75, 0x08, /* REPORT_SIZE (8) */ 0x95, 0x02, /* REPORT_COUNT (2) */ 0x81, 0x06, /* INPUT (Data,Var,Rel) */ 0xc0, /* END_COLLECTION */ 0xc0 /* END_COLLECTION */ }; sdp_record = sdp_record_alloc(); if (!sdp_record) { return NULL; } memset((void*)sdp_record, 0, sizeof(sdp_record_t)); sdp_record->handle = 0xffffffff; sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); root = sdp_list_append(0, &root_uuid); sdp_set_browse_groups(sdp_record, root); add_lang_attr(sdp_record); sdp_uuid16_create(&hidkb_uuid, HID_SVCLASS_ID); svclass_id = sdp_list_append(0, &hidkb_uuid); sdp_set_service_classes(sdp_record, svclass_id); sdp_uuid16_create(&profile[0].uuid, HID_PROFILE_ID); profile[0].version = 0x0100; pfseq = sdp_list_append(0, profile); sdp_set_profile_descs(sdp_record, pfseq); /* PROTO */ sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); proto[1] = sdp_list_append(0, &l2cap_uuid); channel = sdp_data_alloc(SDP_UINT8, &ctrl); proto[1] = sdp_list_append(proto[1], channel); apseq = sdp_list_append(0, proto[1]); sdp_uuid16_create(&hidp_uuid, HIDP_UUID); proto[2] = sdp_list_append(0, &hidp_uuid); apseq = sdp_list_append(apseq, proto[2]); aproto = sdp_list_append(0, apseq); sdp_set_access_protos(sdp_record, aproto); /* ATTR_ADD_PROTO */ proto[1] = sdp_list_append(0, &l2cap_uuid); channel = sdp_data_alloc(SDP_UINT8, &intr); proto[1] = sdp_list_append(proto[1], channel); apseq = sdp_list_append(0, proto[1]); sdp_uuid16_create(&hidp_uuid, HIDP_UUID); proto[2] = sdp_list_append(0, &hidp_uuid); apseq = sdp_list_append(apseq, proto[2]); aproto = sdp_list_append(0, apseq); sdp_set_add_access_protos(sdp_record, aproto); sdp_set_info_attr(sdp_record, "Android Bluetooth Keyboard", "", "HID device over Bluetooth for Android"); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_DEVICE_RELEASE_NUMBER, SDP_UINT16, &hid_release_num); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_PARSER_VERSION, SDP_UINT16, &hid_parser_version); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_DEVICE_SUBCLASS, SDP_UINT8, &hid_dev_subclass); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_COUNTRY_CODE, SDP_UINT8, &hid_country_code); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_VIRTUAL_CABLE, SDP_BOOL, &hid_virtual_cable); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_RECONNECT_INITIATE, SDP_BOOL, &hid_reconn_initiate); dtds[0] = &dtd2; values[0] = &hid_spec_type; dtds[1] = &dtd_data; values[1] = (uint8_t*)hid_spec; leng[0] = 0; leng[1] = sizeof(hid_spec); hid_spec_lst = sdp_seq_alloc_with_length(dtds, values, leng, 2); hid_spec_lst2 = sdp_data_alloc(SDP_SEQ8, hid_spec_lst); sdp_attr_add(sdp_record, SDP_ATTR_HID_DESCRIPTOR_LIST, hid_spec_lst2); for (i = 0; i < sizeof(hid_attr_lang)/2; i++) { dtds2[i] = &dtd; values2[i] = &hid_attr_lang[i]; } lang_lst = sdp_seq_alloc(dtds2, values2, sizeof(hid_attr_lang)/2); lang_lst2 = sdp_data_alloc(SDP_SEQ8, lang_lst); sdp_attr_add(sdp_record, SDP_ATTR_HID_LANG_ID_BASE_LIST, lang_lst2); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_SDP_DISABLE, SDP_BOOL, &hid_sdp_disable); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_BATTERY_POWER, SDP_BOOL, &hid_batt_power); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_REMOTE_WAKEUP, SDP_BOOL, &hid_remote_wake); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_PROFILE_VERSION, SDP_UINT16, &hid_profile_version); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_SUPERVISION_TIMEOUT, SDP_UINT16, &hid_superv_timeout); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_NORMALLY_CONNECTABLE, SDP_BOOL, &hid_normally_connectable); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_BOOT_DEVICE, SDP_BOOL, &hid_boot_device); return sdp_record; }
/** * Creates the SDP record for BD remtoe HID emulation. Probably works with PS3 only (experimental) */ static sdp_record_t *create_hid_bdremote_record() { sdp_record_t *sdp_record; sdp_list_t *svclass_id, *pfseq, *apseq, *root; uuid_t root_uuid, hidkb_uuid, l2cap_uuid, hidp_uuid; sdp_profile_desc_t profile[1]; sdp_list_t *aproto, *proto[3]; sdp_data_t *channel, *lang_lst, *lang_lst2, *hid_spec_lst, *hid_spec_lst2; int i; uint8_t dtd = SDP_UINT16; uint8_t dtd2 = SDP_UINT8; uint8_t dtd_data = SDP_TEXT_STR8; void *dtds[2]; void *values[2]; void *dtds2[2]; void *values2[2]; int leng[2]; uint8_t hid_spec_type = 0x22; uint16_t hid_attr_lang[] = {0x409,0x100}; uint16_t value_int = 0; static const uint16_t ctrl = 0x11; static const uint16_t intr = 0x13; static const uint16_t hid_release_num = 0x100; static const uint16_t hid_parser_version = 0x111; static const uint8_t hid_dev_subclass = 0x0c; static const uint8_t hid_country_code = 0x21; static const uint8_t hid_virtual_cable = 0x1; static const uint8_t hid_reconn_initiate = 0x1; static const uint8_t hid_sdp_disable = 0x0; static const uint8_t hid_batt_power = 0x1; static const uint8_t hid_remote_wake = 0x1; static const uint16_t hid_profile_version = 0x100; static const uint16_t hid_superv_timeout = 0x1f40; static const uint8_t hid_normally_connectable = 0x0; static const uint8_t hid_boot_device = 0x10; const uint8_t hid_spec[] = { /* PS3 blu-ray remote */ 0x05, 0x01, /* Usage Page (Generic Desktop) */ 0x09, 0x05, /* Usage ID (Game Pad) */ 0xa1, 0x01, /* Collection (Application) */ 0x85, 0x01, /* Report ID (1) */ 0x15, 0x00, /* Logical Minimum (0) */ 0x26, 0xff, 0x00, /* Logical Maximum (255) */ 0x75, 0x08, /* Report Size (8) */ 0x95, 0x0b, /* Report Count (11) */ 0x06, 0x00, 0xff, /* Usage Page (Vendor Defined Page 1) */ 0x09, 0x01, /* Usage (Vendor Usage 1) */ 0x81, 0x00, /* Input (Data,Array,Absolute) */ 0x85, 0x01, /* Report ID (1) */ 0x95, 0x0b, /* Report Count (11) */ 0x09, 0x01, /* Usage (Vendor Usage 1) */ 0xb1, 0x00, /* Feature (Data,Array,Absolute) */ 0x85, 0x02, /* Report ID (2) */ 0x95, 0x0b, /* Report Count (11) */ 0x09, 0x01, /* Usage (Vendor Usage 1) */ 0xb1, 0x00, /* Feature (Data,Array,Absolute) */ 0x85, 0x03, /* Report ID (3) */ 0x95, 0x0b, /* Report Count (11) */ 0x09, 0x01, /* Usage (Vendor Usage 1) */ 0xb1, 0x00, /* Feature (Data,Array,Absolute) */ 0x85, 0x04, /* Report ID (4) */ 0x95, 0x0b, /* Report Count (11) */ 0x09, 0x01, /* Usage (Vendor Usage 1) */ 0xb1, 0x00, /* Feature (Data,Array,Absolute) */ 0x85, 0x05, /* Report ID (5) */ 0x95, 0x0b, /* Report count (11) */ 0x09, 0x01, /* Usage (Vendor Usage 1) */ 0xb1, 0x00, /* Feature (Data,Array,Absolute) */ 0x85, 0x06, /* Report ID (6) */ 0x95, 0x0b, /* Report count (11) */ 0x09, 0x01, /* Usage (Vendor Usage 1) */ 0xb1, 0x00, /* Feature (Data,Array,Absolute) */ 0xc0 /* End Collection */ }; sdp_record = sdp_record_alloc(); if (!sdp_record) { return NULL; } memset((void*)sdp_record, 0, sizeof(sdp_record_t)); sdp_record->handle = 0xffffffff; sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); root = sdp_list_append(0, &root_uuid); sdp_set_browse_groups(sdp_record, root); add_lang_attr(sdp_record); sdp_uuid16_create(&hidkb_uuid, HID_SVCLASS_ID); svclass_id = sdp_list_append(0, &hidkb_uuid); sdp_set_service_classes(sdp_record, svclass_id); sdp_uuid16_create(&profile[0].uuid, HID_PROFILE_ID); profile[0].version = 0x0100; pfseq = sdp_list_append(0, profile); sdp_set_profile_descs(sdp_record, pfseq); /* PROTO */ sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); proto[1] = sdp_list_append(0, &l2cap_uuid); channel = sdp_data_alloc(SDP_UINT8, &ctrl); proto[1] = sdp_list_append(proto[1], channel); apseq = sdp_list_append(0, proto[1]); sdp_uuid16_create(&hidp_uuid, HIDP_UUID); proto[2] = sdp_list_append(0, &hidp_uuid); apseq = sdp_list_append(apseq, proto[2]); aproto = sdp_list_append(0, apseq); sdp_set_access_protos(sdp_record, aproto); /* ATTR_ADD_PROTO */ proto[1] = sdp_list_append(0, &l2cap_uuid); channel = sdp_data_alloc(SDP_UINT8, &intr); proto[1] = sdp_list_append(proto[1], channel); apseq = sdp_list_append(0, proto[1]); sdp_uuid16_create(&hidp_uuid, HIDP_UUID); proto[2] = sdp_list_append(0, &hidp_uuid); apseq = sdp_list_append(apseq, proto[2]); aproto = sdp_list_append(0, apseq); sdp_set_add_access_protos(sdp_record, aproto); sdp_set_info_attr(sdp_record, "Android Bluetooth Keyboard", "", "HID device over Bluetooth for Android"); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_DEVICE_RELEASE_NUMBER, SDP_UINT16, &hid_release_num); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_PARSER_VERSION, SDP_UINT16, &hid_parser_version); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_DEVICE_SUBCLASS, SDP_UINT8, &hid_dev_subclass); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_COUNTRY_CODE, SDP_UINT8, &hid_country_code); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_VIRTUAL_CABLE, SDP_BOOL, &hid_virtual_cable); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_RECONNECT_INITIATE, SDP_BOOL, &hid_reconn_initiate); dtds[0] = &dtd2; values[0] = &hid_spec_type; dtds[1] = &dtd_data; values[1] = (uint8_t*)hid_spec; leng[0] = 0; leng[1] = sizeof(hid_spec); hid_spec_lst = sdp_seq_alloc_with_length(dtds, values, leng, 2); hid_spec_lst2 = sdp_data_alloc(SDP_SEQ8, hid_spec_lst); sdp_attr_add(sdp_record, SDP_ATTR_HID_DESCRIPTOR_LIST, hid_spec_lst2); for (i = 0; i < sizeof(hid_attr_lang)/2; i++) { dtds2[i] = &dtd; values2[i] = &hid_attr_lang[i]; } lang_lst = sdp_seq_alloc(dtds2, values2, sizeof(hid_attr_lang)/2); lang_lst2 = sdp_data_alloc(SDP_SEQ8, lang_lst); sdp_attr_add(sdp_record, SDP_ATTR_HID_LANG_ID_BASE_LIST, lang_lst2); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_SDP_DISABLE, SDP_BOOL, &hid_sdp_disable); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_BATTERY_POWER, SDP_BOOL, &hid_batt_power); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_REMOTE_WAKEUP, SDP_BOOL, &hid_remote_wake); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_PROFILE_VERSION, SDP_UINT16, &hid_profile_version); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_SUPERVISION_TIMEOUT, SDP_UINT16, &hid_superv_timeout); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_NORMALLY_CONNECTABLE, SDP_BOOL, &hid_normally_connectable); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_BOOT_DEVICE, SDP_BOOL, &hid_boot_device); return sdp_record; }
/** * Creates the SDP record for PS3 keypad HID emulation. Works well with many different * clients: windows, linux (ubuntu), PS3, and motorola android devices. */ static sdp_record_t *create_hid_ps3_keypad_record() { sdp_record_t *sdp_record; sdp_list_t *svclass_id, *pfseq, *apseq, *root; uuid_t root_uuid, hidkb_uuid, l2cap_uuid, hidp_uuid; sdp_profile_desc_t profile[1]; sdp_list_t *aproto, *proto[3]; sdp_data_t *channel, *lang_lst, *lang_lst2, *hid_spec_lst, *hid_spec_lst2; int i; uint8_t dtd = SDP_UINT16; uint8_t dtd2 = SDP_UINT8; uint8_t dtd_data = SDP_TEXT_STR8; void *dtds[2]; void *values[2]; void *dtds2[2]; void *values2[2]; int leng[2]; uint8_t hid_spec_type = 0x22; uint16_t hid_attr_lang[] = {0x409,0x100}; uint16_t value_int = 0; static const uint16_t ctrl = 0x11; static const uint16_t intr = 0x13; static const uint16_t hid_release_num = 0x100; static const uint16_t hid_parser_version = 0x111; static const uint8_t hid_dev_subclass = 0x40; static const uint8_t hid_country_code = 0x4; static const uint8_t hid_virtual_cable = 0x0; static const uint8_t hid_reconn_initiate = 0x1; static const uint8_t hid_sdp_disable = 0x0; static const uint8_t hid_batt_power = 0x1; static const uint8_t hid_remote_wake = 0x0; static const uint16_t hid_profile_version = 0x100; static const uint16_t hid_superv_timeout = 0x1f40; static const uint8_t hid_normally_connectable = 0x0; static const uint8_t hid_boot_device = 0x1; static const uint8_t hid_spec[] = { /* Pointer (mouse) */ 0x05, 0x01, /* Usage Page (Desktop), */ 0x09, 0x02, /* Usage (Mouse), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x02, /* Report ID (2), */ 0x09, 0x01, /* Usage (Pointer), */ 0xA1, 0x00, /* Collection (Physical), */ 0x05, 0x09, /* Usage Page (Button), */ 0x19, 0x01, /* Usage Minimum (01h), */ 0x29, 0x02, /* Usage Maximum (02h), */ 0x15, 0x00, /* Logical Minimum (0), */ 0x25, 0x01, /* Logical Maximum (1), */ 0x95, 0x02, /* Report Count (2), */ 0x75, 0x01, /* Report Size (1), */ 0x81, 0x02, /* Input (Variable), */ 0x95, 0x01, /* Report Count (1), */ 0x75, 0x06, /* Report Size (6), */ 0x81, 0x03, /* Input (Constant, Variable), */ 0x05, 0x01, /* Usage Page (Desktop), */ 0x09, 0x30, /* Usage (X), */ 0x09, 0x31, /* Usage (Y), */ 0x15, 0x81, /* Logical Minimum (-127), */ 0x25, 0x7F, /* Logical Maximum (127), */ 0x75, 0x08, /* Report Size (8), */ 0x95, 0x02, /* Report Count (2), */ 0x81, 0x06, /* Input (Variable, Relative), */ 0x75, 0x08, /* Report Size (8), */ 0x95, 0x01, /* Report Count (1), */ 0x81, 0x01, /* Input (Constant), */ 0x06, 0x00, 0xFF, /* Usage Page (FF00h), */ 0x09, 0x20, /* Usage (20h), */ 0x15, 0x00, /* Logical Minimum (0), */ 0x26, 0xFF, 0x0F, /* Logical Maximum (4095), */ 0x75, 0x0C, /* Report Size (12), */ 0x95, 0x02, /* Report Count (2), */ 0x81, 0x02, /* Input (Variable), */ 0x09, 0x21, /* Usage (21h), */ 0x15, 0x00, /* Logical Minimum (0), */ 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ 0x75, 0x08, /* Report Size (8), */ 0x95, 0x01, /* Report Count (1), */ 0x81, 0x02, /* Input (Variable), */ 0xC0, /* End Collection, */ 0xC0, /* End Collection, */ /* Keyboard */ 0x05, 0x01, /* Usage Page (Desktop), */ 0x09, 0x06, /* Usage (Keyboard), */ 0xA1, 0x01, /* Collection (Application), */ 0x85, 0x01, /* Report ID (1), */ 0x05, 0x07, /* Usage Page (Keyboard), */ 0x19, 0xE0, /* Usage Minimum (KB Leftcontrol), */ 0x29, 0xE7, /* Usage Maximum (KB Right GUI), */ 0x15, 0x00, /* Logical Minimum (0), */ 0x25, 0x01, /* Logical Maximum (1), */ 0x75, 0x01, /* Report Size (1), */ 0x95, 0x08, /* Report Count (8), */ 0x81, 0x02, /* Input (Variable), */ 0x95, 0x01, /* Report Count (1), */ 0x75, 0x08, /* Report Size (8), */ 0x81, 0x01, /* Input (Constant), */ 0x95, 0x05, /* Report Count (5), */ 0x75, 0x01, /* Report Size (1), */ 0x05, 0x08, /* Usage Page (LED), */ 0x19, 0x01, /* Usage Minimum (01h), */ 0x29, 0x05, /* Usage Maximum (05h), */ 0x91, 0x02, /* Output (Variable), */ 0x95, 0x01, /* Report Count (1), */ 0x75, 0x03, /* Report Size (3), */ 0x91, 0x01, /* Output (Constant), */ 0x95, 0x06, /* Report Count (6), */ 0x75, 0x08, /* Report Size (8), */ 0x15, 0x00, /* Logical Minimum (0), */ 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ 0x05, 0x07, /* Usage Page (Keyboard), */ 0x19, 0x00, /* Usage Minimum (None), */ 0x29, 0xE7, /* Usage Maximum (KB Right GUI), */ 0x81, 0x00, /* Input, */ 0xC0, /* End Collection, */ 0x06, 0x01, 0xFF, /* Usage Page (FF01h), */ 0x09, 0x20, /* Usage (20h), */ 0xA1, 0x01, /* Collection (Application), */ 0x09, 0x21, /* Usage (21h), */ 0x85, 0x03, /* Report ID (3), */ 0x75, 0x08, /* Report Size (8), */ 0x95, 0x01, /* Report Count (1), */ 0x15, 0x00, /* Logical Minimum (0), */ 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ 0x09, 0x22, /* Usage (22h), */ 0x81, 0x02, /* Input (Variable), */ 0x75, 0x08, /* Report Size (8), */ 0x95, 0x01, /* Report Count (1), */ 0x15, 0x00, /* Logical Minimum (0), */ 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ 0x09, 0x23, /* Usage (23h), */ 0x81, 0x02, /* Input (Variable), */ 0x75, 0x08, /* Report Size (8), */ 0x95, 0x06, /* Report Count (6), */ 0x81, 0x01, /* Input (Constant), */ 0x09, 0x24, /* Usage (24h), */ 0x15, 0x00, /* Logical Minimum (0), */ 0x25, 0x01, /* Logical Maximum (1), */ 0x75, 0x08, /* Report Size (8), */ 0x95, 0x01, /* Report Count (1), */ 0x91, 0x02, /* Output (Variable), */ 0xC0, /* End Collection, */ /* ?? PS3 proprietary? */ 0x06, 0x02, 0xFF, /* Usage Page (FF02h), */ 0x09, 0x20, /* Usage (20h), */ 0xA1, 0x01, /* Collection (Application), */ 0x09, 0x21, /* Usage (21h), */ 0x85, 0x04, /* Report ID (4), */ 0x15, 0x00, /* Logical Minimum (0), */ 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ 0x75, 0x08, /* Report Size (8), */ 0x95, 0x0F, /* Report Count (15), */ 0xB1, 0x02, /* Feature (Variable), */ 0x09, 0x22, /* Usage (22h), */ 0x85, 0x05, /* Report ID (5), */ 0x15, 0x00, /* Logical Minimum (0), */ 0x26, 0xFF, 0x00, /* Logical Maximum (255), */ 0x75, 0x08, /* Report Size (8), */ 0x95, 0x16, /* Report Count (22), */ 0xB1, 0x02, /* Feature (Variable), */ 0xC0 /* End Collection */ }; sdp_record = sdp_record_alloc(); if (!sdp_record) { return NULL; } memset((void*)sdp_record, 0, sizeof(sdp_record_t)); sdp_record->handle = 0xffffffff; sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); root = sdp_list_append(0, &root_uuid); sdp_set_browse_groups(sdp_record, root); add_lang_attr(sdp_record); sdp_uuid16_create(&hidkb_uuid, HID_SVCLASS_ID); svclass_id = sdp_list_append(0, &hidkb_uuid); sdp_set_service_classes(sdp_record, svclass_id); sdp_uuid16_create(&profile[0].uuid, HID_PROFILE_ID); profile[0].version = 0x0100; pfseq = sdp_list_append(0, profile); sdp_set_profile_descs(sdp_record, pfseq); /* PROTO */ sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); proto[1] = sdp_list_append(0, &l2cap_uuid); channel = sdp_data_alloc(SDP_UINT8, &ctrl); proto[1] = sdp_list_append(proto[1], channel); apseq = sdp_list_append(0, proto[1]); sdp_uuid16_create(&hidp_uuid, HIDP_UUID); proto[2] = sdp_list_append(0, &hidp_uuid); apseq = sdp_list_append(apseq, proto[2]); aproto = sdp_list_append(0, apseq); sdp_set_access_protos(sdp_record, aproto); /* ATTR_ADD_PROTO */ proto[1] = sdp_list_append(0, &l2cap_uuid); channel = sdp_data_alloc(SDP_UINT8, &intr); proto[1] = sdp_list_append(proto[1], channel); apseq = sdp_list_append(0, proto[1]); sdp_uuid16_create(&hidp_uuid, HIDP_UUID); proto[2] = sdp_list_append(0, &hidp_uuid); apseq = sdp_list_append(apseq, proto[2]); aproto = sdp_list_append(0, apseq); sdp_set_add_access_protos(sdp_record, aproto); sdp_set_info_attr(sdp_record, "Android PS3 Bluetooth Keypad", "", "PS3 compatible HID device over Bluetooth for Android"); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_DEVICE_RELEASE_NUMBER, SDP_UINT16, &hid_release_num); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_PARSER_VERSION, SDP_UINT16, &hid_parser_version); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_DEVICE_SUBCLASS, SDP_UINT8, &hid_dev_subclass); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_COUNTRY_CODE, SDP_UINT8, &hid_country_code); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_VIRTUAL_CABLE, SDP_BOOL, &hid_virtual_cable); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_RECONNECT_INITIATE, SDP_BOOL, &hid_reconn_initiate); dtds[0] = &dtd2; values[0] = &hid_spec_type; dtds[1] = &dtd_data; values[1] = (uint8_t*)hid_spec; leng[0] = 0; leng[1] = sizeof(hid_spec); hid_spec_lst = sdp_seq_alloc_with_length(dtds, values, leng, 2); hid_spec_lst2 = sdp_data_alloc(SDP_SEQ8, hid_spec_lst); sdp_attr_add(sdp_record, SDP_ATTR_HID_DESCRIPTOR_LIST, hid_spec_lst2); for (i = 0; i < sizeof(hid_attr_lang)/2; i++) { dtds2[i] = &dtd; values2[i] = &hid_attr_lang[i]; } lang_lst = sdp_seq_alloc(dtds2, values2, sizeof(hid_attr_lang)/2); lang_lst2 = sdp_data_alloc(SDP_SEQ8, lang_lst); sdp_attr_add(sdp_record, SDP_ATTR_HID_LANG_ID_BASE_LIST, lang_lst2); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_SDP_DISABLE, SDP_BOOL, &hid_sdp_disable); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_BATTERY_POWER, SDP_BOOL, &hid_batt_power); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_REMOTE_WAKEUP, SDP_BOOL, &hid_remote_wake); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_PROFILE_VERSION, SDP_UINT16, &hid_profile_version); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_SUPERVISION_TIMEOUT, SDP_UINT16, &hid_superv_timeout); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_NORMALLY_CONNECTABLE, SDP_BOOL, &hid_normally_connectable); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_BOOT_DEVICE, SDP_BOOL, &hid_boot_device); return sdp_record; }
static int register_service_additional_protocols(sdp_record_t *rec, struct health_app *app) { int ret = -1; uuid_t l2cap_uuid, mcap_d_uuid; sdp_list_t *l2cap_list, *proto_list = NULL, *mcap_list = NULL; sdp_list_t *access_proto_list = NULL; sdp_data_t *psm = NULL; uint32_t dcpsm; GError *err = NULL; DBG(""); /* set l2cap information */ sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); l2cap_list = sdp_list_append(NULL, &l2cap_uuid); if (!l2cap_list) goto fail; dcpsm = mcap_get_data_psm(mcap, &err); if (err) goto fail; psm = sdp_data_alloc(SDP_UINT16, &dcpsm); if (!psm) goto fail; if (!sdp_list_append(l2cap_list, psm)) goto fail; proto_list = sdp_list_append(NULL, l2cap_list); if (!proto_list) goto fail; /* set mcap information */ sdp_uuid16_create(&mcap_d_uuid, MCAP_DATA_UUID); mcap_list = sdp_list_append(NULL, &mcap_d_uuid); if (!mcap_list) goto fail; if (!sdp_list_append(proto_list, mcap_list)) goto fail; /* attach protocol information to service record */ access_proto_list = sdp_list_append(NULL, proto_list); if (!access_proto_list) goto fail; sdp_set_add_access_protos(rec, access_proto_list); ret = 0; fail: sdp_list_free(l2cap_list, NULL); sdp_list_free(mcap_list, NULL); sdp_list_free(proto_list, NULL); sdp_list_free(access_proto_list, NULL); if (psm) sdp_data_free(psm); if (err) g_error_free(err); return ret; }
int register_record(int descriptor_is_relative){ // Connect to to local SDP-Servicer on localhost, to publish // the new service record. // Session will be established. sdp_session_t *session; session = sdp_connect ( BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY ); if ( ! session ) { // LOGCAT: __android_log_print(ANDROID_LOG_DEBUG, TAG, "SDP: Connection to SDP failed."); return CODE_SDP_SESSION_FAILED; } // LOGCAT: __android_log_print(ANDROID_LOG_DEBUG, TAG, "SDP: Connection to SDP established."); // Service record, to be included in the registry of the SDP-Server sdp_record_t record; // To create the record, several lists must be put together sdp_list_t *languages, *service_class_id, *profile_sequence, *access_protocol_sequence, *root_list, *access_protocol, *protocol_list[3]; // The uuid_t data type is used to represent the 128-bit UUID that // is used as un universal unique identifier. SEE THE THESIS, SUBSECTION 2.2.2 uuid_t root_uuid, hid_uuid, l2cap_uuid, hidp_uuid; // BluetoothProfileDescriptorList. SEE THE THESIS, SUBSECTION 4.2.6 sdp_profile_desc_t sdp_profile[1]; // LanguageBaseAttributeIDList, SEE THE THESIS, SUBSECTION 4.2.4 sdp_lang_attr_t base_language; // The sdp_data_t structure stores information in a service record sdp_data_t *psm, *hid_descriptor_list, *hid_descriptor_formatted_list, *language_base_list, *language_base_formatted_list; // SDP-specific types: 8- and 16- bit unsigned integers and a 8-bit string uint8_t data_type_uint8 = SDP_UINT8; uint8_t data_type_uint16 = SDP_UINT16; uint8_t data_type_str8 = SDP_TEXT_STR8; int length[2]; // arrays used to form the sdp specific strcuture of sequence attribites: descriptor and language base void *data_types[2] , *descriptor_array[2], *language_base_array[2]; memset(&record, 0, sizeof(sdp_record_t)); // Assigning the Record Handle, SEE THE THESIS, SUBSECTION 4.2.2 record.handle = handle; // Putting together attributes, common to all services. // SEE THE THESIS, SECTION 4.2 // Setting the Browse Group and making // the service record publicly available. // SEE THE THESIS, SUBSECTION 4.2.3 sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); root_list = sdp_list_append(0, &root_uuid); sdp_set_browse_groups( &record, root_list ); // The LanguageBaseAttributeIDList // SEE THE THESIS, SUBSECTION 4.2.4 base_language.code_ISO639 = (0x65 << 8) | 0x6e; base_language.base_offset = SDP_PRIMARY_LANG_BASE; base_language.encoding = 106; languages = sdp_list_append(0, &base_language); sdp_set_lang_attr(&record, languages); sdp_list_free(languages, 0); // The ServiceClassIDList // SEE THE THESIS, SUBSECTION 4.2.1 sdp_uuid16_create(&hid_uuid, HID_SVCLASS_ID); service_class_id = sdp_list_append(0, &hid_uuid); sdp_set_service_classes(&record, service_class_id); // The BluetoothProfileDescriptorList // SEE THE THESIS, SUBSECTION 4.2.6 sdp_uuid16_create(&sdp_profile[0].uuid, HID_PROFILE_ID); sdp_profile[0].version = 0x0100; profile_sequence = sdp_list_append(0, sdp_profile); sdp_set_profile_descs(&record, profile_sequence); // The ProtocolDescriptorList // SEE THE THESIS, SUBSECTION 4.2.5 // We set information about: // A) Control Channel -> // B) Interruption Channel // We use the protocol_list to bind information // about L2CAP and HID stack level // A) Control Channel (PSM: 0x11) // 1) Set info on L2CAP sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); protocol_list[1] = sdp_list_append(0, &l2cap_uuid); psm = sdp_data_alloc(SDP_UINT16, &control_channel_psm); protocol_list[1] = sdp_list_append(protocol_list[1], psm); access_protocol_sequence = sdp_list_append(0, protocol_list[1]); // 2) Set info on HID sdp_uuid16_create(&hidp_uuid, HIDP_UUID); protocol_list[2] = sdp_list_append(0, &hidp_uuid); access_protocol_sequence = sdp_list_append(access_protocol_sequence, protocol_list[2]); // bind to DecriptorList access_protocol = sdp_list_append(0, access_protocol_sequence); sdp_set_access_protos(&record, access_protocol); // B) Interruption Channel (PSM: 0x13) // 1) Set info on L2CAP protocol_list[1] = sdp_list_append(0, &l2cap_uuid); psm = sdp_data_alloc(SDP_UINT16, &interruption_channel_psm); protocol_list[1] = sdp_list_append(protocol_list[1], psm); access_protocol_sequence = sdp_list_append(0, protocol_list[1]); // 2) Set info on HID sdp_uuid16_create(&hidp_uuid, HIDP_UUID); protocol_list[2] = sdp_list_append(0, &hidp_uuid); access_protocol_sequence = sdp_list_append(access_protocol_sequence, protocol_list[2]); access_protocol = sdp_list_append(0, access_protocol_sequence); sdp_set_add_access_protos(&record, access_protocol); // Setting the information on device, author and service, // throuth the human-readable attributes // SEE THE THESIS, SUBSECTION 4.2.4 sdp_set_info_attr(&record, SERVICE_NAME, SERVICE_INFO, AUTHOR_INFO); // After putting together the attributes, common to all services, // we bind the attributes that are specific to the HID service. // SEE THE THESIS, SECTION 4.3 // Adding all HID attributes (mandatory or optional) // explained in the THESIS (4.3.1 - 4.3.13) // SEE THE THESIS, SUBSECTION 4.3.1 if(descriptor_is_relative){ sdp_attr_add_new( &record, SDP_ATTR_HID_DEVICE_RELEASE_NUMBER, SDP_UINT16, &attr_release_number_mouse_keyboard); }else{ sdp_attr_add_new( &record, SDP_ATTR_HID_DEVICE_RELEASE_NUMBER, SDP_UINT16, &attr_release_number_pointer_keyboard); } // SEE THE THESIS, SUBSECTION 4.3.2 sdp_attr_add_new( &record, SDP_ATTR_HID_PARSER_VERSION, SDP_UINT16, &attr_parser_version); // SEE THE THESIS, SUBSECTION 4.3.3 sdp_attr_add_new( &record, SDP_ATTR_HID_DEVICE_SUBCLASS, SDP_UINT8, &attr_device_subclass); // SEE THE THESIS, SUBSECTION 4.3.4 sdp_attr_add_new( &record, SDP_ATTR_HID_COUNTRY_CODE, SDP_UINT8, &attr_country_code); // SEE THE THESIS, SUBSECTION 4.3.5 sdp_attr_add_new( &record, SDP_ATTR_HID_VIRTUAL_CABLE, SDP_BOOL, &attr_virtual_cable); // SEE THE THESIS, SUBSECTION 4.3.6 sdp_attr_add_new( &record, SDP_ATTR_HID_RECONNECT_INITIATE, SDP_BOOL, &attr_reconnect_initiate); // SEE THE THESIS, SUBSECTION 4.3.13 // Adding the HIDDescriptorList attribute is more complex, // thus it is data sequence. // // The attribute contains two things: // A) The descriptor type as unsigned integer (In our case it is a report descriptor) // B) The two descriptors as string sequence (keyboard + mouse or keyboard + pointer) data_types[0] = &data_type_uint8; data_types[1] = &data_type_str8; // We check the descriptor_is_realtive value to // find out, if the keyboard + mouse or keyboard + pointer // service description is to be added. if(descriptor_is_relative){ descriptor_array[0] = &hid_descriptor_type; descriptor_array[1] =(uint8_t *) attr_hid_descriptor_relative; length[0] = 0; length[1] = sizeof(attr_hid_descriptor_relative); }else{ descriptor_array[0] = &hid_descriptor_type; descriptor_array[1] =(uint8_t *) attr_hid_descriptor_absolute; length[0] = 0; length[1] = sizeof(attr_hid_descriptor_absolute); } // We bind the array containing the type and the array containing the values // with the sdp_seq_alloc_with_length function hid_descriptor_list = sdp_seq_alloc_with_length( data_types, descriptor_array, length, 2 ); // The newly created array contains all information, so it is used to create // the list from the right SDP-specific type (SDP_SEQ8) hid_descriptor_formatted_list = sdp_data_alloc( SDP_SEQ8, hid_descriptor_list ); // Finally the list is added as un SDP-attribute sdp_attr_add( &record, SDP_ATTR_HID_DESCRIPTOR_LIST, hid_descriptor_formatted_list ); // Done! // The same is also done with the HIDLANGIDBaseList // SEE THE THESIS, SUBSECTION 4.3.12 data_types[0] = &data_type_uint16; data_types[1] = &data_type_uint16; language_base_array[0] = &attr_language_base[0]; language_base_array[1] = &attr_language_base[1]; //sizeof(attr_language_base) is devided by two, since values are 16-bit integers (not 8-bit like with the HIDDecriptorList) language_base_list = sdp_seq_alloc(data_types, language_base_array, sizeof(attr_language_base) / 2); language_base_formatted_list = sdp_data_alloc(SDP_SEQ8, language_base_list); sdp_attr_add(&record, SDP_ATTR_HID_LANG_ID_BASE_LIST, language_base_formatted_list); // Done! // SEE THE THESIS, SUBSECTION 4.3.7 sdp_attr_add_new( &record, SDP_ATTR_HID_SDP_DISABLE, SDP_BOOL, &attr_sdp_disable); // SEE THE THESIS, SUBSECTION 4.3.8 sdp_attr_add_new( &record, SDP_ATTR_HID_BATTERY_POWER, SDP_BOOL, &attr_battery_power); // SEE THE THESIS, SUBSECTION 4.3.9 sdp_attr_add_new( &record, SDP_ATTR_HID_REMOTE_WAKEUP, SDP_BOOL, &attr_remote_wake); // SEE THE THESIS, SUBSECTION 4.3.10 sdp_attr_add_new( &record, SDP_ATTR_HID_PROFILE_VERSION, SDP_UINT16, &attr_profile_version); // sdp_attr_add_new( &record, // SDP_ATTR_HID_SUPERVISION_TIMEOUT, // SDP_UINT16, // &attr_supervision_timeout); // SEE THE THESIS, SUBSECTION 4.3.6 sdp_attr_add_new( &record, SDP_ATTR_HID_NORMALLY_CONNECTABLE, SDP_BOOL, &attr_normally_connectable); // SEE THE THESIS, SUBSECTION 4.3.11 sdp_attr_add_new( &record, SDP_ATTR_HID_BOOT_DEVICE, SDP_BOOL, &attr_boot_device); // At last the record is good to go and could be added to the sdp registry! if (sdp_record_register(session, &record, SDP_RECORD_PERSIST) < 0) { // LOGCAT: __android_log_print(ANDROID_LOG_DEBUG, TAG, "SDP: Registration of new record failed."); return CODE_RECORD_REGISTRATION_FAILED; } // LOGCAT: __android_log_print(ANDROID_LOG_DEBUG, TAG, "SDP: Registration of new record successful."); sdp_close(session); return CODE_RECORD_REGISTERED; }
static sdp_record_t *avrcp_tg_record(void) { sdp_list_t *svclass_id, *pfseq, *apseq, *root, *apseq_browsing; uuid_t root_uuid, l2cap, avctp, avrtg; sdp_profile_desc_t profile[1]; sdp_list_t *aproto_control, *proto_control[2]; sdp_record_t *record; sdp_data_t *psm_control, *version, *features, *psm_browsing; sdp_list_t *aproto_browsing, *proto_browsing[2] = {0}; uint16_t lp = AVCTP_CONTROL_PSM; uint16_t lp_browsing = AVCTP_BROWSING_PSM; uint16_t avrcp_ver = 0x0104, avctp_ver = 0x0103; uint16_t feat = ( AVRCP_FEATURE_CATEGORY_1 | AVRCP_FEATURE_CATEGORY_2 | AVRCP_FEATURE_CATEGORY_3 | AVRCP_FEATURE_CATEGORY_4 | AVRCP_FEATURE_BROWSING | AVRCP_FEATURE_PLAYER_SETTINGS ); record = sdp_record_alloc(); if (!record) return NULL; sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); root = sdp_list_append(0, &root_uuid); sdp_set_browse_groups(record, root); /* Service Class ID List */ sdp_uuid16_create(&avrtg, AV_REMOTE_TARGET_SVCLASS_ID); svclass_id = sdp_list_append(0, &avrtg); sdp_set_service_classes(record, svclass_id); /* Protocol Descriptor List */ sdp_uuid16_create(&l2cap, L2CAP_UUID); proto_control[0] = sdp_list_append(0, &l2cap); psm_control = sdp_data_alloc(SDP_UINT16, &lp); proto_control[0] = sdp_list_append(proto_control[0], psm_control); apseq = sdp_list_append(0, proto_control[0]); sdp_uuid16_create(&avctp, AVCTP_UUID); proto_control[1] = sdp_list_append(0, &avctp); version = sdp_data_alloc(SDP_UINT16, &avctp_ver); proto_control[1] = sdp_list_append(proto_control[1], version); apseq = sdp_list_append(apseq, proto_control[1]); aproto_control = sdp_list_append(0, apseq); sdp_set_access_protos(record, aproto_control); proto_browsing[0] = sdp_list_append(0, &l2cap); psm_browsing = sdp_data_alloc(SDP_UINT16, &lp_browsing); proto_browsing[0] = sdp_list_append(proto_browsing[0], psm_browsing); apseq_browsing = sdp_list_append(0, proto_browsing[0]); proto_browsing[1] = sdp_list_append(0, &avctp); proto_browsing[1] = sdp_list_append(proto_browsing[1], version); apseq_browsing = sdp_list_append(apseq_browsing, proto_browsing[1]); aproto_browsing = sdp_list_append(0, apseq_browsing); sdp_set_add_access_protos(record, aproto_browsing); /* Bluetooth Profile Descriptor List */ sdp_uuid16_create(&profile[0].uuid, AV_REMOTE_PROFILE_ID); profile[0].version = avrcp_ver; pfseq = sdp_list_append(0, &profile[0]); sdp_set_profile_descs(record, pfseq); features = sdp_data_alloc(SDP_UINT16, &feat); sdp_attr_add(record, SDP_ATTR_SUPPORTED_FEATURES, features); sdp_set_info_attr(record, "AVRCP TG", 0, 0); free(psm_browsing); sdp_list_free(proto_browsing[0], 0); sdp_list_free(proto_browsing[1], 0); sdp_list_free(apseq_browsing, 0); sdp_list_free(aproto_browsing, 0); free(psm_control); free(version); sdp_list_free(proto_control[0], 0); sdp_list_free(proto_control[1], 0); sdp_list_free(apseq, 0); sdp_list_free(aproto_control, 0); sdp_list_free(pfseq, 0); sdp_list_free(root, 0); sdp_list_free(svclass_id, 0); return record; }
/* * add keyboard descriptor */ void sdp_add_keyboard() { sdp_list_t *svclass_id, *pfseq, *apseq, *root; uuid_t root_uuid, hidkb_uuid, l2cap_uuid, hidp_uuid; sdp_profile_desc_t profile[1]; sdp_list_t *aproto, *proto[3]; sdp_data_t *channel, *lang_lst, *lang_lst2, *hid_spec_lst, *hid_spec_lst2; int i; uint8_t dtd = SDP_UINT16; uint8_t dtd2 = SDP_UINT8; uint8_t dtd_data = SDP_TEXT_STR8; sdp_session_t *session; void *dtds[2]; void *values[2]; void *dtds2[2]; void *values2[2]; int leng[2]; uint8_t hid_spec_type = 0x22; uint16_t hid_attr_lang[] = {0x409,0x100}; static const uint8_t ctrl = 0x11; static const uint8_t intr = 0x13; static const uint16_t hid_attr[] = {0x100,0x111,0x40,0x0d,0x01,0x01}; static const uint16_t hid_attr2[] = {0x0,0x01,0x100,0x1f40,0x01,0x01}; // taken from Apple Wireless Keyboard const uint8_t hid_spec[] = { 0x05, 0x01, // usage page 0x09, 0x06, // keyboard 0xa1, 0x01, // key codes 0x85, 0x01, // minimum 0x05, 0x07, // max 0x19, 0xe0, // logical min 0x29, 0xe7, // logical max 0x15, 0x00, // report size 0x25, 0x01, // report count 0x75, 0x01, // input data variable absolute 0x95, 0x08, // report count 0x81, 0x02, // report size 0x75, 0x08, 0x95, 0x01, 0x81, 0x01, 0x75, 0x01, 0x95, 0x05, 0x05, 0x08, 0x19, 0x01, 0x29, 0x05, 0x91, 0x02, 0x75, 0x03, 0x95, 0x01, 0x91, 0x01, 0x75, 0x08, 0x95, 0x06, 0x15, 0x00, 0x26, 0xff, 0x00, 0x05, 0x07, 0x19, 0x00, 0x2a, 0xff, 0x00, 0x81, 0x00, 0x75, 0x01, 0x95, 0x01, 0x15, 0x00, 0x25, 0x01, 0x05, 0x0c, 0x09, 0xb8, 0x81, 0x06, 0x09, 0xe2, 0x81, 0x06, 0x09, 0xe9, 0x81, 0x02, 0x09, 0xea, 0x81, 0x02, 0x75, 0x01, 0x95, 0x04, 0x81, 0x01, 0xc0 // end tag }; if (!sdp_session) { printf("%s: sdp_session invalid\n", (char*)__func__); exit(-1); } session = sdp_session; sdp_record = sdp_record_alloc(); if (!sdp_record) { perror("add_keyboard sdp_record_alloc: "); exit(-1); } memset((void*)sdp_record, 0, sizeof(sdp_record_t)); sdp_record->handle = 0xffffffff; sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); root = sdp_list_append(0, &root_uuid); sdp_set_browse_groups(sdp_record, root); add_lang_attr(sdp_record); sdp_uuid16_create(&hidkb_uuid, HID_SVCLASS_ID); svclass_id = sdp_list_append(0, &hidkb_uuid); sdp_set_service_classes(sdp_record, svclass_id); sdp_uuid16_create(&profile[0].uuid, HID_PROFILE_ID); profile[0].version = 0x0100; pfseq = sdp_list_append(0, profile); sdp_set_profile_descs(sdp_record, pfseq); // PROTO sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); proto[1] = sdp_list_append(0, &l2cap_uuid); channel = sdp_data_alloc(SDP_UINT8, &ctrl); proto[1] = sdp_list_append(proto[1], channel); apseq = sdp_list_append(0, proto[1]); sdp_uuid16_create(&hidp_uuid, HIDP_UUID); proto[2] = sdp_list_append(0, &hidp_uuid); apseq = sdp_list_append(apseq, proto[2]); aproto = sdp_list_append(0, apseq); sdp_set_access_protos(sdp_record, aproto); // ATTR_ADD_PROTO proto[1] = sdp_list_append(0, &l2cap_uuid); channel = sdp_data_alloc(SDP_UINT8, &intr); proto[1] = sdp_list_append(proto[1], channel); apseq = sdp_list_append(0, proto[1]); sdp_uuid16_create(&hidp_uuid, HIDP_UUID); proto[2] = sdp_list_append(0, &hidp_uuid); apseq = sdp_list_append(apseq, proto[2]); aproto = sdp_list_append(0, apseq); sdp_set_add_access_protos(sdp_record, aproto); sdp_set_info_attr(sdp_record, "Collin's Fake Bluetooth Keyboard", "MUlliNER.ORG", "http://www.mulliner.org/bluetooth/"); for (i = 0; i < sizeof(hid_attr)/2; i++) { sdp_attr_add_new(sdp_record, SDP_ATTR_HID_DEVICE_RELEASE_NUMBER+i, SDP_UINT16, &hid_attr[i]); } dtds[0] = &dtd2; values[0] = &hid_spec_type; dtds[1] = &dtd_data; values[1] = (uint8_t*)hid_spec; leng[0] = 0; leng[1] = sizeof(hid_spec); hid_spec_lst = sdp_seq_alloc_with_length(dtds, values, leng, 2); hid_spec_lst2 = sdp_data_alloc(SDP_SEQ8, hid_spec_lst); sdp_attr_add(sdp_record, SDP_ATTR_HID_DESCRIPTOR_LIST, hid_spec_lst2); for (i = 0; i < sizeof(hid_attr_lang)/2; i++) { dtds2[i] = &dtd; values2[i] = &hid_attr_lang[i]; } lang_lst = sdp_seq_alloc(dtds2, values2, sizeof(hid_attr_lang)/2); lang_lst2 = sdp_data_alloc(SDP_SEQ8, lang_lst); sdp_attr_add(sdp_record, SDP_ATTR_HID_LANG_ID_BASE_LIST, lang_lst2); sdp_attr_add_new(sdp_record, SDP_ATTR_HID_SDP_DISABLE, SDP_UINT16, &hid_attr2[0]); for (i = 0; i < sizeof(hid_attr2)/2-1; i++) { sdp_attr_add_new(sdp_record, SDP_ATTR_HID_REMOTE_WAKEUP+i, SDP_UINT16, &hid_attr2[i+1]); } if (sdp_record_register(session, sdp_record, 0) < 0) { printf("%s: HID Device (Keyboard) Service Record registration failed\n", (char*)__func__); exit(-1); } }