[PC-BSD Commits] r15136 - pcbsd/current/src-qt4/libpcbsd

svn at pcbsd.org svn at pcbsd.org
Thu Feb 2 08:37:31 PST 2012


Author: kenmoore
Date: 2012-02-02 16:37:30 +0000 (Thu, 02 Feb 2012)
New Revision: 15136

Modified:
   pcbsd/current/src-qt4/libpcbsd/hardware.cpp
   pcbsd/current/src-qt4/libpcbsd/pcbsd-hardware.h
Log:
Make a number of little changes to the bluetooth functions in libpcbsd



Modified: pcbsd/current/src-qt4/libpcbsd/hardware.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/hardware.cpp	2012-02-02 15:52:07 UTC (rev 15135)
+++ pcbsd/current/src-qt4/libpcbsd/hardware.cpp	2012-02-02 16:37:30 UTC (rev 15136)
@@ -105,10 +105,11 @@
 
   //overwrite the original hcsecd.conf file since writing is finished
   Utils::runShellCommand("mv /etc/bluetooth/hcsecd.conf.tmp /etc/bluetooth/hcsecd.conf");
+  //Set the proper permissions again
+  Utils::runShellCommand("chmod 600 /etc/bluetooth/hcsecd.conf");  
+  //restart hcsecd
+  Utils::runShellCommand("/etc/rc.d/hcsecd restart");
   
-  //restart the bluetooth service
-  restartBT();
-  
   return;
 }
 
@@ -160,6 +161,9 @@
 }
 
 void Hardware::rmBTdevice(QString bdaddr,bool willRestart=true){
+  //Disconnect the device first
+  disconnectBTDevice(bdaddr);
+  
   QStringList oldbdaddr, oldname, oldkey, oldpin;
   //scan the file and save all the devices except the one to be removed
   QFile filein( "/etc/bluetooth/hcsecd.conf" );
@@ -204,9 +208,11 @@
   }  
   //overwrite the original file
   Utils::runShellCommand("mv /etc/bluetooth/hcsecd.conf.tmp /etc/bluetooth/hcsecd.conf");
+  //Set the proper permissions again
+  Utils::runShellCommand("chmod 600 /etc/bluetooth/hcsecd.conf");
   
-  //Restart the bluetooth service if desired
-  if(willRestart) { restartBT(); }
+  //Restart the hcsecd if desired
+  if(willRestart) { Utils::runShellCommand("/etc/rc.d/hcsecd restart"); }
 }
 
 QString Hardware::getHcsecdDeviceValue(QString rawline){
@@ -220,7 +226,19 @@
 }
 
 void Hardware::restartBT(){
-  Utils::runShellCommand("/etc/rc.d/hcsecd restart");
+  qDebug() << "Restarting hcsecd";
+  Utils::runShellCommand("/etc/rc.d/hcsecd restart"); //restart hcsecd to make sure any changes are available
+  //Try to connect to all the devices saved in hcsecd.conf that are not already connected
+  QStringList savedBdaddrList = readAllSavedBTDevices();
+  for(int i=0; i<savedBdaddrList.length(); i++){
+    if( getBTConnectionHandle(savedBdaddrList[i]).isEmpty() ){ //if not currently connected
+      qDebug() << "Initiating Connection: "+savedBdaddrList[i];
+      QString result = pairBTDevice(savedBdaddrList[i]);
+      if(!result.isEmpty()){qDebug() << result; }
+      else{qDebug() << "Connection successful";}
+    }
+  }
+  qDebug() << "Finished restarting Bluetooth Services";
 }
 
 QStringList Hardware::findBTdevices(){
@@ -234,30 +252,38 @@
   return bdaddrlist;
 }
 
-QString Hardware::getBTRemoteName(QString bdaddr){
+QString Hardware::getBTRemoteName(QString bdaddr,bool tryagain){
+  //tryagain is TRUE by default
     QString cmd = "hccontrol remote_name_request "+bdaddr;
     QString name = Utils::runShellCommandSearch(cmd,"Name:");
     name = name.section(":",1,1);
     name = name.simplified(); //remove extra white space
+    if(name.isEmpty() && tryagain){
+      name = getBTRemoteName(bdaddr,FALSE); //try one more time, false to avoid loop situation
+    }
     return name;
 }
 
 QString Hardware::pairBTDevice(QString bdaddr){
+  //Returns empty string if device connected successfully
+  
   Utils::runShellCommand("hccontrol write_authentication_enable 1"); //Turn on computer initiated authentication
   //Initiate connection
   QString cmd = "hccontrol create_connection "+ bdaddr;
   QStringList result = Utils::runShellCommand(cmd);
   //Determine if connection accepted and prepare status output
+  QString handle = getBTConnectionHandle(bdaddr); //should be a handle if connection successful
   QString status;
-  if( result.contains("Connection handle:") && result.length() > 2){ status = "Connected"; }
-  else{
+  if(handle.isEmpty()){
     //Did not connect, get the error
     QString junk = result.join(" ").section(":",1,1,QString::SectionSkipEmpty); //remove the "Status:" indicator
     junk = junk.section("[",0,0,QString::SectionSkipEmpty).simplified(); //remove the error code [0x...] from the end
     QString err = result.join(" ").section("[",1,1).section("]",0,0).simplified(); //Get the error code
-    if(err == "0x18"){status = "Error: "+junk+" - Check PIN and KEY configuration"; } //Add extra information for known errors
+    //Add extra information for known errors
+    if(err == "0x18"){status = "Error: "+junk+" - Check PIN and KEY configuration"; } 
+    else if(err == "0x4"){status = "Error: "+junk+" - Check that device is in range and turned on"; }
     //Add more known errors later
-    else{ status = "Error: "+junk; }
+    else{ status = "Error: #"+err+" : "+junk; }
   }
   //Clean up settings
   Utils::runShellCommand("hccontrol write_authentication_enable 0"); //Turn off computer initated authentication

Modified: pcbsd/current/src-qt4/libpcbsd/pcbsd-hardware.h
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/pcbsd-hardware.h	2012-02-02 15:52:07 UTC (rev 15135)
+++ pcbsd/current/src-qt4/libpcbsd/pcbsd-hardware.h	2012-02-02 16:37:30 UTC (rev 15136)
@@ -39,7 +39,7 @@
    static void rmBTdevice(QString bdaddr, bool willRestart);
    static void restartBT();
    static QStringList findBTdevices();
-   static QString getBTRemoteName(QString bdaddr);
+   static QString getBTRemoteName(QString bdaddr, bool tryagain = TRUE);
    static QStringList readAllSavedBTDevices();
    static QStringList readSavedBTDevice(QString bdaddr);
    static QString pairBTDevice(QString bdaddr);



More information about the Commits mailing list