Skip to contentSkip to conversation

Trouble adding a text parameter to the SDP service record

Bluez-devel Jordi Jaen Pallares 1 participant 1 message Jul 30, 2005 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

Hi list,

I am trying to add a attribute "Public Key" (20 bytes length) to the description of a service, but I get a segfault (see code below).

Following some examples in the bluez source code
(and in
http://people.csail.mit.edu/people/albert/pubs/ashuang-sm-thesis-2005.pdf)
I have managed to add successfully the PSM and the protocol version attributes to the service description, but I could not find examples of adding "custom" parameters.

I am sure that I still have to provide an identifier to the attribute, but could not find out how to do it.

Any further help will be appreciated.

Here is the code :

---- snip ----

int main()
{
int ret = 0;
uint32_t service_uuid_int[] = { 0, 0, 0, 0x00FF }; uint16_t l2cap_psm = 1111, ver = 0x001; uuid_t root_uuid, l2cap_uuid, svc_uuid;

sdp_list_t *l2cap_list = 0 ,
*root_list = 0 ,
*proto_list = 0 ,
*access_proto_list = 0 ;

sdp_data_t *psm = 0 , *version = 0, *psha1 = 0;

const char *service_name = "new service"; const char *service_dsc = "description of my service" ; const char *service_prov = "Bluetooth Access Point" ;

// this is the key I want to put in the parameter
const char *pubsha1 = "0123456789abcdef6789" ;

sdp_record_t *record = sdp_record_alloc();

// set the general service ID sdp_uuid128_create (&svc_uuid, &service_uuid_int) ; sdp_set_service_id (record, svc_uuid) ;

// make the service record publicly browsable sdp_uuid16_create (&root_uuid, PUBLIC_BROWSE_GROUP) ; root_list = sdp_list_append (0, &root_uuid) ; sdp_set_browse_groups (record, root_list) ; sdp_list_free (root_list, 0);

// set l2cap information
sdp_uuid16_create (&l2cap_uuid, L2CAP_UUID) ;
l2cap_list = sdp_list_append (0, &l2cap_uuid) ;

// set PSM information
psm = sdp_data_alloc (SDP_UINT16, &l2cap_psm) ;
l2cap_list = sdp_list_append (l2cap_list, psm) ;

// set protocol version
version = sdp_data_alloc(SDP_UINT16, &ver); l2cap_list = sdp_list_append(l2cap_list, version);

// set key parameter
psha1 = sdp_data_alloc(SDP_TEXT_STR16, pubsha1) ; l2cap_list = sdp_list_append (l2cap_list, psha1) ;

proto_list = sdp_list_append (0 , l2cap_list) ;

// attach protocol information to service record access_proto_list = sdp_list_append ( 0 , proto_list ) ; printf("The next line causes segmentation fault\n"); sdp_set_access_protos ( record, access_proto_list ) ; printf("not reached\n");

// set the name, provider , and description sdp_set_info_attr (record, service_name, service_prov, service_dsc ) ;

// connect to the local SDP server and register the service record sdp_session_t *session = 0 ;

session = sdp_connect ( BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY ) ; ret = sdp_record_register ( session , record , SDP_RECORD_PERSIST ) ; if (ret < 0) {
printf("Service Record registration failed\n");
ret = -1;

}

printf("Service registration completed\n");

// cleanup
sdp_list_free (l2cap_list, 0);
sdp_list_free (access_proto_list, 0);
sdp_record_free (record);

return ret;
}

--- snap ---

Best regards,

Jordi