5 Replies Latest reply on Apr 9, 2014 9:36 PM by yuanpu

    Bluetooth connecting

    Luzhcs

      Hi everyone. I have a problem with connecting Bluetooth.

      I am using intel centrino wireless-N 135. I read a lot of post about bluetooth connecting to iphone 4. but still haven't found solution.

      I am getting blocked at input pin code. When i was using and waiting for signal. Iphone4 poped up a message for input pin code  I tried 0000,1111,1234..etc..

      This is what i typed.

      root@clanton~:rfcomm /dev/rfcomm0 <baddr> 1 or 1&.

      (i already set up hciconfig hci0 up.)

      I don't know where i can set my pin code. I tried sspmode; but not working.

      I really need help. thank you and sorry for my bad english.

        • 1. Re: Bluetooth connecting
          Propst

          This post might give a clue:

          http://forums.gentoo.org/viewtopic-t-797762-start-4.html

          In that case, pincodes for specific device pairs are stored in a pincodes file.  Maybe there is a way to set a generic PIN there for any device pairs?

          2 of 2 people found this helpful
          • 2. Re: Bluetooth connecting
            Luzhcs

            Thank you propst , but actually i tried this already and it didn't work well.. because i think that pincodes file didn't exist at there.And i manually made a hcid.conf file. but don't know how to fit it in to mine.

            It is really annoying.. i spent too long time.

            Any suggestion for me?  

            • 3. Re: Bluetooth connecting
              yuanpu

              actually pincodes does not help for galileo.

              i use 135 ,and follow these commands can connect my iphone yesterday ,but not today(pincode issue i do not know why),

              #rfcomm bind  /dev/rfcomm0 xx:xx:xx:xx:xx:xx(other bluetooth device mac)

              #cat >/dev/rfcomm0

              you can try these commands, may you success.

               

              after all of this i prepare to write c programme to communicate with control another bluetooth device like a single chip something on l2 raw data packets.

               

              waiting for some help too.

              thank u.

              • 4. Re: Bluetooth connecting
                AlexanderMerz

                Just for the record: Distribution specific help pages may not always help, because they often use distribution specific tools. So you should check help pages of other linux distributions too. Also there are different versions of BlueZ in the wild, which behave different (including but not limited to config file and binary locations, and also tools).

                 

                To disable the pincode request, you can try:

                hciconfig hci0 sspmode 1

                 

                SSP = Simple Pairing, doesn't require a pin.

                • 5. Re: Bluetooth connecting
                  yuanpu

                  now i can send bluetooth messages from linux to galileo.

                  1. follow the steps https://github.com/tokoro10g/galileo-makefile, then you can compile c programme without compile

                     the yoto damn thing or cross compiler.

                     2.  the server run on galileo.(need some of bluez include file bluetooth.h  l2cap.h)

                          server.c

                  #include <fcntl.h>

                  #include <sys/types.h>

                  #include <sys/stat.h>

                  #include <string.h>

                  #include <stdlib.h>

                  #include <errno.h>

                  #include <unistd.h>

                  #include <syslog.h>

                  #include <sys/socket.h>

                  #include <bluetooth.h>

                  #include <l2cap.h>

                  #include <time.h>

                   

                   

                   

                   

                  #define RWRR (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)

                  #define BUFFSIZE 1024

                   

                   

                  void puintobg(){

                         /* Our process ID and Session ID */

                          pid_t pid, sid;

                          /* Fork off the parent process */

                          pid = fork();

                          if (pid < 0)

                                  exit(EXIT_FAILURE);

                          /* If we got a good PID, then

                             we can exit the parent process. */

                          if (pid > 0)

                                  exit(EXIT_SUCCESS);

                          /* Change the file mode mask */

                          umask(0);

                          /* Create a new SID for the child process */

                          sid = setsid();

                          if (sid < 0)

                                  exit(EXIT_FAILURE);

                          /* Change the current working directory */

                          if ((chdir("/")) < 0)

                                  exit(EXIT_FAILURE);

                          /* Close out the standard file descriptors */

                          close(STDIN_FILENO);

                          close(STDOUT_FILENO);

                          close(STDERR_FILENO);

                    }

                   

                   

                   

                   

                   

                   

                  int main(int argc, char **argv)

                  {

                    puintobg();

                    time_t   timep;

                      struct sockaddr_l2 loc_addr = { 0 }, rem_addr = { 0 };

                      struct sockaddr_l2 addr;

                      socklen_t optlen;

                      char buf[BUFFSIZE] = { 0 };

                      char buftmp[BUFFSIZE]={0};

                      char str[18];

                      int s, client, bytes_read;

                      socklen_t opt = sizeof(rem_addr);

                   

                   

                      // allocate socket

                      s = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);

                   

                   

                      // bind socket to port 0x1001 of the first available

                      // bluetooth adapter

                      loc_addr.l2_family = AF_BLUETOOTH;

                      loc_addr.l2_bdaddr = *BDADDR_ANY;

                      loc_addr.l2_psm = htobs(0x1001);

                   

                   

                      if (bind(s, (struct sockaddr *)&loc_addr, sizeof(loc_addr)) < 0) {

                    //perror("Can't bind socket");

                    goto error;

                    }

                   

                   

                      /* Get local address */

                    memset(&addr, 0, sizeof(addr));

                    optlen = sizeof(addr);

                   

                   

                    if (getsockname(s, (struct sockaddr *) &addr, &optlen) < 0) {

                    //perror("Can't get local address");

                    goto error;

                    }

                    ba2str(&addr.l2_bdaddr, str);

                      //printf("localaddr %s ...\n", str);

                   

                   

                      // put socket into listening mode

                      listen(s, 1);

                    while(1){

                      // accept one connection

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

                   

                   

                      ba2str( &rem_addr.l2_bdaddr, buf );

                      sprintf(buftmp, "accepted connection from %s ", buf);

                      memset(buf, 0, sizeof(buf));

                      // read data from the client

                      bytes_read = read(client, buf, sizeof(buf));

                      if( bytes_read > 0 ) {

                      int fd=0;;

                         //printf("received [%s]\n", buf);

                         if((fd = open("btContent.log", O_WRONLY | O_CREAT | O_APPEND, RWRR)) < 0)

                    goto error;

                    write(fd,buftmp,strlen(buftmp));

                    write(fd, "[",1);

                    write(fd, buf, bytes_read);

                    write(fd, "]",1);

                    time(&timep);

                    write(fd,ctime(&timep),24);

                    write(fd, "\n",1);

                    //goto error;

                    close(fd);

                      }

                      close(client);

                    }

                  error:

                      close(client);

                      close(s);

                    exit(1);

                  }

                  3.client.c runs on linux with usb bluetooth device

                  #include <stdio.h>

                  #include <string.h>

                  #include <sys/socket.h>

                  #include "bluetooth.h"

                  #include "l2cap.h"

                   

                   

                  int main(int argc, char **argv)

                  {

                      struct sockaddr_l2 addr = { 0 };

                      int s, status;

                      char *message;

                      char dest[18];

                   

                   

                      if(argc < 2)

                      {

                          fprintf(stderr, "usage: %s <bt_addr> <bt_message>\n", argv[0]);

                          exit(2);

                      }

                   

                   

                    if(argc==3){

                      strncpy(dest, argv[1], 18);

                      message=argv[2];

                      }

                    else{

                    strncpy(dest,"00:15:00:96:7F:93",18);

                    message=argv[1];

                    }

                      // allocate a socket

                      s = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);

                   

                   

                      // set the connection parameters (who to connect to)

                      addr.l2_family = AF_BLUETOOTH;

                      addr.l2_psm = htobs(0x1001);

                      str2ba( dest, &addr.l2_bdaddr );

                   

                   

                      // connect to server

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

                   

                   

                      // send a message

                      if( status == 0 ) {

                          status = write(s, message, strlen(message));

                      }

                   

                   

                      if( status < 0 ) perror("uh oh");

                   

                   

                      close(s);

                  }

                   

                  4.of course do not forget run :

                  hciconfig hci0 up

                  hciconfig hci0 piscan 

                  on galileo.