From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Message-ID: <7aa80ced0502230228296ac5e7@mail.gmail.com> From: Mohan K To: bluez-users@lists.sourceforge.net, sebastian.roth@esk.fhg.de Subject: Re: [Bluez-users] Re: Can't able to send data in both direction In-Reply-To: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_48_32773339.1109154533065" References: <7aa80ced0502222239dd01830@mail.gmail.com> <7aa80ced05022223273b5bba4c@mail.gmail.com> Sender: bluez-users-admin@lists.sourceforge.net Errors-To: bluez-users-admin@lists.sourceforge.net Reply-To: bluez-users@lists.sourceforge.net List-Unsubscribe: , List-Id: BlueZ users List-Post: List-Help: List-Subscribe: , List-Archive: Date: Wed, 23 Feb 2005 15:58:53 +0530 ------=_Part_48_32773339.1109154533065 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi Sebastian, The same program works for CSR dongle. I derived the function from l2test.c Regards Mohan On Wed, 23 Feb 2005 11:14:06 +0100, Sebastian Roth wrote: > Hi, > > > When the sending program runs on the SiW dongle PC , HCI dump is > > not displaying any thing and it is giving the following error. > > > > Error message on the sending side: > > > > [root@localhost ]# ./senddata > > > > L2CAP socket opened successfully. > > > > Can't connect: No route to host (113) > I have no clue why this happens. Please post the sourcecode of your > application. > > > Can't send data. > > : Bad file descriptor > This happens because it can't connect. > No connection, not able to send data! > > Maybe there is a problem in the program. Or the needed kernel modules > are not loaded (just a guess). > # lsmod | grep -e l2cap -e rfcomm > > Best regards, > Sebastian > > ------------------------------------------------------- > SF email is sponsored by - The IT Product Guide > Read honest & candid reviews on hundreds of IT Products from real users. > Discover which products truly live up to the hype. Start reading now. > http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click > _______________________________________________ > Bluez-users mailing list > Bluez-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/bluez-users > ------=_Part_48_32773339.1109154533065 Content-Type: text/x-c; name="recvdata.c" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="recvdata.c" /* * * BlueZ - Bluetooth protocol stack for Linux * * Copyright (C) 2000-2001 Qualcomm Incorporated * Copyright (C) 2002-2003 Maxim Krasnyansky * Copyright (C) 2002-2005 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation; * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL= ITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIG= HTS. * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR A= NY * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES= =20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN= =20 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF= =20 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,=20 * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS=20 * SOFTWARE IS DISCLAIMED. * * * $Id: l2test.c,v 1.16 2005/01/11 21:42:38 holtmann Exp $ */ =09=09=09/*Bluetooth Receive program*/ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include #include #include #include #include #include #include #include #include static unsigned char *buf; /* Default mtu */ static int imtu =3D 672; static int omtu =3D 0; /* Default data size */ static long data_size =3D 672; /* Default addr and psm */ static bdaddr_t bdaddr; static unsigned short psm =3D 10; static int master =3D 0; static int auth =3D 0; static int encrypt =3D 0; static int secure =3D 0; static int socktype =3D SOCK_SEQPACKET; static int linger =3D 0; static int reliable =3D 0; unsigned char packet[256]; unsigned char sbuf[256]=3D{'a','b','c','d','e','f',0x7c,'g',0x7c,'i'}; unsigned char formpacket(unsigned char device, unsigned char len ); void send_data(int); static void hexdump(unsigned char *s, unsigned long l) { =09unsigned long i; =09unsigned char j,k; =09unsigned char temp=3D0x00; =09/*for(i=3D0;i 0) =09=09{=09=09=09 =09=09=09printf("\nRecevied %d bytes\n", len); =09=09static int omtu =3D 0; =09hexdump(buf,len); =09=09} =09 =09 =09} } static void do_listen(void) { =09struct sockaddr_l2 loc_addr, rem_addr; =09struct l2cap_options opts; =09int s, s1, opt; =09char ba[18]; =09if ((s =3D socket(PF_BLUETOOTH, socktype, BTPROTO_L2CAP)) < 0) { =09=09printf("\nCan't create socket: %s (%d)\n", strerror(errno), errno); =09=09exit(1); =09} =09loc_addr.l2_family =3D AF_BLUETOOTH; =09bacpy(&loc_addr.l2_bdaddr, &bdaddr); =09loc_addr.l2_psm =3D htobs(psm); =09 =09if (bind(s, (struct sockaddr *) &loc_addr, sizeof(loc_addr)) < 0) { =09=09printf("\nCan't bind socket: %s (%d)\n", strerror(errno), errno); =09=09exit(1); =09} =09/* Set link mode */ =09opt =3D 0; =09if (reliable) =09=09opt |=3D L2CAP_LM_RELIABLE; =09if (master) =09=09opt |=3D L2CAP_LM_MASTER; =09if (auth) =09=09opt |=3D L2CAP_LM_AUTH; =09if (encrypt) =09=09opt |=3D L2CAP_LM_ENCRYPT; =09if (secure) =09=09opt |=3D L2CAP_LM_SECURE; =09if (setsockopt(s, SOL_L2CAP, L2CAP_LM, &opt, sizeof(opt)) < 0) { =09=09printf("\nCan't set L2CAP link mode: %s (%d)\n", strerror(errno), err= no); =09=09exit(1); =09} =09/* Get default options */ =09opt =3D sizeof(opts); =09if (getsockopt(s, SOL_L2CAP, L2CAP_OPTIONS, &opts, &opt) < 0) { =09=09printf("\nCan't get default L2CAP options: %s (%d)\n", strerror(errno= ), errno); =09=09exit(1); =09} =09/* Set new options */ =09opts.imtu =3D imtu; =09if (setsockopt(s, SOL_L2CAP, L2CAP_OPTIONS, &opts, opt) < 0) { =09=09printf("\nCan't set L2CAP options: %s (%d)\n", strerror(errno), errno= ); =09=09exit(1); =09} /*=09if (socktype =3D=3D SOCK_DGRAM) { =09=09handler(s); =09=09return; =09}*/ =09if (listen(s, 10)) { =09=09printf("\nCan not listen on the socket: %s (%d)\n", strerror(errno), = errno); =09=09exit(1); =09} =09printf("\nWaiting for connection on psm %d ...\n", psm); =09while(1) { =09=09opt =3D sizeof(rem_addr); =09=09if ((s1 =3D accept(s, (struct sockaddr *) &rem_addr, &opt)) < 0) { =09=09=09printf("\nAccept failed: %s (%d)\n", strerror(errno), errno); =09=09=09exit(1); =09=09} =09=09opt =3D sizeof(opts); =09=09if (getsockopt(s1, SOL_L2CAP, L2CAP_OPTIONS, &opts, &opt) < 0) { =09=09=09printf("\nCan't get L2CAP options: %s (%d)\n", strerror(errno), er= rno); =09=09=09exit(1); =09=09} =09=09ba2str(&rem_addr.l2_bdaddr, ba); =09=09printf("\nConnect from %s [imtu %d, omtu %d, flush_to %d]\n",ba, opts= .imtu, opts.omtu, opts.flush_to); =09=09/* Enable SO_LINGER */ =09=09if (linger) { =09=09=09struct linger l =3D { .l_onoff =3D 1, .l_linger =3D linger }; =09=09=09if (setsockopt(s, SOL_SOCKET, SO_LINGER, &l, sizeof(l)) < 0) { =09=09=09=09printf("\nCan't enable SO_LINGER: %s (%d)\n", =09=09=09=09=09strerror(errno), errno); =09=09=09=09exit(1); =09=09=09} =09=09} =09 =09=09 =09=09dump_mode(s1); =09=09close(s1); =09=09printf("\nDisconnect: %m\n"); =09} } // Sending part at the receving end unsigned char formpacket(unsigned char device, unsigned char len ) { =09unsigned char temp=3D0x00; =09unsigned char i,j,pdlen; =09 =09packet[0]=3D0x7c; =09switch(device) =09{ =09=09case 1: =09=09=09packet[1]=3D0x01; =09=09=09break; =09=09case 2: =09=09=09packet[1]=3D0x02; =09=09=09break; =09=09case 3: =09=09=09packet[1]=3D0x03; =09=09=09break; =09=09case 4: =09=09=09packet[1]=3D0x04; =09=09=09break; =09} =09=09 =09pdlen=3Dlen; =09for(i=3D3,j=3D0;j * Copyright (C) 2002-2005 Marcel Holtmann * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation; * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL= ITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIG= HTS. * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR A= NY * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES= =20 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN= =20 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF= =20 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,=20 * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS=20 * SOFTWARE IS DISCLAIMED. * * * $Id: l2test.c,v 1.16 2005/01/11 21:42:38 holtmann Exp $ */ = =20 =09=09=09/*Send program*/ #include #include #include #include #include #include #include #include #include #include #include #include "csr.h" unsigned char packet[256]; unsigned char buf[256]=3D{'a','b','c','d','e','f',0x7c,'g',0x7c,'i'}; static unsigned char *rbuf; static int master =3D 0; static int auth =3D 0; static int encrypt =3D 0; static int secure =3D 0; static int reliable =3D 0; static int socktype =3D SOCK_SEQPACKET; /* Default mtu */ static int imtu =3D 672; static int omtu =3D 0; static int linger =3D 0; /* Default data size */ static long data_size =3D 672; /* Default addr and psm */ static bdaddr_t bdaddr; static unsigned short psm =3D 10; //const char str[18]=3D"00:0B:0D:33:DA:F9"; void dump_mode(int); static int listen_connection(void); void accept_connection(int); static void do_listen(void); unsigned char formpacket(unsigned char device, unsigned char len ) { =09unsigned char temp=3D0x00; =09unsigned char i,j,pdlen; =09 =09packet[0]=3D0x7c; =09switch(device) =09{ =09=09case 1: =09=09=09packet[1]=3D0x01; =09=09=09break; =09=09case 2: =09=09=09packet[1]=3D0x02; =09=09=09break; =09=09case 3: =09=09=09packet[1]=3D0x03; =09=09=09break; =09=09case 4: =09=09=09packet[1]=3D0x04; =09=09=09break; =09} =09=09 =09pdlen=3Dlen; =09for(i=3D3,j=3D0;j 0) =09=09{=09=09=09 =09=09=09printf("\nRecevied %d bytes\n", len); =09=09=09hexdump(rbuf,len); =09=09} =09} =09close(s); } int main(void) { =09int fd; =09fd=3Dremote_connect("00:0B:0D:33:DA:F9"); =09send_data(fd); =09//fd=3Dlisten_connection(); =09//accept_connection(fd); //=09do_listen(); =09 =09 } ------=_Part_48_32773339.1109154533065-- ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ Bluez-users mailing list Bluez-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bluez-users