static int bt_string2uuid(uuid_t *uuid, const char *string) { uint32_t data0, data4; uint16_t data1, data2, data3, data5; if (sscanf(string, "%08x-%04hx-%04hx-%04hx-%08x%04hx", &data0, &data1, &data2, &data3, &data4, &data5) == 6) { uint8_t val[16]; data0 = g_htonl(data0); data1 = g_htons(data1); data2 = g_htons(data2); data3 = g_htons(data3); data4 = g_htonl(data4); data5 = g_htons(data5); memcpy(&val[0], &data0, 4); memcpy(&val[4], &data1, 2); memcpy(&val[6], &data2, 2); memcpy(&val[8], &data3, 2); memcpy(&val[10], &data4, 4); memcpy(&val[14], &data5, 2); sdp_uuid128_create(uuid, val); return 0; } return -EINVAL; }
uint16_t dec_read_by_type_req(const uint8_t *pdu, int len, uint16_t *start, uint16_t *end, uuid_t *uuid) { const uint16_t min_len = sizeof(pdu[0]) + sizeof(*start) + sizeof(*end); if (pdu == NULL) return 0; if (start == NULL || end == NULL || uuid == NULL) return 0; if (len < min_len + 2) return 0; if (pdu[0] != ATT_OP_READ_BY_TYPE_REQ) return 0; *start = att_get_u16(&pdu[1]); *end = att_get_u16(&pdu[3]); if (len == min_len + 2) sdp_uuid16_create(uuid, att_get_u16(&pdu[5])); else sdp_uuid128_create(uuid, &pdu[5]); return len; }
int main(int argc, char const *argv[]) { uint32_t svc_uuid_int[] = {0, 0, 0, 0xABCD}; int status; bdaddr_t target, source; uuid_t svc_uuid; sdp_list_t *response_list, *search_list, *attrid_list; sdp_session_t *session = 0; uint32_t range = 0x0000ffff; uint8_t port = 0; //connect to the SDP server running on the remote machine str2ba(dest, &target); str2ba(src, &source); session = sdp_connect(&source, &target, 0); if (session == NULL) { perror("sdp_connect"); exit(1); } sdp_uuid128_create(&svc_uuid, &svc_uuid_int); search_list = sdp_list_append(0, &svc_uuid); attrid_list = sdp_list_append(0, &range); //get a list of service records that have UUID 0xabcd response_list = NULL; status = sdp_service_search_attr_req(session, search_list, SDP_ATTR_REQ_RANGE, attrid_list, &response_list); if (status == 0) { sdp_list_t *proto_list = NULL; sdp_list_t *r = response_list; //go through each of the service records for (; r; r = r->next) { sdp_record_t *rec = (sdp_record_t *)r->data; //get a list of the protocol sequences if (sdp_get_access_protos(rec, &proto_list) == 0) { // get the RFCOMM port number port = sdp_get_proto_port(proto_list, RFCOMM_UUID); sdp_list_free(proto_list, 0); } sdp_record_free(rec); } } sdp_list_free(response_list, 0); sdp_list_free(search_list, 0); sdp_list_free(attrid_list, 0); sdp_close(session); if (port != 0) { printf("found service running on RFCOMM Port %d\n", port); } return 0; }
int dun_sdp_search(bdaddr_t *src, bdaddr_t *dst, int *channel, int type) { sdp_session_t *s; sdp_list_t *srch, *attrs, *rsp; uuid_t svclass; uint16_t attr; int err; s = sdp_connect(src, dst, 0); if (!s) { syslog(LOG_ERR, "Failed to connect to the SDP server. %s(%d)", strerror(errno), errno); return -1; } switch (type) { case MROUTER: sdp_uuid16_create(&svclass, SERIAL_PORT_SVCLASS_ID); break; case ACTIVESYNC: sdp_uuid128_create(&svclass, (void *) async_uuid); break; case DIALUP: sdp_uuid16_create(&svclass, DIALUP_NET_SVCLASS_ID); break; default: sdp_uuid16_create(&svclass, LAN_ACCESS_SVCLASS_ID); break; } srch = sdp_list_append(NULL, &svclass); attr = SDP_ATTR_PROTO_DESC_LIST; attrs = sdp_list_append(NULL, &attr); err = sdp_service_search_attr_req(s, srch, SDP_ATTR_REQ_INDIVIDUAL, attrs, &rsp); sdp_close(s); if (err) return 0; for(; rsp; rsp = rsp->next) { sdp_record_t *rec = (sdp_record_t *) rsp->data; sdp_list_t *protos; if (!sdp_get_access_protos(rec, &protos)) { int ch = sdp_get_proto_port(protos, RFCOMM_UUID); if (ch > 0) { *channel = ch; return 1; } } } return 0; }
int str2uuid( const char *uuid_str, uuid_t *uuid ) { uint32_t uuid_int[4]; char *endptr; if( strlen( uuid_str ) == 36 ) { // Parse uuid128 standard format: 12345678-9012-3456-7890-123456789012 char buf[9] = { 0 }; if( uuid_str[8] != '-' && uuid_str[13] != '-' && uuid_str[18] != '-' && uuid_str[23] != '-' ) { return 0; } // first 8-bytes strncpy(buf, uuid_str, 8); uuid_int[0] = htonl( strtoul( buf, &endptr, 16 ) ); if( endptr != buf + 8 ) return 0; // second 8-bytes strncpy(buf, uuid_str+9, 4); strncpy(buf+4, uuid_str+14, 4); uuid_int[1] = htonl( strtoul( buf, &endptr, 16 ) ); if( endptr != buf + 8 ) return 0; // third 8-bytes strncpy(buf, uuid_str+19, 4); strncpy(buf+4, uuid_str+24, 4); uuid_int[2] = htonl( strtoul( buf, &endptr, 16 ) ); if( endptr != buf + 8 ) return 0; // fourth 8-bytes strncpy(buf, uuid_str+28, 8); uuid_int[3] = htonl( strtoul( buf, &endptr, 16 ) ); if( endptr != buf + 8 ) return 0; if( uuid != NULL ) sdp_uuid128_create( uuid, uuid_int ); } else if ( strlen( uuid_str ) == 8 ) { // 32-bit reserved UUID uint32_t i = strtoul( uuid_str, &endptr, 16 ); if( endptr != uuid_str + 8 ) return 0; if( uuid != NULL ) sdp_uuid32_create( uuid, i ); } else if( strlen( uuid_str ) == 4 ) { // 16-bit reserved UUID int i = strtol( uuid_str, &endptr, 16 ); if( endptr != uuid_str + 4 ) return 0; if( uuid != NULL ) sdp_uuid16_create( uuid, i ); } else { return 0; } return 1; }
static sdp_record_t *create_app_record(uint8_t chan, const uint8_t *app_uuid, const char *svc_name) { sdp_record_t *record; uuid_t uuid; sdp_uuid128_create(&uuid, app_uuid); record = create_rfcomm_record(chan, &uuid, svc_name, false); if (!record) return NULL; return record; }
static int RegisterSdp(uint8_t port) { int ret = 1; // {6A841273-4A97-4eed-A299-C23D571A54E7} // {00001101-0000-1000-8000-00805F9B34FB} uint8_t svc_uuid_int[] = {0x00, 0x00, 0x11, 0x01, 0x00, 0x00, 0x10, 0x00, 0x80, 0x00, 0x00, 0x80, 0x5f, 0x9b, 0x34, 0xfb}; uuid_t root_uuid, l2cap_uuid, rfcomm_uuid, svc_uuid; sdp_list_t *l2cap_list = 0, *rfcomm_list = 0, *root_list = 0, *proto_list = 0, *access_proto_list = 0; sdp_data_t* channel = 0; sdpRecord = sdp_record_alloc(); // set the general service ID sdp_uuid128_create(&svc_uuid, &svc_uuid_int); sdp_set_service_id(sdpRecord, 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(sdpRecord, root_list); // set l2cap information sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); l2cap_list = sdp_list_append(0, &l2cap_uuid); proto_list = sdp_list_append(0, l2cap_list); // set rfcomm information sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID); channel = sdp_data_alloc(SDP_UINT8, &port); rfcomm_list = sdp_list_append(0, &rfcomm_uuid); sdp_list_append(rfcomm_list, channel); sdp_list_append(proto_list, rfcomm_list); // attach protocol information to service record access_proto_list = sdp_list_append(0, proto_list); sdp_set_access_protos(sdpRecord, access_proto_list); // set the name, provider, and description sdp_set_info_attr(sdpRecord, "DroidCam", "", "Android Webcam"); // connect to the local SDP server, register the service record sdpSession = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY); if(sdp_record_register(sdpSession, sdpRecord, 0)) { MSG_ERROR("Could not register Bluetooth service"); ret = 0; } sdp_data_free(channel); sdp_list_free(l2cap_list, 0); sdp_list_free(rfcomm_list, 0); sdp_list_free(root_list, 0); sdp_list_free(access_proto_list, 0); return ret; }
sdp_session_t *register_service() { uint32_t service_uuid_int[] = { 0, 0, 0, 0xABCD }; uint8_t rfcomm_channel = 11; const char *service_name = "Edison Test"; const char *service_dsc = "Edison Experimental"; const char *service_prov = "glfernando"; sdp_session_t *session = 0; bdaddr_t bdaddr_local = {{0, 0, 0, 0xff, 0xff, 0xff}}; uuid_t root_uuid, l2cap_uuid, rfcomm_uuid, svc_uuid; sdp_list_t *l2cap_list = 0, *rfcomm_list = 0, *root_list = 0, *proto_list = 0, *access_proto_list = 0; sdp_data_t *channel = 0, *psm = 0; 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 ); // set l2cap information sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); l2cap_list = sdp_list_append( 0, &l2cap_uuid ); proto_list = sdp_list_append( 0, l2cap_list ); // set rfcomm information sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID); channel = sdp_data_alloc(SDP_UINT8, &rfcomm_channel); rfcomm_list = sdp_list_append( 0, &rfcomm_uuid ); sdp_list_append( rfcomm_list, channel ); sdp_list_append( proto_list, rfcomm_list ); // attach protocol information to service record access_proto_list = sdp_list_append( 0, proto_list ); sdp_set_access_protos( record, access_proto_list ); // set the name, provider, and description sdp_set_info_attr(record, service_name, service_prov, service_dsc); // connect to the local SDP server, register the service record, and disconnect session = sdp_connect( BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY); if (!session) { printf("session NULL , err %s\n", strerror(errno)); } sdp_record_register(session, record, 0); // cleanup sdp_data_free( channel ); sdp_list_free( l2cap_list, 0 ); sdp_list_free( rfcomm_list, 0 ); sdp_list_free( root_list, 0 ); sdp_list_free( access_proto_list, 0 ); return session; }
sdp_session_t *register_service(int chnel, int l2_chnel) { uint32_t service_uuid_int[] = { 0, 0, 0, 0xABCD }; uint8_t rfcomm_channel = chnel; uint16_t l2cap_channel = l2_chnel; const char *service_name = "Roto-Rooter Data Router"; const char *service_dsc = "An experimental plumbing router"; const char *service_prov = "Roto-Rooter"; uuid_t root_uuid, l2cap_uuid, rfcomm_uuid, svc_uuid; sdp_list_t *l2cap_list = 0, *rfcomm_list = 0, *root_list = 0, *proto_list = 0, *access_proto_list = 0, *class_id_list = 0; sdp_data_t *channel = 0, *psm = 0, *l2cap_port = 0; sdp_record_t *record = sdp_record_alloc(); // set the general service ID sdp_uuid128_create( &svc_uuid, &service_uuid_int ); class_id_list = sdp_list_append(0, &svc_uuid); //sdp_set_service_id( record, svc_uuid ); sdp_set_service_classes( record, class_id_list); // 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 ); // set l2cap information sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); l2cap_list = sdp_list_append( 0, &l2cap_uuid ); l2cap_port = sdp_data_alloc(SDP_UINT16, &l2cap_channel); sdp_list_append( l2cap_list, l2cap_port); proto_list = sdp_list_append( 0, l2cap_list ); // set rfcomm information sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID); channel = sdp_data_alloc(SDP_UINT8, &rfcomm_channel); rfcomm_list = sdp_list_append( 0, &rfcomm_uuid ); sdp_list_append( rfcomm_list, channel ); sdp_list_append( proto_list, rfcomm_list ); // attach protocol information to service record access_proto_list = sdp_list_append( 0, proto_list ); sdp_set_access_protos( record, access_proto_list ); // set the name, provider, and description sdp_set_info_attr(record, service_name, service_prov, service_dsc); int err = 0; sdp_session_t *session = 0; // connect to the local SDP server, register the service record, and // disconnect session = sdp_connect( BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY ); err = sdp_record_register(session, record, 0); // cleanup sdp_data_free( channel ); sdp_list_free( l2cap_list, 0 ); sdp_list_free( rfcomm_list, 0 ); sdp_list_free( root_list, 0 ); sdp_list_free( access_proto_list, 0 ); return session; }
sdp_session_t *register_service() { uint32_t svc_uuid_int[] = { 0x00000000,0x00000000,0x00000000,0x0001 }; uint8_t rfcomm_channel = 1; const char *service_name = "Remote Host"; const char *service_dsc = "What the remote should be connecting to."; const char *service_prov = "Your mother"; uuid_t root_uuid, l2cap_uuid, rfcomm_uuid, svc_uuid; sdp_list_t *l2cap_list = 0, *rfcomm_list = 0, *root_list = 0, *proto_list = 0, *access_proto_list = 0; sdp_data_t *channel = 0, *psm = 0; sdp_record_t *record = sdp_record_alloc(); // set the general service ID sdp_uuid128_create( &svc_uuid, &svc_uuid_int ); sdp_set_service_id( record, svc_uuid ); sdp_list_t service_class = {NULL, &svc_uuid}; sdp_set_service_classes( record, &service_class); // 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 ); // set l2cap information sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); l2cap_list = sdp_list_append( 0, &l2cap_uuid ); proto_list = sdp_list_append( 0, l2cap_list ); // set rfcomm information sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID); channel = sdp_data_alloc(SDP_UINT8, &rfcomm_channel); rfcomm_list = sdp_list_append( 0, &rfcomm_uuid ); sdp_list_append( rfcomm_list, channel ); sdp_list_append( proto_list, rfcomm_list ); // attach protocol information to service record access_proto_list = sdp_list_append( 0, proto_list ); sdp_set_access_protos( record, access_proto_list ); // set the name, provider, and description sdp_set_info_attr(record, service_name, service_prov, service_dsc); int err = 0; sdp_session_t *session = 0; // connect to the local SDP server, register the service record, and // disconnect session = sdp_connect( BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY ); err = sdp_record_register(session, record, 0); // cleanup //sdp_data_free( channel ); sdp_list_free( l2cap_list, 0 ); sdp_list_free( rfcomm_list, 0 ); sdp_list_free( root_list, 0 ); sdp_list_free( access_proto_list, 0 ); return session; }
int register_service(sdp_session_t *session) { uint8_t rfcomm_channel = 11; const char *service_name = "Atmel Simple Test Service"; const char *svc_dsc = "Simple Test for SDP Register"; const char *service_prov = "Tony"; int ret = 0; uuid_t root_uuid, l2cap_uuid, rfcomm_uuid, svc_uuid, svc_class_uuid; sdp_list_t *l2cap_list = 0, *rfcomm_list = 0, *root_list = 0, *proto_list = 0, *access_proto_list = 0, *svc_class_list = 0, *profile_list = 0; sdp_data_t *channel = 0; sdp_profile_desc_t profile; sdp_record_t record = { 0 }; /* set the general service ID */ sdp_uuid128_create( &svc_uuid, &uuid128 ); sdp_set_service_id( &record, svc_uuid ); /* set the service class */ sdp_uuid16_create(&svc_class_uuid, SERIAL_PORT_SVCLASS_ID); svc_class_list = sdp_list_append(0, &svc_class_uuid); sdp_set_service_classes(&record, svc_class_list); /* set the Bluetooth profile information */ sdp_uuid16_create(&profile.uuid, SERIAL_PORT_PROFILE_ID); profile.version = 0x0100; profile_list = sdp_list_append(0, &profile); sdp_set_profile_descs(&record, profile_list); /* 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 ); /* set l2cap information */ sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); l2cap_list = sdp_list_append( 0, &l2cap_uuid ); proto_list = sdp_list_append( 0, l2cap_list ); /* register the RFCOMM channel for RFCOMM sockets */ sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID); channel = sdp_data_alloc(SDP_UINT8, &rfcomm_channel); rfcomm_list = sdp_list_append( 0, &rfcomm_uuid ); sdp_list_append( rfcomm_list, channel ); sdp_list_append( proto_list, rfcomm_list ); access_proto_list = sdp_list_append( 0, proto_list ); sdp_set_access_protos( &record, access_proto_list ); /* set the name, provider, and description */ sdp_set_info_attr(&record, service_name, service_prov, svc_dsc); /* register the service record, */ if(sdp_record_register(session, &record, SDP_RECORD_PERSIST) < 0) { printf("Service Record registration failed\n"); ret = -1; goto end; } end: // cleanup sdp_data_free(channel); sdp_list_free(l2cap_list, 0); sdp_list_free(rfcomm_list, 0); sdp_list_free(root_list, 0); sdp_list_free(access_proto_list, 0); sdp_list_free(svc_class_list, 0); sdp_list_free(profile_list, 0); return ret; }
sdp_session_t* io_rfcomm_advertise(uint8_t ch, const char *name, const char *desc, const uint32_t *uuid128) { uuid_t root_uuid, rfcomm_uuid, svc_uuid, svc_class_uuid, l2cap_uuid; sdp_list_t *rfcomm_list = 0, *root_list = 0, *proto_list = 0, *access_proto_list = 0, *svc_class_list = 0, *profile_list = 0, *l2cap_list = 0; //*l2cap_list sdp_data_t *channel = 0; sdp_profile_desc_t profile; sdp_record_t record = { 0 }; sdp_session_t *session = 0; //set general service ID sdp_uuid128_create(&svc_uuid, &uuid128); sdp_set_service_id(&record, svc_uuid); // set the service class sdp_uuid16_create(&svc_class_uuid, SERIAL_PORT_SVCLASS_ID); svc_class_list = sdp_list_append(0, &svc_class_uuid); sdp_set_service_classes(&record, svc_class_list); // set the Bluetooth profile information sdp_uuid16_create(&profile.uuid, SERIAL_PORT_PROFILE_ID); profile.version = 0x0100; profile_list = sdp_list_append(0, &profile); sdp_set_profile_descs(&record, profile_list); // 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 ); //set l2cap information sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); l2cap_list = sdp_list_append( 0, &l2cap_uuid ); proto_list = sdp_list_append( 0, l2cap_list ); // register rfcomm channel for rfcomm sockets sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID); channel = sdp_data_alloc(SDP_UINT8, &ch); rfcomm_list = sdp_list_append( 0, &rfcomm_uuid ); sdp_list_append( rfcomm_list, channel ); sdp_list_append( proto_list, rfcomm_list ); access_proto_list = sdp_list_append(0, proto_list); sdp_set_access_protos(&record, access_proto_list); //set name, provider, description sdp_set_info_attr(&record, name, "", desc); //connect to local SDP server, register service record, and disconnect session = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, 0); sdp_record_register(session, &record, 0); //cleanup sdp_data_free(channel); sdp_list_free(l2cap_list, 0); sdp_list_free( rfcomm_list, 0 ); sdp_list_free( root_list, 0 ); sdp_list_free( access_proto_list, 0 ); return session; }
sdp_session_t *register_service(){ //4e:65:78:75:73:2d:43:6f:6d:70:75:74:69:6e:67 ~ Nexus-Computing :)4e65 7875 732d 436f 6d70 7574 696e 6700 //uint32_t service_uuid_int[] = {0x4e65,0x7875,0x732d,0x436f,0x6d70,0x7574,0x696e,0x6700}; uint8_t service_uuid_int[] = {0x07,0x29,0x3d,0xb4,0xa3, 0x23, 0x4e, 0x07,0x8b, 0x8b,0x25,0x0b,0x34,0x0e, 0x42, 0xa4}; uint8_t rfcomm_channel = SVC_CHANNEL; uuid_t root_uuid, l2cap_uuid, rfcomm_uuid, svc_uuid; sdp_list_t *l2cap_list = 0, *rfcomm_list = 0, *root_list = 0, *proto_list = 0, *access_proto_list = 0, *class_id_list; sdp_data_t *channel = 0, *psm = 0; 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 ); // set l2cap information sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); l2cap_list = sdp_list_append( 0, &l2cap_uuid ); proto_list = sdp_list_append( 0, l2cap_list ); // set rfcomm information sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID); channel = sdp_data_alloc(SDP_UINT8, &rfcomm_channel); rfcomm_list = sdp_list_append( 0, &rfcomm_uuid ); sdp_list_append( rfcomm_list, channel ); sdp_list_append( proto_list, rfcomm_list ); // attach protocol information to service record access_proto_list = sdp_list_append( 0, proto_list ); sdp_set_access_protos( record, access_proto_list ); //service classes IMPORTANT FOR ANDROID! class_id_list = sdp_list_append( 0, &svc_uuid); sdp_set_service_classes( record, class_id_list ); // set the name, provider, and description sdp_set_info_attr(record, SVC_NAME, SVC_PROV, SVC_DESC); int err = 0; sdp_session_t *session = 0; // connect to the local SDP server, register the service record, and // disconnect session = sdp_connect( BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY ); err = sdp_record_register(session, record, 0); if(err != 0) perror("Error registring record"); // cleanup sdp_data_free( channel ); sdp_list_free( l2cap_list, 0 ); sdp_list_free( rfcomm_list, 0 ); sdp_list_free( root_list, 0 ); sdp_list_free( access_proto_list, 0 ); return session; }
static int register_attributes(void) { const char *desc_out_temp = "Outside Temperature"; const char *desc_out_hum = "Outside Relative Humidity"; const char *desc_weight = "Rucksack Weight"; const char *manufacturer_name1 = "ACME Temperature Sensor"; const char *manufacturer_name2 = "ACME Weighing Scales"; const char *serial1 = "237495-3282-A"; const char *serial2 = "11267-2327A00239"; const unsigned char char_weight_uuid[] = { 0x80, 0x88, 0xF2, 0x18, 0x90, 0x2C, 0x45, 0x0B, 0xB6, 0xC4, 0x62, 0x89, 0x1E, 0x8C, 0x25, 0xE9 }; const unsigned char prim_weight_uuid[] = { 0x4F, 0x0A, 0xC0, 0x96, 0x35, 0xD4, 0x49, 0x11, 0x96, 0x31, 0xDE, 0xA8, 0xDC, 0x74, 0xEE, 0xFE }; uint8_t atval[256]; uuid_t uuid; int len; /* Battery state service: primary service definition */ sdp_uuid16_create(&uuid, GATT_PRIM_SVC_UUID); att_put_u16(BATTERY_STATE_SVC_UUID, &atval[0]); attrib_db_add(0x0100, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2); /* Battery: battery state characteristic */ sdp_uuid16_create(&uuid, GATT_CHARAC_UUID); atval[0] = ATT_CHAR_PROPER_READ; att_put_u16(0x0110, &atval[1]); att_put_u16(BATTERY_STATE_UUID, &atval[3]); attrib_db_add(0x0106, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5); /* Battery: battery state attribute */ sdp_uuid16_create(&uuid, BATTERY_STATE_UUID); atval[0] = 0x04; attrib_db_add(0x0110, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 1); /* Battery: Client Characteristic Configuration */ sdp_uuid16_create(&uuid, GATT_CLIENT_CHARAC_CFG_UUID); atval[0] = 0x00; atval[1] = 0x00; attrib_db_add(0x0111, &uuid, ATT_NONE, ATT_AUTHENTICATION, atval, 2); /* Thermometer: primary service definition */ sdp_uuid16_create(&uuid, GATT_PRIM_SVC_UUID); att_put_u16(THERM_HUMIDITY_SVC_UUID, &atval[0]); attrib_db_add(0x0200, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2); /* Thermometer: Include */ sdp_uuid16_create(&uuid, GATT_INCLUDE_UUID); att_put_u16(0x0500, &atval[0]); att_put_u16(0x0504, &atval[2]); att_put_u16(MANUFACTURER_SVC_UUID, &atval[4]); attrib_db_add(0x0201, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 6); /* Thermometer: Include */ att_put_u16(0x0550, &atval[0]); att_put_u16(0x0568, &atval[2]); attrib_db_add(0x0202, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 4); /* Thermometer: temperature characteristic */ sdp_uuid16_create(&uuid, GATT_CHARAC_UUID); atval[0] = ATT_CHAR_PROPER_READ; att_put_u16(0x0204, &atval[1]); att_put_u16(TEMPERATURE_UUID, &atval[3]); attrib_db_add(0x0203, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5); /* Thermometer: temperature characteristic value */ sdp_uuid16_create(&uuid, TEMPERATURE_UUID); atval[0] = 0x8A; atval[1] = 0x02; attrib_db_add(0x0204, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2); /* Thermometer: temperature characteristic format */ sdp_uuid16_create(&uuid, GATT_CHARAC_FMT_UUID); atval[0] = 0x0E; atval[1] = 0xFE; att_put_u16(FMT_CELSIUS_UUID, &atval[2]); atval[4] = 0x01; att_put_u16(FMT_OUTSIDE_UUID, &atval[5]); attrib_db_add(0x0205, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 7); /* Thermometer: characteristic user description */ sdp_uuid16_create(&uuid, GATT_CHARAC_USER_DESC_UUID); len = strlen(desc_out_temp); strncpy((char *) atval, desc_out_temp, len); attrib_db_add(0x0206, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, len); /* Thermometer: relative humidity characteristic */ sdp_uuid16_create(&uuid, GATT_CHARAC_UUID); atval[0] = ATT_CHAR_PROPER_READ; att_put_u16(0x0212, &atval[1]); att_put_u16(RELATIVE_HUMIDITY_UUID, &atval[3]); attrib_db_add(0x0210, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5); /* Thermometer: relative humidity value */ sdp_uuid16_create(&uuid, RELATIVE_HUMIDITY_UUID); atval[0] = 0x27; attrib_db_add(0x0212, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 1); /* Thermometer: relative humidity characteristic format */ sdp_uuid16_create(&uuid, GATT_CHARAC_FMT_UUID); atval[0] = 0x04; atval[1] = 0x00; att_put_u16(FMT_PERCENT_UUID, &atval[2]); att_put_u16(BLUETOOTH_SIG_UUID, &atval[4]); att_put_u16(FMT_OUTSIDE_UUID, &atval[6]); attrib_db_add(0x0213, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 8); /* Thermometer: characteristic user description */ sdp_uuid16_create(&uuid, GATT_CHARAC_USER_DESC_UUID); len = strlen(desc_out_hum); strncpy((char *) atval, desc_out_hum, len); attrib_db_add(0x0214, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, len); /* Secondary Service: Manufacturer Service */ sdp_uuid16_create(&uuid, GATT_SND_SVC_UUID); att_put_u16(MANUFACTURER_SVC_UUID, &atval[0]); attrib_db_add(0x0500, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2); /* Manufacturer name characteristic definition */ sdp_uuid16_create(&uuid, GATT_CHARAC_UUID); atval[0] = ATT_CHAR_PROPER_READ; att_put_u16(0x0502, &atval[1]); att_put_u16(MANUFACTURER_NAME_UUID, &atval[3]); attrib_db_add(0x0501, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5); /* Manufacturer name characteristic value */ sdp_uuid16_create(&uuid, MANUFACTURER_NAME_UUID); len = strlen(manufacturer_name1); strncpy((char *) atval, manufacturer_name1, len); attrib_db_add(0x0502, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, len); /* Manufacturer serial number characteristic */ sdp_uuid16_create(&uuid, GATT_CHARAC_UUID); atval[0] = ATT_CHAR_PROPER_READ; att_put_u16(0x0504, &atval[1]); att_put_u16(MANUFACTURER_SERIAL_UUID, &atval[3]); attrib_db_add(0x0503, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5); /* Manufacturer serial number characteristic value */ sdp_uuid16_create(&uuid, MANUFACTURER_SERIAL_UUID); len = strlen(serial1); strncpy((char *) atval, serial1, len); attrib_db_add(0x0504, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, len); /* Secondary Service: Manufacturer Service */ sdp_uuid16_create(&uuid, GATT_SND_SVC_UUID); att_put_u16(MANUFACTURER_SVC_UUID, &atval[0]); attrib_db_add(0x0505, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2); /* Manufacturer name characteristic definition */ sdp_uuid16_create(&uuid, GATT_CHARAC_UUID); atval[0] = ATT_CHAR_PROPER_READ; att_put_u16(0x0507, &atval[1]); att_put_u16(MANUFACTURER_NAME_UUID, &atval[3]); attrib_db_add(0x0506, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5); /* Secondary Service: Vendor Specific Service */ sdp_uuid16_create(&uuid, GATT_SND_SVC_UUID); att_put_u16(VENDOR_SPECIFIC_SVC_UUID, &atval[0]); attrib_db_add(0x0550, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 2); /* Vendor Specific Type characteristic definition */ sdp_uuid16_create(&uuid, GATT_CHARAC_UUID); atval[0] = ATT_CHAR_PROPER_READ; att_put_u16(0x0568, &atval[1]); att_put_u16(VENDOR_SPECIFIC_TYPE_UUID, &atval[3]); attrib_db_add(0x0560, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5); /* Vendor Specific Type characteristic value */ sdp_uuid16_create(&uuid, VENDOR_SPECIFIC_TYPE_UUID); atval[0] = 0x56; atval[1] = 0x65; atval[2] = 0x6E; atval[3] = 0x64; atval[4] = 0x6F; atval[5] = 0x72; attrib_db_add(0x0568, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 6); /* Manufacturer name attribute */ sdp_uuid16_create(&uuid, MANUFACTURER_NAME_UUID); len = strlen(manufacturer_name2); strncpy((char *) atval, manufacturer_name2, len); attrib_db_add(0x0507, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, len); /* Characteristic: serial number */ sdp_uuid16_create(&uuid, GATT_CHARAC_UUID); atval[0] = ATT_CHAR_PROPER_READ; att_put_u16(0x0509, &atval[1]); att_put_u16(MANUFACTURER_SERIAL_UUID, &atval[3]); attrib_db_add(0x0508, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 5); /* Serial number characteristic value */ sdp_uuid16_create(&uuid, MANUFACTURER_SERIAL_UUID); len = strlen(serial2); strncpy((char *) atval, serial2, len); attrib_db_add(0x0509, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, len); /* Weight service: primary service definition */ sdp_uuid16_create(&uuid, GATT_PRIM_SVC_UUID); memcpy(atval, prim_weight_uuid, 16); attrib_db_add(0x0680, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 16); /* Weight: include */ sdp_uuid16_create(&uuid, GATT_INCLUDE_UUID); att_put_u16(0x0505, &atval[0]); att_put_u16(0x0509, &atval[2]); att_put_u16(MANUFACTURER_SVC_UUID, &atval[4]); attrib_db_add(0x0681, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 6); /* Weight: characteristic */ sdp_uuid16_create(&uuid, GATT_CHARAC_UUID); atval[0] = ATT_CHAR_PROPER_READ; att_put_u16(0x0683, &atval[1]); memcpy(&atval[3], char_weight_uuid, 16); attrib_db_add(0x0682, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 19); /* Weight: characteristic value */ sdp_uuid128_create(&uuid, char_weight_uuid); atval[0] = 0x82; atval[1] = 0x55; atval[2] = 0x00; atval[3] = 0x00; attrib_db_add(0x0683, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 4); /* Weight: characteristic format */ sdp_uuid16_create(&uuid, GATT_CHARAC_FMT_UUID); atval[0] = 0x08; atval[1] = 0xFD; att_put_u16(FMT_KILOGRAM_UUID, &atval[2]); att_put_u16(BLUETOOTH_SIG_UUID, &atval[4]); att_put_u16(FMT_HANGING_UUID, &atval[6]); attrib_db_add(0x0684, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, 8); /* Weight: characteristic user description */ sdp_uuid16_create(&uuid, GATT_CHARAC_USER_DESC_UUID); len = strlen(desc_weight); strncpy((char *) atval, desc_weight, len); attrib_db_add(0x0685, &uuid, ATT_NONE, ATT_NOT_PERMITTED, atval, len); return 0; }
int dun_sdp_register(bdaddr_t *device, uint8_t channel, int type) { sdp_list_t *svclass, *pfseq, *apseq, *root, *aproto; uuid_t root_uuid, l2cap, rfcomm, dun; sdp_profile_desc_t profile[1]; sdp_list_t *proto[2]; int status; session = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, 0); if (!session) { syslog(LOG_ERR, "Failed to connect to the local SDP server. %s(%d)", strerror(errno), errno); return -1; } record = sdp_record_alloc(); if (!record) { syslog(LOG_ERR, "Failed to alloc service record"); return -1; } sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP); root = sdp_list_append(NULL, &root_uuid); sdp_set_browse_groups(record, root); sdp_uuid16_create(&l2cap, L2CAP_UUID); proto[0] = sdp_list_append(NULL, &l2cap); apseq = sdp_list_append(NULL, proto[0]); sdp_uuid16_create(&rfcomm, RFCOMM_UUID); proto[1] = sdp_list_append(NULL, &rfcomm); proto[1] = sdp_list_append(proto[1], sdp_data_alloc(SDP_UINT8, &channel)); apseq = sdp_list_append(apseq, proto[1]); aproto = sdp_list_append(NULL, apseq); sdp_set_access_protos(record, aproto); switch (type) { case MROUTER: sdp_uuid16_create(&dun, SERIAL_PORT_SVCLASS_ID); break; case ACTIVESYNC: sdp_uuid128_create(&dun, (void *) async_uuid); break; case DIALUP: sdp_uuid16_create(&dun, DIALUP_NET_SVCLASS_ID); break; default: sdp_uuid16_create(&dun, LAN_ACCESS_SVCLASS_ID); break; } svclass = sdp_list_append(NULL, &dun); sdp_set_service_classes(record, svclass); switch (type) { case LANACCESS: sdp_uuid16_create(&profile[0].uuid, LAN_ACCESS_PROFILE_ID); profile[0].version = 0x0100; pfseq = sdp_list_append(NULL, &profile[0]); sdp_set_profile_descs(record, pfseq); break; case DIALUP: sdp_uuid16_create(&profile[0].uuid, DIALUP_NET_PROFILE_ID); profile[0].version = 0x0100; pfseq = sdp_list_append(NULL, &profile[0]); sdp_set_profile_descs(record, pfseq); break; } switch (type) { case MROUTER: sdp_set_info_attr(record, "mRouter", NULL, NULL); break; case ACTIVESYNC: sdp_set_info_attr(record, "ActiveSync", NULL, NULL); break; case DIALUP: sdp_set_info_attr(record, "Dialup Networking", NULL, NULL); break; default: sdp_set_info_attr(record, "LAN Access Point", NULL, NULL); break; } status = sdp_device_record_register(session, device, record, 0); if (status) { syslog(LOG_ERR, "SDP registration failed."); sdp_record_free(record); record = NULL; return -1; } return 0; }
int discover_sdp(char* remote) { int channel = 0; // returns rfcomm channel uuid_t svc_uuid; int err; bdaddr_t target; sdp_list_t *response_list = NULL, *search_list, *attrid_list; sdp_session_t *session = 0; str2ba( remote , &target ); // connect to the SDP server running on the remote machine if (D) printf("connecting..\n"); session = sdp_connect( BDADDR_ANY, &target, SDP_RETRY_IF_BUSY ); // specify the UUID of the application we're searching for if (D) printf("uuid\n"); sdp_uuid128_create( &svc_uuid, &service_uuid_int ); search_list = sdp_list_append( NULL, &svc_uuid ); // specify that we want a list of all the matching applications' attributes uint32_t range = 0x0000ffff; attrid_list = sdp_list_append( NULL, &range ); // get a list of service records that have UUID 0xabcd err = sdp_service_search_attr_req( session, search_list, \ SDP_ATTR_REQ_RANGE, attrid_list, &response_list); sdp_list_t *r = response_list; // go through each of the service records for (; r; r = r->next ) { sdp_record_t *rec = (sdp_record_t*) r->data; sdp_list_t *proto_list; // get a list of the protocol sequences if( sdp_get_access_protos( rec, &proto_list ) == 0 ) { sdp_list_t *p = proto_list; // go through each protocol sequence for( ; p ; p = p->next ) { sdp_list_t *pds = (sdp_list_t*)p->data; // go through each protocol list of the protocol sequence for( ; pds ; pds = pds->next ) { // check the protocol attributes sdp_data_t *d = (sdp_data_t*)pds->data; int proto = 0; for( ; d; d = d->next ) { switch( d->dtd ) { case SDP_UUID16: case SDP_UUID32: case SDP_UUID128: proto = sdp_uuid_to_proto( &d->val.uuid ); break; case SDP_UINT8: if( proto == RFCOMM_UUID ) { printf("rfcomm channel: %d\n",d->val.int8); channel = (int)d->val.int8; } break; } } } sdp_list_free( (sdp_list_t*)p->data, 0 ); } sdp_list_free( proto_list, 0 ); } printf("found service record 0x%x\n", rec->handle); sdp_record_free( rec ); } sdp_close(session); return channel; }
static int add_service(sdp_session_t *session, uint32_t *handle, uint8_t rfcomm_channel) { int ret = 0; unsigned char service_uuid_int[] = CARBOT_BLUETOOTH_SDP_UUID; const char *service_name = "Carbot Soul"; const char *service_dsc = "General Purpose Android-Auto Interface"; const char *service_prov = "Ubergrund.com"; uuid_t root_uuid; uuid_t rfcomm_uuid, l2cap_uuid, svc_uuid; sdp_list_t *root_list; sdp_list_t *rfcomm_list = 0, *l2cap_list = 0, *proto_list = 0, *access_proto_list = 0, *service_list = 0; sdp_data_t *channel = 0; sdp_record_t *rec; // connect to the local SDP server, register the service record, and // disconnect if (!session) { logDebug("Bad local SDP session\n"); return -1; } rec = sdp_record_alloc(); // set the general service ID sdp_uuid128_create(&svc_uuid, &service_uuid_int); service_list = sdp_list_append(0, &svc_uuid); sdp_set_service_classes(rec, service_list); sdp_set_service_id(rec, 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(rec, root_list); // set l2cap information sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); l2cap_list = sdp_list_append(0, &l2cap_uuid); proto_list = sdp_list_append(0, l2cap_list); // set rfcomm information sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID); rfcomm_list = sdp_list_append(0, &rfcomm_uuid); channel = sdp_data_alloc(SDP_UINT8, &rfcomm_channel); sdp_list_append(rfcomm_list, channel); sdp_list_append(proto_list, rfcomm_list); // attach protocol information to service record access_proto_list = sdp_list_append(0, proto_list); sdp_set_access_protos(rec, access_proto_list); // set the name, provider, and description sdp_set_info_attr(rec, service_name, service_prov, service_dsc); ret = sdp_record_register(session, rec, 0); if (ret < 0) { logError("Service registration failed\n"); } else { *handle = rec->handle; } // cleanup sdp_data_free(channel); sdp_list_free(l2cap_list, 0); sdp_list_free(rfcomm_list, 0); sdp_list_free(root_list, 0); sdp_list_free(proto_list, 0); sdp_list_free(access_proto_list, 0); sdp_list_free(service_list, 0); sdp_record_free(rec); return ret; }
struct session_data *session_create(const char *source, const char *destination, const char *target, uint8_t channel, session_callback_t function, void *user_data) { struct session_data *session; struct callback_data *callback; int err; if (destination == NULL) return NULL; session = g_try_malloc0(sizeof(*session)); if (session == NULL) return NULL; session->refcount = 1; session->channel = channel; session->conn = dbus_bus_get(DBUS_BUS_SESSION, NULL); if (session->conn == NULL) { session_free(session); return NULL; } if (source == NULL) bacpy(&session->src, BDADDR_ANY); else str2ba(source, &session->src); str2ba(destination, &session->dst); if (!g_ascii_strncasecmp(target, "OPP", 3)) { sdp_uuid16_create(&session->uuid, OBEX_OBJPUSH_SVCLASS_ID); } else if (!g_ascii_strncasecmp(target, "FTP", 3)) { sdp_uuid16_create(&session->uuid, OBEX_FILETRANS_SVCLASS_ID); session->target = OBEX_FTP_UUID; session->target_len = OBEX_FTP_UUID_LEN; } else if (!g_ascii_strncasecmp(target, "PBAP", 4)) { sdp_uuid16_create(&session->uuid, PBAP_PSE_SVCLASS_ID); session->target = OBEX_PBAP_UUID; session->target_len = OBEX_PBAP_UUID_LEN; } else if (!g_ascii_strncasecmp(target, "SYNC", 4)) { sdp_uuid16_create(&session->uuid, IRMC_SYNC_SVCLASS_ID); session->target = OBEX_SYNC_UUID; session->target_len = OBEX_SYNC_UUID_LEN; } else if (!g_ascii_strncasecmp(target, "PCSUITE", 7)) { sdp_uuid128_create(&session->uuid, pcsuite_uuid); } else { return NULL; } callback = g_try_malloc0(sizeof(*callback)); if (callback == NULL) { session_free(session); return NULL; } callback->session = session_ref(session); callback->func = function; callback->data = user_data; if (session->channel > 0) { session->io = rfcomm_connect(&session->src, &session->dst, session->channel, rfcomm_callback, callback); err = (session->io == NULL) ? -EINVAL : 0; } else { callback->sdp = service_connect(&session->src, &session->dst, service_callback, callback); err = (callback->sdp == NULL) ? -ENOMEM : 0; } if (err < 0) { session_free(session); g_free(callback); return NULL; } return session; }
/* Allows this service to be discovered when running sdptool. For example, you can find this service * after starting it by running * * $ sdptool browse local * * (Adapted from http://www.btessentials.com/examples/bluez/sdp-register.c) * */ sdp_session_t *register_service(uint8_t rfcomm_channel) { /* A 128-bit number used to identify this service. The words are ordered from most to least * significant, but within each word, the octets are ordered from least to most significant. * For example, the UUID represneted by this array is 00001101-0000-1000-8000-00805F9B34FB. (The * hyphenation is a convention specified by the Service Discovery Protocol of the Bluetooth Core * Specification, but is not particularly important for this program.) * * This UUID is the Bluetooth Base UUID and is commonly used for simple Bluetooth applications. * Regardless of the UUID used, it must match the one that the Armatus Android app is searching * for. */ uint32_t svc_uuid_int[] = { 0x01110000, 0x00100000, 0x80000080, 0xFB349B5F }; const char *service_name = "Armatus Bluetooth server"; const char *svc_dsc = "A HERMIT server that interfaces with the Armatus Android app"; const char *service_prov = "Armatus"; uuid_t root_uuid, l2cap_uuid, rfcomm_uuid, svc_uuid, svc_class_uuid; sdp_list_t *l2cap_list = 0, *rfcomm_list = 0, *root_list = 0, *proto_list = 0, *access_proto_list = 0, *svc_class_list = 0, *profile_list = 0; sdp_data_t *channel = 0; sdp_profile_desc_t profile; sdp_record_t record = { 0 }; sdp_session_t *session = 0; // set the general service ID sdp_uuid128_create(&svc_uuid, &svc_uuid_int); sdp_set_service_id(&record, svc_uuid); char str[256] = ""; sdp_uuid2strn(&svc_uuid, str, 256); printf("Registering UUID %s\n", str); // set the service class sdp_uuid16_create(&svc_class_uuid, SERIAL_PORT_SVCLASS_ID); svc_class_list = sdp_list_append(0, &svc_class_uuid); sdp_set_service_classes(&record, svc_class_list); // set the Bluetooth profile information sdp_uuid16_create(&profile.uuid, SERIAL_PORT_PROFILE_ID); profile.version = 0x0100; profile_list = sdp_list_append(0, &profile); sdp_set_profile_descs(&record, profile_list); // 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); // set l2cap information sdp_uuid16_create(&l2cap_uuid, L2CAP_UUID); l2cap_list = sdp_list_append(0, &l2cap_uuid); proto_list = sdp_list_append(0, l2cap_list); // register the RFCOMM channel for RFCOMM sockets sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID); channel = sdp_data_alloc(SDP_UINT8, &rfcomm_channel); rfcomm_list = sdp_list_append(0, &rfcomm_uuid); sdp_list_append(rfcomm_list, channel); sdp_list_append(proto_list, rfcomm_list); access_proto_list = sdp_list_append(0, proto_list); sdp_set_access_protos(&record, access_proto_list); // set the name, provider, and description sdp_set_info_attr(&record, service_name, service_prov, svc_dsc); // connect to the local SDP server, register the service record, // and disconnect session = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY); sdp_record_register(session, &record, 0); // cleanup sdp_data_free(channel); sdp_list_free(l2cap_list, 0); sdp_list_free(rfcomm_list, 0); sdp_list_free(root_list, 0); sdp_list_free(access_proto_list, 0); sdp_list_free(svc_class_list, 0); sdp_list_free(profile_list, 0); return session; }
int main(int argc, char **argv) { /* on Samsung Galaxy S3 Service Name: LIVIO_CONNECT Service RecHandle: 0x1000a Service Class ID List: UUID 128: fbe4be12-374a-486b-a473-24e39408a24d Protocol Descriptor List: "L2CAP" (0x0100) "RFCOMM" (0x0003) */ uint8_t svc_uuid_int[] = { 0xfb, 0xe4, 0xbe, 0x12, 0x37, 0x4a, 0x48, 0x6b, 0xa4, 0x73, 0x24, 0xe3, 0x94, 0x08, 0xa2, 0x4d}; uuid_t svc_uuid; int err; bdaddr_t target; sdp_list_t *response_list = NULL, *search_list, *attrid_list; sdp_session_t *session = 0; if(argc < 2) { printf("usage: %s <bt-addr> \n",argv[0]); exit(1); } str2ba( argv[1], &target ); // connect to the SDP server running on the remote machine session = sdp_connect( BDADDR_ANY, &target, SDP_RETRY_IF_BUSY ); // specify the UUID of the application we're searching for sdp_uuid128_create( &svc_uuid, &svc_uuid_int ); search_list = sdp_list_append( NULL, &svc_uuid ); // specify that we want a list of all the matching applications' attributes uint32_t range = 0x0000ffff; attrid_list = sdp_list_append( NULL, &range ); printf("starting search...\n"); // get a list of service records that have UUID 0xabcd err = sdp_service_search_attr_req( session, search_list, \ SDP_ATTR_REQ_RANGE, attrid_list, &response_list); sdp_list_t *r = response_list; printf("search completed\n"); // go through each of the service records for (; r; r = r->next ) { sdp_record_t *rec = (sdp_record_t*) r->data; sdp_list_t *proto_list; // get a list of the protocol sequences if( sdp_get_access_protos( rec, &proto_list ) == 0 ) { sdp_list_t *p = proto_list; // go through each protocol sequence for( ; p ; p = p->next ) { sdp_list_t *pds = (sdp_list_t*)p->data; // go through each protocol list of the protocol sequence for( ; pds ; pds = pds->next ) { // check the protocol attributes sdp_data_t *d = (sdp_data_t*)pds->data; int proto = 0; for( ; d; d = d->next ) { switch( d->dtd ) { case SDP_UUID16: case SDP_UUID32: case SDP_UUID128: proto = sdp_uuid_to_proto( &d->val.uuid ); printf("\tproto: 0x%x\n", proto); break; case SDP_UINT8: if( proto == RFCOMM_UUID ) { printf("rfcomm channel: %d\n",d->val.int8); } break; } } } sdp_list_free( (sdp_list_t*)p->data, 0 ); } sdp_list_free( proto_list, 0 ); } printf("found service record 0x%x\n", rec->handle); sdp_record_free( rec ); } sdp_close(session); }