[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bluetooth-dev] Use L2CAP without upper layers




>I'm trying to set my protocol_layer with my own function in them to get rid
>off rfcomm... Is there a better way to do that ?
I'd suggest to try BlueZ (http://bluez.sf.net). 
Writing L2CAP apps is as easy as:

Client:
         struct sockaddr_l2 addr;
         int s;

         s = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
         
         memset(&addr, 0, sizeof(addr));
         addr.l2_family = AF_BLUETOOTH;
         addr.l2_psm = htobs(100);
         baswap(&addr.l2_bdaddr, strtoba("aa:aa:aa:aa:aa:aa"));

         connect(s, (struct sockaddr *)&addr, sizeof(addr));

         And then just read read/write on socket s. 

Server:
         struct sockaddr_l2 loc_addr, rem_addr;
         int  s, s1, opt;

         s = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);

         memset(&loc_addr, 0, sizeof(loc_addr));
         loc_addr.l2_family = AF_BLUETOOTH;
         loc_addr.l2_bdaddr = BDADDR_ANY;
         loc_addr.l2_psm    = htobs(100);
         bind(s, (struct sockaddr *) &loc_addr, sizeof(loc_addr));
         listen(s, 10);

         opt = sizeof(rem_addr);
         s1 = accept(s, (struct sockaddr *)&rem_addr, &opt));

         And then just read read/write on socket s1. 

Regards
Max

Maksim Krasnyanskiy	
Senior Kernel Engineer
Qualcomm Incorporated

maxk@xxxxxxx.com
http://bluez.sf.net
http://vtun.sf.net

-
To unsubscribe from this list: send the line "unsubscribe bluetooth-dev" in
the body of a message to majordomo@xxxxxxx.com