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

svn at pcbsd.org svn at pcbsd.org
Wed Feb 1 16:55:34 PST 2012


Author: kenmoore
Date: 2012-02-02 00:55:34 +0000 (Thu, 02 Feb 2012)
New Revision: 15130

Modified:
   pcbsd/current/src-qt4/libpcbsd/hardware.cpp
   pcbsd/current/src-qt4/libpcbsd/pcbsd-hardware.h
Log:
Add more bluetooth functionality to libpcbsd-hardware - including connection/disconnection functionality



Modified: pcbsd/current/src-qt4/libpcbsd/hardware.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/hardware.cpp	2012-02-02 00:54:36 UTC (rev 15129)
+++ pcbsd/current/src-qt4/libpcbsd/hardware.cpp	2012-02-02 00:55:34 UTC (rev 15130)
@@ -241,3 +241,41 @@
     name = name.simplified(); //remove extra white space
     return name;
 }
+
+QString Hardware::pairBTDevice(QString bdaddr){
+  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 status;
+  if( result.contains("Connection handle:") && result.length() > 2){ status = "Connected"; }
+  else{
+    //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 more known errors later
+    else{ status = "Error: "+junk; }
+  }
+  //Clean up settings
+  Utils::runShellCommand("hccontrol write_authentication_enable 0"); //Turn off computer initated authentication
+  
+  return status;
+}
+
+void Hardware::disconnectBTDevice(QString bdaddr){
+  //Find the connection handle from the BD_ADDR
+  QString handle = getBTConnectionHandle(bdaddr);
+  if(handle.isEmpty()){ return; } //Do nothing if the device is not currently connected
+  //Send the disconnect signal
+  QString cmd = "hccontrol disconnect "+handle;
+  Utils::runShellCommand(cmd);
+}
+
+QString Hardware::getBTConnectionHandle(QString bdaddr){
+  QStringList output = Utils::runShellCommand("hccontrol read_connection_list");
+  QString handle = output.filter(bdaddr).join(";").section(" ",1,1,QString::SectionSkipEmpty);
+  return handle;
+}

Modified: pcbsd/current/src-qt4/libpcbsd/pcbsd-hardware.h
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/pcbsd-hardware.h	2012-02-02 00:54:36 UTC (rev 15129)
+++ pcbsd/current/src-qt4/libpcbsd/pcbsd-hardware.h	2012-02-02 00:55:34 UTC (rev 15130)
@@ -42,6 +42,9 @@
    static QString getBTRemoteName(QString bdaddr);
    static QStringList readAllSavedBTDevices();
    static QStringList readSavedBTDevice(QString bdaddr);
+   static QString pairBTDevice(QString bdaddr);
+   static void disconnectBTDevice(QString bdaddr);
+   static QString getBTConnectionHandle(QString bdaddr);
 
 private:
    static QString getHcsecdDeviceValue(QString rawline); //for bluetooth functions



More information about the Commits mailing list