All of lore.kernel.org
 help / color / mirror / Atom feed
* [Bluez-devel] Registering service / Getting data
@ 2006-08-29 16:01 Dieter Verslype
  2006-08-29 20:56 ` Marcel Holtmann
  0 siblings, 1 reply; 4+ messages in thread
From: Dieter Verslype @ 2006-08-29 16:01 UTC (permalink / raw)
  To: bluez-devel

[-- Attachment #1: Type: text/plain, Size: 954 bytes --]

Hello list,

I'm developing an application that should capture some data sent by a
bluetooth device.
The device is not discoverable, only comes up when it has some data to send.
It searches for devices with a certain PIN. When it can pair, it queries
the sdpd for
services meeting the Serial Port Profile (0x1101) and sends the data to
this service.

When I use hcidump, i can see the data pass, but I can't figure out how to
get it in a C program.

I used http://people.csail.mit.edu/albert/bluez-intro/index.html as
reference to program in C.

When I register my service with the sdpd daemon, i don't know how to query
the sdpd. At least i don't see my service using sdptool. When I run the C
program, nothing happens, the app keeps listening for incoming
connections.

In attachment my hcidump and c-file.

Any tips would come in handy.


gr,

Dieter Verslype

PS: i'm pretty unexperienced when it comes to C programming.

[-- Attachment #2: hcidump.txt --]
[-- Type: text/plain, Size: 14141 bytes --]

 
root@laptop:/home/dvrslype# hcidump -X -t
HCI sniffer - Bluetooth packet analyzer ver 1.28
device: hci0 snap_len: 1028 filter: 0xffffffff
1156866276.073822 < HCI Command: Inquiry (0x01|0x0001) plen 5
  0000: 33 8b 9e 06 00                                    3....
1156866276.078498 > HCI Event: Command Status (0x0f) plen 4
  0000: 00 01 01 04                                       ....
1156866279.143001 > HCI Event: Inquiry Result (0x02) plen 15
  0000: 01 fb 9d d1 bc 16 00 02  02 00 04 02 52 e3 5c     ............R.\
1156866283.767258 > HCI Event: Inquiry Complete (0x01) plen 1
  0000: 00                                                .
1156866576.080375 < HCI Command: Inquiry (0x01|0x0001) plen 5
  0000: 33 8b 9e 06 00                                    3....
1156866576.088970 > HCI Event: Command Status (0x0f) plen 4
  0000: 00 01 01 04                                       ....
1156866576.797853 > HCI Event: Inquiry Result (0x02) plen 15
  0000: 01 fb 9d d1 bc 16 00 02  02 00 04 02 52 9e 5c     ............R.\
1156866583.775727 > HCI Event: Inquiry Complete (0x01) plen 1
  0000: 00                                                .
1156866619.667922 > HCI Event: Connect Request (0x04) plen 10
  0000: d0 6a 0d 96 a0 00 00 00  00 01                    .j........
1156866619.667968 < HCI Command: Accept Connection Request (0x01|0x0009) plen 7
  0000: d0 6a 0d 96 a0 00 01                              .j.....
1156866619.682923 > HCI Event: Command Status (0x0f) plen 4
  0000: 00 01 09 04                                       ....
1156866619.722915 > HCI Event: Link Key Request (0x17) plen 6
  0000: d0 6a 0d 96 a0 00                                 .j....
1156866619.741892 < HCI Command: Link Key Request Reply (0x01|0x000b) plen 22
  0000: d0 6a 0d 96 a0 00 fb 0d  77 9e 11 2e 67 3d 03 31  .j......w...g=.1
  0010: fc 04 b7 97 f9 c3                                 ......
1156866619.771906 > HCI Event: Command Complete (0x0e) plen 10
  0000: 01 0b 04 00 d0 6a 0d 96  a0 00                    .....j....
1156866620.003867 > HCI Event: Connect Complete (0x03) plen 11
  0000: 00 29 00 d0 6a 0d 96 a0  00 01 01                 .)..j......
1156866620.003912 < HCI Command: Write Link Policy Settings (0x02|0x000d) plen 4
  0000: 29 00 0f 00                                       )...
1156866620.005877 > HCI Event: Page Scan Repetition Mode Change (0x20) plen 7
  0000: d0 6a 0d 96 a0 00 01                              .j.....
1156866620.023866 > HCI Event: Command Complete (0x0e) plen 6
  0000: 01 0d 08 00 29 00                                 ....).
1156866620.023905 < HCI Command: Change Connection Packet Type (0x01|0x000f) plen 4
  0000: 29 00 18 cc                                       )...
1156866620.044861 > HCI Event: Max Slots Change (0x1b) plen 3
  0000: 29 00 05                                          )..
1156866620.046867 > HCI Event: Command Status (0x0f) plen 4
  0000: 00 01 0f 04                                       ....
1156866620.048863 > HCI Event: Connection Packet Type Changed (0x1d) plen 5
  0000: 00 29 00 18 cc                                    .)...
1156866620.052861 > ACL data: handle 41 flags 0x02 dlen 12
    L2CAP(s): Connect req: psm 1 scid 0x0040
1156866620.052909 < ACL data: handle 41 flags 0x02 dlen 16
    L2CAP(s): Connect rsp: dcid 0x0040 scid 0x0040 result 0 status 0
      Connection successful
1156866620.062859 > HCI Event: Number of Completed Packets (0x13) plen 5
  0000: 01 29 00 01 00                                    .)...
1156866620.072858 > ACL data: handle 41 flags 0x02 dlen 16
    L2CAP(s): Config req: dcid 0x0040 flags 0x00 clen 4
      MTU 48
1156866620.072898 < ACL data: handle 41 flags 0x02 dlen 14
    L2CAP(s): Config rsp: scid 0x0040 flags 0x00 result 0 clen 0
      Success
1156866620.072907 < ACL data: handle 41 flags 0x02 dlen 12
    L2CAP(s): Config req: dcid 0x0040 flags 0x00 clen 0
1156866620.094857 > HCI Event: Number of Completed Packets (0x13) plen 5
  0000: 01 29 00 01 00                                    .)...
1156866620.096855 > HCI Event: Number of Completed Packets (0x13) plen 5
  0000: 01 29 00 01 00                                    .)...
1156866620.104851 > ACL data: handle 41 flags 0x02 dlen 14
    L2CAP(s): Config rsp: scid 0x0040 flags 0x00 result 0 clen 0
      Success
1156866620.131848 > ACL data: handle 41 flags 0x02 dlen 19
    L2CAP(d): cid 0x0040 len 15 [psm 1]
        SDP SS Req: tid 0x1 len 0xa
          pat uuid-32 0x1101 (SP)
          max 40
          cont 00
1156866620.132971 < ACL data: handle 41 flags 0x02 dlen 22
    L2CAP(d): cid 0x0040 len 18 [psm 1]
        SDP SS Rsp: tid 0x1 len 0xd
          count 2
          handles 0x10000 0x10002
          cont 00
1156866620.138845 > HCI Event: Number of Completed Packets (0x13) plen 5
  0000: 01 29 00 01 00                                    .)...
1156866620.166845 > ACL data: handle 41 flags 0x02 dlen 21
    L2CAP(d): cid 0x0040 len 17 [psm 1]
        SDP SA Req: tid 0x2 len 0xc
          handle 0x10000
          max 38
          aid(s) 0x0004 (ProtocolDescList)
          cont 00
1156866620.168067 < ACL data: handle 41 flags 0x02 dlen 31
    L2CAP(d): cid 0x0040 len 27 [psm 1]
        SDP SA Rsp: tid 0x2 len 0x16
          count 19
          aid 0x0004 (ProtocolDescList)
             < < uuid-16 0x0100 (L2CAP) > <
             uuid-16 0x0003 (RFCOMM) uint 0x1b > >
          cont 00
1156866620.193837 > HCI Event: Number of Completed Packets (0x13) plen 5
  0000: 01 29 00 01 00                                    .)...
1156866620.245829 > ACL data: handle 41 flags 0x02 dlen 12
    L2CAP(s): Connect req: psm 3 scid 0x0041
1156866620.245880 < ACL data: handle 41 flags 0x02 dlen 16
    L2CAP(s): Connect rsp: dcid 0x0041 scid 0x0041 result 0 status 0
      Connection successful
1156866620.271825 > HCI Event: Number of Completed Packets (0x13) plen 5
  0000: 01 29 00 01 00                                    .)...
1156866620.279824 > ACL data: handle 41 flags 0x02 dlen 16
    L2CAP(s): Config req: dcid 0x0041 flags 0x00 clen 4
      MTU 325
1156866620.279861 < ACL data: handle 41 flags 0x02 dlen 14
    L2CAP(s): Config rsp: scid 0x0041 flags 0x00 result 0 clen 0
      Success
1156866620.279870 < ACL data: handle 41 flags 0x02 dlen 16
    L2CAP(s): Config req: dcid 0x0041 flags 0x00 clen 4
      MTU 1013
1156866620.302819 > HCI Event: Number of Completed Packets (0x13) plen 5
  0000: 01 29 00 01 00                                    .)...
1156866620.304817 > HCI Event: Number of Completed Packets (0x13) plen 5
  0000: 01 29 00 01 00                                    .)...
1156866620.312818 > ACL data: handle 41 flags 0x02 dlen 18
    L2CAP(s): Config rsp: scid 0x0041 flags 0x00 result 0 clen 4
      Success
      MTU 325
1156866620.315827 > ACL data: handle 41 flags 0x02 dlen 8
    L2CAP(d): cid 0x0041 len 4 [psm 3]
      RFCOMM(s): SABM: cr 1 dlci 0 pf 1 ilen 0 fcs 0x1c
1156866620.315867 < ACL data: handle 41 flags 0x02 dlen 8
    L2CAP(d): cid 0x0041 len 4 [psm 3]
      RFCOMM(s): UA: cr 1 dlci 0 pf 1 ilen 0 fcs 0xd7
1156866620.340811 > HCI Event: Number of Completed Packets (0x13) plen 5
  0000: 01 29 00 01 00                                    .)...
1156866620.368807 > ACL data: handle 41 flags 0x02 dlen 18
    L2CAP(d): cid 0x0041 len 14 [psm 3]
      RFCOMM(s): PN CMD: cr 1 dlci 0 pf 0 ilen 10 fcs 0x70 mcc_len 8
      dlci 54 frame_type 0 credit_flow 15 pri 0 ack_timer 0
      frame_size 319 max_retrans 0 credits 0
1156866620.368857 < ACL data: handle 41 flags 0x02 dlen 18
    L2CAP(d): cid 0x0041 len 14 [psm 3]
      RFCOMM(s): PN RSP: cr 0 dlci 0 pf 0 ilen 10 fcs 0xaa mcc_len 8
      dlci 54 frame_type 0 credit_flow 14 pri 0 ack_timer 0
      frame_size 319 max_retrans 0 credits 7
1156866620.395806 > HCI Event: Number of Completed Packets (0x13) plen 5
  0000: 01 29 00 01 00                                    .)...
1156866620.422801 > ACL data: handle 41 flags 0x02 dlen 8
    L2CAP(d): cid 0x0041 len 4 [psm 3]
      RFCOMM(s): SABM: cr 1 dlci 54 pf 1 ilen 0 fcs 0x6e
1156866620.423519 < HCI Command: Authentication Requested (0x01|0x0011) plen 2
  0000: 29 00                                             ).
1156866620.446798 > HCI Event: Command Status (0x0f) plen 4
  0000: 00 01 11 04                                       ....
1156866620.518783 > HCI Event: Auth Complete (0x06) plen 3
  0000: 00 29 00                                          .).
1156866620.518825 < HCI Command: Set Connection Encryption (0x01|0x0013) plen 3
  0000: 29 00 01                                          )..
1156866620.532780 > HCI Event: Command Status (0x0f) plen 4
  0000: 00 01 13 04                                       ....
1156866620.534782 > HCI Event: Encrypt Change (0x08) plen 4
  0000: 00 29 00 01                                       .)..
1156866620.534825 < ACL data: handle 41 flags 0x02 dlen 8
    L2CAP(d): cid 0x0041 len 4 [psm 3]
      RFCOMM(s): UA: cr 1 dlci 54 pf 1 ilen 0 fcs 0xa5
1156866620.534839 < ACL data: handle 41 flags 0x02 dlen 12
    L2CAP(d): cid 0x0041 len 8 [psm 3]
      RFCOMM(s): MSC CMD: cr 0 dlci 0 pf 0 ilen 4 fcs 0xaa mcc_len 2
      dlci 54 fc 0 rtc 1 rtr 1 ic 0 dv 1 b1 1 b2 1 b3 0 len 0
1156866620.541060 < HCI Command: Remote Name Request (0x01|0x0019) plen 10
  0000: d0 6a 0d 96 a0 00 02 00  00 00                    .j........
1156866620.549779 > HCI Event: Command Status (0x0f) plen 4
  0000: 00 01 19 04                                       ....
1156866620.554779 > HCI Event: Number of Completed Packets (0x13) plen 5
  0000: 01 29 00 01 00                                    .)...
1156866620.556780 > HCI Event: Number of Completed Packets (0x13) plen 5
  0000: 01 29 00 01 00                                    .)...
1156866620.583779 > ACL data: handle 41 flags 0x02 dlen 12
    L2CAP(d): cid 0x0041 len 8 [psm 3]
      RFCOMM(s): MSC RSP: cr 1 dlci 0 pf 0 ilen 4 fcs 0x70 mcc_len 2
      dlci 54 fc 0 rtc 1 rtr 1 ic 0 dv 1 b1 1 b2 1 b3 0 len 0
1156866620.584782 > ACL data: handle 41 flags 0x02 dlen 12
    L2CAP(d): cid 0x0041 len 8 [psm 3]
      RFCOMM(s): MSC CMD: cr 1 dlci 0 pf 0 ilen 4 fcs 0x70 mcc_len 2
      dlci 54 fc 0 rtc 1 rtr 1 ic 0 dv 0 b1 1 b2 1 b3 0 len 0
1156866620.584823 < ACL data: handle 41 flags 0x02 dlen 12
    L2CAP(d): cid 0x0041 len 8 [psm 3]
      RFCOMM(s): MSC RSP: cr 0 dlci 0 pf 0 ilen 4 fcs 0xaa mcc_len 2
      dlci 54 fc 0 rtc 1 rtr 1 ic 0 dv 0 b1 1 b2 1 b3 0 len 0
1156866620.584838 < ACL data: handle 41 flags 0x02 dlen 9
    L2CAP(d): cid 0x0041 len 5 [psm 3]
      RFCOMM(d): UIH: cr 0 dlci 54 pf 1 ilen 0 fcs 0xb5 credits 33
1156866620.595777 > HCI Event: Number of Completed Packets (0x13) plen 5
  0000: 01 29 00 02 00                                    .)...
1156866620.596778 > ACL data: handle 41 flags 0x02 dlen 9
    L2CAP(d): cid 0x0041 len 5 [psm 3]
      RFCOMM(d): UIH: cr 1 dlci 54 pf 1 ilen 0 fcs 0x6f credits 6
1156866620.618770 > ACL data: handle 41 flags 0x02 dlen 12
    L2CAP(s): Disconn req: dcid 0x0040 scid 0x0040
1156866620.618818 < ACL data: handle 41 flags 0x02 dlen 12
    L2CAP(s): Disconn rsp: dcid 0x0040 scid 0x0040
1156866620.635775 > HCI Event: Remote Name Req Complete (0x07) plen 255
  0000: 00 d0 6a 0d 96 a0 00 31  34 31 35 30 35 30 38 30  ..j....141505080
  0010: 30 30 37 31 20 20 00 00  00 00 00 00 00 00 00 00  0071  ..........
  0020: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
  0030: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
  0040: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
  0050: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
  0060: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
  0070: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
  0080: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
  0090: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
  00a0: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
  00b0: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
  00c0: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
  00d0: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
  00e0: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  ................
  00f0: 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00     ...............
1156866620.637766 > HCI Event: Number of Completed Packets (0x13) plen 5
  0000: 01 29 00 01 00                                    .)...
###HERE's DATA I HAVE TO CAPTURE
###VVVVVVVVVVVVVVVVVVVVVVVVVVVVV
1156866620.733754 > ACL data: handle 41 flags 0x02 dlen 82
    L2CAP(d): cid 0x0041 len 78 [psm 3]
      RFCOMM(d): UIH: cr 1 dlci 54 pf 0 ilen 74 fcs 0x73
      0000: 02 00 0e 00 00 00 41 01  00 d6 07 08 1c 08 35 16  ......A.......5.
      0010: d6 07 08 1d 0f 34 1b d0  6a 0d 96 a0 00 7a 2d 5d  .....4..j....z-]
      0020: 3a 0a 00 35 30 35 30 38  30 30 30 37 31 20 20 00  :..5050800071  .
      0030: 00 00 00 00 00 00 00 00  00 d9 00 11 53 54 2c 2b  ............ST,+
      0040: 30 30 31 2e 31 30 6b 67  0d 0a                    001.10kg..
1156866630.920104 > ACL data: handle 41 flags 0x02 dlen 8
    L2CAP(d): cid 0x0041 len 4 [psm 3]
      RFCOMM(s): DISC: cr 1 dlci 54 pf 1 ilen 0 fcs 0x8f
1156866630.920157 < ACL data: handle 41 flags 0x02 dlen 8
    L2CAP(d): cid 0x0041 len 4 [psm 3]
      RFCOMM(s): UA: cr 1 dlci 54 pf 1 ilen 0 fcs 0xa5
1156866630.964096 > HCI Event: Number of Completed Packets (0x13) plen 5
  0000: 01 29 00 01 00                                    .)...
1156866630.990090 > ACL data: handle 41 flags 0x02 dlen 12
    L2CAP(s): Disconn req: dcid 0x0041 scid 0x0041
1156866630.990131 < ACL data: handle 41 flags 0x02 dlen 12
    L2CAP(s): Disconn rsp: dcid 0x0041 scid 0x0041
1156866634.904460 > HCI Event: Disconn Complete (0x05) plen 4
  0000: 00 29 00 08                                       .)..

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: rfcomm-server.c --]
[-- Type: text/x-csrc; name="rfcomm-server.c", Size: 3676 bytes --]

#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>

sdp_session_t* register_service();

int main(int argc, char **argv)
{
    //register service in SDPd
    sdp_session_t* session = register_service();

    struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 };
    char buf[1024] = { 0 };
    int s, client, bytes_read;
    int opt = sizeof(rem_addr);

    // allocate socket
    s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);

    // bind socket to port 1 of the first available 
    // local bluetooth adapter
    loc_addr.rc_family = AF_BLUETOOTH;
    loc_addr.rc_bdaddr = *BDADDR_ANY;
    loc_addr.rc_channel = (uint8_t) 1;
    bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr));

    // put socket into listening mode
    listen(s, 1);

    // accept one connection
    client = accept(s, (struct sockaddr *)&rem_addr, &opt);

    ba2str( &rem_addr.rc_bdaddr, buf );
    fprintf(stderr, "accepted connection from %s\n", buf);
    memset(buf, 0, sizeof(buf));

    // read data from the client
    bytes_read = read(client, buf, sizeof(buf));
    if( bytes_read > 0 ) {
        printf("received [%s]\n", buf);
    }

    // close connection
    close(client);
    close(s);
    sdp_close(session);
    return 0;
}

sdp_session_t* register_service() {
    uint32_t service_uuid_int[] = { 0, 0, 0, 0x1101 };
    uint8_t rfcomm_channel = 11;
    const char *service_name = "Healt Monitor Service";
    const char *service_dsc = "Captures Bluetooth packages and stores in SQL_DB";
    const char *service_prov = "IBCN-Niko";

    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);
	   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;
}

[-- Attachment #4: Type: text/plain, Size: 373 bytes --]

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642

[-- Attachment #5: Type: text/plain, Size: 164 bytes --]

_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bluez-devel] Registering service / Getting data
  2006-08-29 16:01 Dieter Verslype
@ 2006-08-29 20:56 ` Marcel Holtmann
  0 siblings, 0 replies; 4+ messages in thread
From: Marcel Holtmann @ 2006-08-29 20:56 UTC (permalink / raw)
  To: BlueZ development

Hi Dieter,

> I'm developing an application that should capture some data sent by a
> bluetooth device.
> The device is not discoverable, only comes up when it has some data to send.
> It searches for devices with a certain PIN. When it can pair, it queries
> the sdpd for
> services meeting the Serial Port Profile (0x1101) and sends the data to
> this service.
> 
> When I use hcidump, i can see the data pass, but I can't figure out how to
> get it in a C program.
> 
> I used http://people.csail.mit.edu/albert/bluez-intro/index.html as
> reference to program in C.
> 
> When I register my service with the sdpd daemon, i don't know how to query
> the sdpd. At least i don't see my service using sdptool. When I run the C
> program, nothing happens, the app keeps listening for incoming
> connections.
> 
> In attachment my hcidump and c-file.

first of all the preferred mode is "hcidump -X -V", because I am not
going to decode any HCI traffic by hand.

Second, the RFCOMM channel in the SDP service registration (in your case
it is 11) should match the channel you listen on (which is 1).

Regards

Marcel



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bluez-devel] Registering service / Getting data
@ 2006-08-30  8:20 Dieter Verslype
  2006-08-30  9:31 ` Dieter Verslype
  0 siblings, 1 reply; 4+ messages in thread
From: Dieter Verslype @ 2006-08-30  8:20 UTC (permalink / raw)
  To: Bluez Developers List

Hello list,

> The RFCOMM channel in the SDP service registration (in your case it is 11)
> should match the channel you listen on (which is 1).

Thx, Marcel, that was a pretty lame mistake, so I fixed that.

The machine I develop on runs Kubuntu 6.06 , and this runs the bleutooth serial chat service
by default (Serial Port profile).
So everytime I wanted to send data (from a scale that's sends the weight), the sender sent it to the serial chat service.
I turned this service of, and ran my own. But now the device doesn't send the data anymore, because in the SDP request
it doesn't find a service meeting the Serial Port profile (0x1101).

Here is my dump:
<hcidump>
root@laptop:/home/dvrslype# hcidump -X -V

HCI sniffer - Bluetooth packet analyzer ver 1.28
device: hci0 snap_len: 1028 filter: 0xffffffff
#INQUIRY
...
#CONNECTION
...
#
# SDP Request for 0x1101 (Serial Port Profile)
#
 > ACL data: handle 41 flags 0x02 dlen 19
    L2CAP(d): cid 0x0040 len 15 [psm 1]
        SDP SS Req: tid 0x1 len 0xa
          pat uuid-32 0x1101 (SP)
          max 40
          cont 00
#
# SDP Response: count 0 <<<<<<<=
#
< ACL data: handle 41 flags 0x02 dlen 14
    L2CAP(d): cid 0x0040 len 10 [psm 1]
        SDP SS Rsp: tid 0x1 len 0x5
          count 0
          cont 00
 > HCI Event: Number of Completed Packets (0x13) plen 5
    handle 41 packets 1
 > HCI Event: Disconn Complete (0x05) plen 4
    status 0x00 handle 41 reason 0x08
    Reason: Connection Timeout
</hcidump>

Here is my code for registering the service and listening to the right 
channel:
<c-code>
#include <bluetooth/bluetooth.h>
#include <bluetooth/rfcomm.h>
#include <bluetooth/sdp.h>
#include <bluetooth/sdp_lib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/socket.h>

sdp_session_t* register_service();

int main(int argc, char **argv)
{
    //register service in SDPd
    sdp_session_t* session = register_service();

    struct sockaddr_rc loc_addr = { 0 }, rem_addr = { 0 };
    char buf[1024] = { 0 };
    int s, client, bytes_read;
    int opt = sizeof(rem_addr);

    // allocate socket
    s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);

    // bind socket to port 1 of the first available
    // local bluetooth adapter
    loc_addr.rc_family = AF_BLUETOOTH;
    loc_addr.rc_bdaddr = *BDADDR_ANY;
    loc_addr.rc_channel = (uint8_t) 1;
    bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr));

    // put socket into listening mode
    listen(s, 1);

    // accept one connection
    client = accept(s, (struct sockaddr *)&rem_addr, &opt);

    ba2str( &rem_addr.rc_bdaddr, buf );
    fprintf(stderr, "accepted connection from %s\n", buf);
    memset(buf, 0, sizeof(buf));

    // read data from the client
    bytes_read = read(client, buf, sizeof(buf));
    if( bytes_read > 0 ) {
        printf("received [%s]\n", buf);
    }

    // close connection
    close(client);
    close(s);
    sdp_close(session);
    return 0;
}

sdp_session_t* register_service() {
    uint32_t service_uuid_int[] = { 0, 0, 0, 0x1101 };
    uint8_t rfcomm_channel = 11;
    const char *service_name = "Healt Monitor Service";
    const char *service_dsc = "Captures Bluetooth packages and stores in 
SQL_DB";
    const char *service_prov = "IBCN-Niko";

    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);
       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;
}
</c-code>

What's wrong about the service registration?
I can't seem to find out how to list it with sdptool, how does that work?

thx in advance,

Dieter

PS: Sorry about not replying to my previous mail, I wasn't subscribed to 
the list yet, now I am!

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Bluez-devel] Registering service / Getting data
  2006-08-30  8:20 [Bluez-devel] Registering service / Getting data Dieter Verslype
@ 2006-08-30  9:31 ` Dieter Verslype
  0 siblings, 0 replies; 4+ messages in thread
From: Dieter Verslype @ 2006-08-30  9:31 UTC (permalink / raw)
  To: BlueZ development

Hello list,

found it myself :) I was confusing the service ID with the Service Class 
UUID list.

I just added this in the register_service() method:

//SERVICE CLASS UUID
uint16_t class_uuid_int = 0x1101;
sdp_uuid16_create( &class_uuid, class_uuid_int );
class_list = sdp_list_append( class_list, &class_uuid);
sdp_set_service_classes( record, class_list );

This results in:

root@laptop:/home/dvrslype# sdptool browse local
Browsing FF:FF:FF:00:00:00 ...
Service Name: Health Monitor Service
Service Description: Captures Bluetooth packages and stores in SQL_DB
Service Provider: IBCN-Niko
Service RecHandle: 0x10000
Service Class ID List:
"Serial Port" (0x1101)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 11

Service Name: KBtSerialChat
Service Description: KDE Bluetooth Serial Chat Service
Service RecHandle: 0x10001
Service Class ID List:
"Serial Port" (0x1101)
Protocol Descriptor List:
"L2CAP" (0x0100)
"RFCOMM" (0x0003)
Channel: 5

gr,

Dieter

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-08-30  9:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-30  8:20 [Bluez-devel] Registering service / Getting data Dieter Verslype
2006-08-30  9:31 ` Dieter Verslype
  -- strict thread matches above, loose matches on Subject: below --
2006-08-29 16:01 Dieter Verslype
2006-08-29 20:56 ` Marcel Holtmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.