Bug 1121930 - Sync Bluetooth daemon protocol with BlueZ 5.27. r=shuang, a=bajaj
authorBruce Sun <brsun@mozilla.com>
Thu, 15 Jan 2015 19:44:02 +0800
changeset 232308 be580b96acb1197c1bc93e905220f25236862530
parent 232307 016ef62fa791adff828680b402dcc99af6b8e35f
child 232309 54e1067836db34f9c3181a10b476306ce35885ae
push id30
push userryanvm@gmail.com
push dateWed, 21 Jan 2015 01:09:36 +0000
treeherdermozilla-b2g37_v2_2@7762046d3296 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersshuang, bajaj
bugs1121930
milestone37.0a2
Bug 1121930 - Sync Bluetooth daemon protocol with BlueZ 5.27. r=shuang, a=bajaj
dom/bluetooth/bluedroid/BluetoothDaemonHandsfreeInterface.cpp
dom/bluetooth/bluedroid/BluetoothDaemonHandsfreeInterface.h
dom/bluetooth/bluedroid/BluetoothDaemonHelpers.cpp
dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHandsfreeInterface.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonHandsfreeInterface.cpp
@@ -480,25 +480,38 @@ BluetoothDaemonHandsfreeModule::PhoneSta
     return rv;
   }
   unused << pdu.forget();
   return NS_OK;
 }
 
 nsresult
 BluetoothDaemonHandsfreeModule::ConfigureWbsCmd(
-  const nsAString& aBdAddr,
+  const nsAString& aRemoteAddr,
   BluetoothHandsfreeWbsConfig aConfig,
   BluetoothHandsfreeResultHandler* aRes)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
-  // TODO: to be implemented
+  nsAutoPtr<BluetoothDaemonPDU> pdu(
+    new BluetoothDaemonPDU(SERVICE_ID, OPCODE_CONFIGURE_WBS,
+                           6 + // Address
+                           1)); // Config
 
-  return NS_ERROR_NOT_IMPLEMENTED;
+  nsresult rv = PackPDU(
+    PackConversion<nsAString, BluetoothAddress>(aRemoteAddr), aConfig, *pdu);
+  if (NS_FAILED(rv)) {
+    return rv;
+  }
+  rv = Send(pdu, aRes);
+  if (NS_FAILED(rv)) {
+    return rv;
+  }
+  unused << pdu.forget();
+  return NS_OK;
 }
 
 // Responses
 //
 
 void
 BluetoothDaemonHandsfreeModule::ErrorRsp(
   const BluetoothDaemonPDUHeader& aHeader,
@@ -642,16 +655,26 @@ BluetoothDaemonHandsfreeModule::PhoneSta
   BluetoothHandsfreeResultHandler* aRes)
 {
   ResultRunnable::Dispatch(
     aRes, &BluetoothHandsfreeResultHandler::PhoneStateChange,
     UnpackPDUInitOp(aPDU));
 }
 
 void
+BluetoothDaemonHandsfreeModule::ConfigureWbsRsp(
+  const BluetoothDaemonPDUHeader& aHeader, BluetoothDaemonPDU& aPDU,
+  BluetoothHandsfreeResultHandler* aRes)
+{
+  ResultRunnable::Dispatch(
+    aRes, &BluetoothHandsfreeResultHandler::ConfigureWbs,
+    UnpackPDUInitOp(aPDU));
+}
+
+void
 BluetoothDaemonHandsfreeModule::HandleRsp(
   const BluetoothDaemonPDUHeader& aHeader, BluetoothDaemonPDU& aPDU,
   void* aUserData)
 {
   static void (BluetoothDaemonHandsfreeModule::* const HandleRsp[])(
     const BluetoothDaemonPDUHeader&,
     BluetoothDaemonPDU&,
     BluetoothHandsfreeResultHandler*) = {
@@ -679,17 +702,19 @@ BluetoothDaemonHandsfreeModule::HandleRs
       &BluetoothDaemonHandsfreeModule::CindResponseRsp),
     INIT_ARRAY_AT(OPCODE_FORMATTED_AT_RESPONSE,
       &BluetoothDaemonHandsfreeModule::FormattedAtResponseRsp),
     INIT_ARRAY_AT(OPCODE_AT_RESPONSE,
       &BluetoothDaemonHandsfreeModule::AtResponseRsp),
     INIT_ARRAY_AT(OPCODE_CLCC_RESPONSE,
       &BluetoothDaemonHandsfreeModule::ClccResponseRsp),
     INIT_ARRAY_AT(OPCODE_PHONE_STATE_CHANGE,
-      &BluetoothDaemonHandsfreeModule::PhoneStateChangeRsp)
+      &BluetoothDaemonHandsfreeModule::PhoneStateChangeRsp),
+    INIT_ARRAY_AT(OPCODE_CONFIGURE_WBS,
+      &BluetoothDaemonHandsfreeModule::ConfigureWbsRsp)
   };
 
   MOZ_ASSERT(!NS_IsMainThread()); // I/O thread
 
   if (NS_WARN_IF(!(aHeader.mOpcode < MOZ_ARRAY_LENGTH(HandleRsp))) ||
       NS_WARN_IF(!HandleRsp[aHeader.mOpcode])) {
     return;
   }
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHandsfreeInterface.h
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonHandsfreeInterface.h
@@ -32,17 +32,18 @@ public:
     OPCODE_STOP_VOICE_RECOGNITION =0x06,
     OPCODE_VOLUME_CONTROL = 0x07,
     OPCODE_DEVICE_STATUS_NOTIFICATION = 0x08,
     OPCODE_COPS_RESPONSE = 0x09,
     OPCODE_CIND_RESPONSE = 0x0a,
     OPCODE_FORMATTED_AT_RESPONSE = 0x0b,
     OPCODE_AT_RESPONSE = 0x0c,
     OPCODE_CLCC_RESPONSE = 0x0d,
-    OPCODE_PHONE_STATE_CHANGE = 0x0e
+    OPCODE_PHONE_STATE_CHANGE = 0x0e,
+    OPCODE_CONFIGURE_WBS = 0x0f
   };
 
   virtual nsresult Send(BluetoothDaemonPDU* aPDU, void* aUserData) = 0;
 
   virtual nsresult RegisterModule(uint8_t aId, uint8_t aMode,
                                   uint32_t aMaxNumClients,
                                   BluetoothSetupResultHandler* aRes) = 0;
 
@@ -196,16 +197,20 @@ protected:
   void ClccResponseRsp(const BluetoothDaemonPDUHeader& aHeader,
                        BluetoothDaemonPDU& aPDU,
                        BluetoothHandsfreeResultHandler* aRes);
 
   void PhoneStateChangeRsp(const BluetoothDaemonPDUHeader& aHeader,
                            BluetoothDaemonPDU& aPDU,
                            BluetoothHandsfreeResultHandler* aRes);
 
+  void ConfigureWbsRsp(const BluetoothDaemonPDUHeader& aHeader,
+                       BluetoothDaemonPDU& aPDU,
+                       BluetoothHandsfreeResultHandler* aRes);
+
   void HandleRsp(const BluetoothDaemonPDUHeader& aHeader,
                  BluetoothDaemonPDU& aPDU,
                  void* aUserData);
 
   //
   // Notifications
   //
 
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.cpp
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.cpp
@@ -371,16 +371,31 @@ Convert(uint8_t aIn, BluetoothHandsfreeV
   if (NS_WARN_IF(aIn >= MOZ_ARRAY_LENGTH(sVolumeType))) {
     return NS_ERROR_ILLEGAL_VALUE;
   }
   aOut = sVolumeType[aIn];
   return NS_OK;
 }
 
 nsresult
+Convert(uint8_t aIn, BluetoothHandsfreeWbsConfig& aOut)
+{
+  static const BluetoothHandsfreeWbsConfig sWbsConfig[] = {
+    CONVERT(0x00, HFP_WBS_NONE),
+    CONVERT(0x01, HFP_WBS_NO),
+    CONVERT(0x02, HFP_WBS_YES)
+  };
+  if (NS_WARN_IF(aIn >= MOZ_ARRAY_LENGTH(sWbsConfig))) {
+    return NS_ERROR_ILLEGAL_VALUE;
+  }
+  aOut = sWbsConfig[aIn];
+  return NS_OK;
+}
+
+nsresult
 Convert(uint8_t aIn, BluetoothPropertyType& aOut)
 {
   static const BluetoothPropertyType sPropertyType[] = {
     CONVERT(0x00, static_cast<BluetoothPropertyType>(0)), // invalid, required by gcc
     CONVERT(0x01, PROPERTY_BDNAME),
     CONVERT(0x02, PROPERTY_BDADDR),
     CONVERT(0x03, PROPERTY_UUIDS),
     CONVERT(0x04, PROPERTY_CLASS_OF_DEVICE),
@@ -808,16 +823,32 @@ Convert(BluetoothHandsfreeVolumeType aIn
     aOut = 0x00; // silences compiler warning
     return NS_ERROR_ILLEGAL_VALUE;
   }
   aOut = sVolumeType[aIn];
   return NS_OK;
 }
 
 nsresult
+Convert(BluetoothHandsfreeWbsConfig aIn, uint8_t& aOut)
+{
+  static const uint8_t sWbsConfig[] = {
+    CONVERT(HFP_WBS_NONE, 0x00),
+    CONVERT(HFP_WBS_NO, 0x01),
+    CONVERT(HFP_WBS_YES, 0x02)
+  };
+  if (NS_WARN_IF(aIn >= MOZ_ARRAY_LENGTH(sWbsConfig))) {
+    aOut = 0x00; // silences compiler warning
+    return NS_ERROR_ILLEGAL_VALUE;
+  }
+  aOut = sWbsConfig[aIn];
+  return NS_OK;
+}
+
+nsresult
 Convert(BluetoothPropertyType aIn, uint8_t& aOut)
 {
   static const uint8_t sPropertyType[] = {
     CONVERT(PROPERTY_UNKNOWN, 0x00),
     CONVERT(PROPERTY_BDNAME, 0x01),
     CONVERT(PROPERTY_BDADDR, 0x02),
     CONVERT(PROPERTY_UUIDS, 0x03),
     CONVERT(PROPERTY_CLASS_OF_DEVICE, 0x04),
--- a/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
+++ b/dom/bluetooth/bluedroid/BluetoothDaemonHelpers.h
@@ -201,16 +201,19 @@ Convert(uint8_t aIn, BluetoothHandsfreeN
 
 nsresult
 Convert(uint8_t aIn, BluetoothHandsfreeVoiceRecognitionState& aOut);
 
 nsresult
 Convert(uint8_t aIn, BluetoothHandsfreeVolumeType& aOut);
 
 nsresult
+Convert(uint8_t aIn, BluetoothHandsfreeWbsConfig& aOut);
+
+nsresult
 Convert(uint8_t aIn, BluetoothBondState& aOut);
 
 nsresult
 Convert(uint8_t aIn, BluetoothDeviceType& aOut);
 
 nsresult
 Convert(uint8_t aIn, BluetoothPropertyType& aOut);
 
@@ -285,16 +288,19 @@ Convert(BluetoothHandsfreeNetworkState a
 
 nsresult
 Convert(BluetoothHandsfreeServiceType aIn, uint8_t& aOut);
 
 nsresult
 Convert(BluetoothHandsfreeVolumeType aIn, uint8_t& aOut);
 
 nsresult
+Convert(BluetoothHandsfreeWbsConfig aIn, uint8_t& aOut);
+
+nsresult
 Convert(BluetoothPropertyType aIn, uint8_t& aOut);
 
 nsresult
 Convert(const BluetoothRemoteName& aIn, nsAString& aOut);
 
 nsresult
 Convert(BluetoothScanMode aIn, uint8_t& aOut);