searching for bluetooth services using bluez sdp
hi there
I am trying to search my mobile phone for bluetooth services. I have copied some code from http://people.csail.mit.edu/albert/b...ntro/x601.html and have changed the mac address to my phones mac address and the 0xABCD to 0x1105 which seems to be the obexpush code in bluez (I'm not sure if I need to change this number). The problem is that although the phone shows some bluetooth activity when I initiate the code I get no output showing me the obex push service so that I can get the 'channel/port' which is all I want. I am using slackware 2.6.18 by the way Here is the script I am using #include <bluetooth/bluetooth.h> #include <bluetooth/sdp.h> #include <bluetooth/sdp_lib.h> int main(int argc, char **argv) { uint32_t svc_uuid_int[] = { 0x0, 0x0, 0x0, 0x1105 }; 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( "xx:xx:xx:xx:xx:xx", &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 ); // 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); } 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); } I am quite a novice at doing this in C as I am used to using bash/shell script and using sdptool. However I am trying to learn C and am using this as a project. Thanks in advance Joe |
It's hard to debug that way. The easiest way would be to add printfs showing results of all the functions you run. Then you can check if you have an error somewhere.
|
what-a-nightmare !!!!!
Ok I have got my bluetoth system running and I made sure that I can do sdp service queries to the target bluetooth device via the sdptool tool so I am happy that bluez is installed properly!?!! i.e Code:
I can write code using the bluez-libs that can connect to my bluetooth target device and return the bdaddr of that device long with its human friendly name(as per the tutorial on the link you sent) But I am stuck on the below. Code:
But it is returning a NULL pointer.Without this structue you can interogate the records any futher. Is this what is happening to you? I used gdb to see what was happening... Code:
9 status=sdp_service_search_attr_req(session,search_list,SDP_ATTR_REQ_RANGE,attrid_list,&response_list); The code above is basically the code that you found on that web page. Question: The UUID is that taken from the service class id list or the service rec handle??? Code:
Service RecHandle: 0x10000 :0( As you can see I am trying to connect to DUN(dial up networking) service. There is sooo little documentation on this stuff... Google dosn't return much...... |
i'm going to have to go through the source code of the sdptool application.
:study: |
This works now.
everything is hard coded in this version (i.e the service of interest and the mac of the remote address).However I am posting this one because it is simpler.I will leave it to you to refine. You will need to change the address of the target bluetooth device and if you want the details from another sdp service you will have to change the service class id that you wish the program to find aswell. Code:
char serv_class_ID[]="0x1106"; /* obex push service identifier */ Code:
#include <bluetooth/bluetooth.h> Code:
Service Class 0x1106 |
Thank you so much slzckboy your a total star!!!!
This works perfectly. Cheers for all your efforts :) |
Hello guy ... i was looking for a method to get all the services from bluetooth whit C ... and this can help me ... the question is ... there ar a way to get all the services ?? or a list of UUID of service to ask for each one ?
|
Nice piece of code, very useful to me, thanks!
Nonetheless this check is required: session = sdp_connect( BDADDR_ANY, &target, SDP_RETRY_IF_BUSY ); if (session == (sdp_session_t *)NULL) { printf("E: Device not found\n"); return -1; } As sdp_service_search_attr_req breaks with a segment violation if NULL is provided as session argument, i.e. when a bluetooth id of a device not in range is provided. |
:)
It was just a "proof or concept" but your right of course. aknom between the code i modified and the code originallly linked to by the original poster you should be able to achieve your aim,if you havn't already. ta |
slzckboy.. sry but i dont tell u .. i use what u say ... thanks
Josephus Ross ... the new versions of obex have something like this to get the channel obexftp_browse_bt(mac, OBEX_PUSH_SERVICE) |
All times are GMT -5. The time now is 09:08 PM. |