diff options
author | Claudio Takahasi <claudio.takahasi@openbossa.org> | 2010-05-25 14:40:27 -0300 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2010-08-09 18:06:43 -0400 |
commit | df3c8e1ebb8d6cdf0e3cfe1cde16d2db8a75871c (patch) | |
tree | 93650b30fc88a545aba45ce64ce3d5c0dcf82e82 /tools | |
parent | 9b8f96b565822beecbb36bf9101955f8d76b8a5a (diff) | |
download | bluez-df3c8e1ebb8d6cdf0e3cfe1cde16d2db8a75871c.tar.gz |
Add GATT SDP record for sdptool
Extend sdptool to allow to add GATT SDP record. Devices that support
GATT over BR/EDR shall publish GATT record. This implementation intend
to be a reference for GATT SDP record creation and it can be a helper
to GATT servers implemented outside BlueZ.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/sdptool.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tools/sdptool.c b/tools/sdptool.c index 89a497ad..d06b1594 100644 --- a/tools/sdptool.c +++ b/tools/sdptool.c @@ -3425,6 +3425,76 @@ static int add_semchla(sdp_session_t *session, svc_info_t *si) return 0; } +static int add_gatt(sdp_session_t *session, svc_info_t *si) +{ + sdp_list_t *svclass_id, *apseq, *proto[2], *profiles, *root, *aproto; + uuid_t root_uuid, proto_uuid, gatt_uuid, l2cap; + sdp_profile_desc_t profile; + sdp_record_t record; + sdp_data_t *psm, *sh, *eh; + uint16_t att_psm = 27, start = 0x0001, end = 0x000f; + int ret; + + memset(&record, 0, sizeof(sdp_record_t)); + record.handle = si->handle; + sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); + root = sdp_list_append(NULL, &root_uuid); + sdp_set_browse_groups(&record, root); + sdp_list_free(root, NULL); + + sdp_uuid16_create(&gatt_uuid, GENERIC_ATTRIB_SVCLASS_ID); + svclass_id = sdp_list_append(NULL, &gatt_uuid); + sdp_set_service_classes(&record, svclass_id); + sdp_list_free(svclass_id, NULL); + + sdp_uuid16_create(&profile.uuid, GENERIC_ATTRIB_PROFILE_ID); + profile.version = 0x0100; + profiles = sdp_list_append(NULL, &profile); + sdp_set_profile_descs(&record, profiles); + sdp_list_free(profiles, NULL); + + sdp_uuid16_create(&l2cap, L2CAP_UUID); + proto[0] = sdp_list_append(NULL, &l2cap); + psm = sdp_data_alloc(SDP_UINT16, &att_psm); + proto[0] = sdp_list_append(proto[0], psm); + apseq = sdp_list_append(NULL, proto[0]); + + sdp_uuid16_create(&proto_uuid, ATT_UUID); + proto[1] = sdp_list_append(NULL, &proto_uuid); + sh = sdp_data_alloc(SDP_UINT16, &start); + proto[1] = sdp_list_append(proto[1], sh); + eh = sdp_data_alloc(SDP_UINT16, &end); + proto[1] = sdp_list_append(proto[1], eh); + apseq = sdp_list_append(apseq, proto[1]); + + aproto = sdp_list_append(NULL, apseq); + sdp_set_access_protos(&record, aproto); + + sdp_set_info_attr(&record, "Generic Attribute Profile", "BlueZ", NULL); + + sdp_set_url_attr(&record, "http://www.bluez.org/", + "http://www.bluez.org/", "http://www.bluez.org/"); + + sdp_set_service_id(&record, gatt_uuid); + + ret = sdp_device_record_register(session, &interface, &record, + SDP_RECORD_PERSIST); + if (ret < 0) + printf("Service Record registration failed\n"); + else + printf("Generic Attribute Profile Service registered\n"); + + sdp_data_free(psm); + sdp_data_free(sh); + sdp_data_free(eh); + sdp_list_free(proto[0], NULL); + sdp_list_free(proto[1], NULL); + sdp_list_free(apseq, NULL); + sdp_list_free(aproto, NULL); + + return ret; +} + struct { char *name; uint32_t class; @@ -3483,6 +3553,7 @@ struct { { "APPLE", 0, add_apple, apple_uuid }, { "ISYNC", APPLE_AGENT_SVCLASS_ID, add_isync, }, + { "GATT", GENERIC_ATTRIB_SVCLASS_ID, add_gatt, }, { 0 } }; |