OSDN Git Service

service: Allow manufacturer data to be set.
authorIan Coolidge <icoolidge@google.com>
Wed, 12 Aug 2015 21:53:15 +0000 (14:53 -0700)
committerIan Coolidge <icoolidge@google.com>
Wed, 12 Aug 2015 22:33:56 +0000 (22:33 +0000)
Plumbs IPC and stack code for manufacturer data
on advertisement or scan response.

Change-Id: I4b70506e35f51479bdf4073c31e4cb4f88fa2c98

service/gatt_server.cpp
service/gatt_server.h
service/ipc/unix_ipc_host.cpp
service/ipc/unix_ipc_host.h

index 7aa930f..54a2618 100644 (file)
@@ -567,10 +567,12 @@ bool Server::Initialize(const Uuid &service_id, int *gatt_pipe, CoreStack *bt) {
   return true;
 }
 
-bool Server::SetAdvertisement(const std::vector<Uuid> &ids,
-                              const std::vector<uint8_t> &service_data,
+bool Server::SetAdvertisement(const std::vector<Uuid>& ids,
+                              const std::vector<uint8_t>& service_data,
+                              const std::vector<uint8_t>& manufacturer_data,
                               bool transmit_name) {
   std::vector<uint8_t> id_data;
+  auto mutable_manufacturer_data = manufacturer_data;
   auto mutable_service_data = service_data;
 
   for (const Uuid &id : ids) {
@@ -587,7 +589,8 @@ bool Server::SetAdvertisement(const std::vector<Uuid> &ids,
       false,                       /* no txpower */
       2, 2,                        /* interval */
       0,                           /* appearance */
-      0, nullptr,                  /* no mfg data */
+      mutable_manufacturer_data.size(),
+      reinterpret_cast<char *>(mutable_manufacturer_data.data()),
       mutable_service_data.size(),
       reinterpret_cast<char *>(mutable_service_data.data()), id_data.size(),
       reinterpret_cast<char *>(id_data.data()));
@@ -598,10 +601,12 @@ bool Server::SetAdvertisement(const std::vector<Uuid> &ids,
   return true;
 }
 
-bool Server::SetScanResponse(const std::vector<Uuid> &ids,
-                            const std::vector<uint8_t> &service_data,
-                            bool transmit_name) {
+bool Server::SetScanResponse(const std::vector<Uuid>& ids,
+                             const std::vector<uint8_t>& service_data,
+                             const std::vector<uint8_t>& manufacturer_data,
+                             bool transmit_name) {
   std::vector<uint8_t> id_data;
+  auto mutable_manufacturer_data = manufacturer_data;
   auto mutable_service_data = service_data;
 
   for (const Uuid &id : ids) {
@@ -618,7 +623,8 @@ bool Server::SetScanResponse(const std::vector<Uuid> &ids,
       false,                      /* no txpower */
       2, 2,                       /* interval */
       0,                          /* appearance */
-      0, nullptr,                 /* no mfg data */
+      mutable_manufacturer_data.size(),
+      reinterpret_cast<char *>(mutable_manufacturer_data.data()),
       mutable_service_data.size(),
       reinterpret_cast<char *>(mutable_service_data.data()), id_data.size(),
       reinterpret_cast<char *>(id_data.data()));
index c61399a..778b136 100644 (file)
@@ -71,13 +71,15 @@ class Server {
   bool Initialize(const Uuid &service_id, int *gatt_pipe, CoreStack *bt);
 
   // Control the content of service advertisement.
-  bool SetAdvertisement(const std::vector<Uuid> &ids,
-                        const std::vector<uint8_t> &service_data,
+  bool SetAdvertisement(const std::vector<Uuid>& ids,
+                        const std::vector<uint8_t>& service_data,
+                        const std::vector<uint8_t>& manufacturer_data,
                         bool transmit_name);
 
   // Control the content of service scan response.
-  bool SetScanResponse(const std::vector<Uuid> &ids,
-                       const std::vector<uint8_t> &service_data,
+  bool SetScanResponse(const std::vector<Uuid>& ids,
+                       const std::vector<uint8_t>& service_data,
+                       const std::vector<uint8_t>& manufacturer_data,
                        bool transmit_name);
 
   // Add an ordinary characteristic for reading and/or writing.
index bd1570d..dc2e981 100644 (file)
@@ -184,6 +184,7 @@ bool UnixIPCHost::OnSetCharacteristicValue(const std::string& service_uuid,
 bool UnixIPCHost::OnSetAdvertisement(const std::string& service_uuid,
                               const std::string& advertise_uuids,
                               const std::string& advertise_data,
+                              const std::string& manufacturer_data,
                               const std::string& transmit_name) {
   LOG_INFO(LOG_TAG, "%s: service:%s uuids:%s data:%s", __func__, service_uuid.c_str(),
            advertise_uuids.c_str(), advertise_data.c_str());
@@ -198,8 +199,15 @@ bool UnixIPCHost::OnSetAdvertisement(const std::string& service_uuid,
 
   std::string decoded_data;
   base::Base64Decode(advertise_data, &decoded_data);
-  std::vector<uint8_t> blob_data(decoded_data.begin(), decoded_data.end());
-  gatt_servers_[service_uuid]->SetAdvertisement(ids, blob_data,
+  std::vector<uint8_t> decoded_advertise_data(decoded_data.begin(),
+                                              decoded_data.end());
+
+  base::Base64Decode(manufacturer_data, &decoded_data);
+  std::vector<uint8_t> decoded_manufacturer_data(decoded_data.begin(),
+                                                 decoded_data.end());
+
+  gatt_servers_[service_uuid]->SetAdvertisement(ids, decoded_advertise_data,
+                                                decoded_manufacturer_data,
                                                 TokenBool(transmit_name));
   return true;
 }
@@ -207,6 +215,7 @@ bool UnixIPCHost::OnSetAdvertisement(const std::string& service_uuid,
 bool UnixIPCHost::OnSetScanResponse(const std::string& service_uuid,
                              const std::string& scan_response_uuids,
                              const std::string& scan_response_data,
+                             const std::string& manufacturer_data,
                              const std::string& transmit_name) {
   std::vector<std::string> scan_response_uuid_tokens;
   base::SplitString(scan_response_uuids, '.', &scan_response_uuid_tokens);
@@ -218,8 +227,15 @@ bool UnixIPCHost::OnSetScanResponse(const std::string& service_uuid,
 
   std::string decoded_data;
   base::Base64Decode(scan_response_data, &decoded_data);
-  std::vector<uint8_t> blob_data(decoded_data.begin(), decoded_data.end());
-  gatt_servers_[service_uuid]->SetScanResponse(ids, blob_data,
+  std::vector<uint8_t> decoded_advertise_data(decoded_data.begin(),
+                                              decoded_data.end());
+
+  base::Base64Decode(manufacturer_data, &decoded_data);
+  std::vector<uint8_t> decoded_manufacturer_data(decoded_data.begin(),
+                                                 decoded_data.end());
+
+  gatt_servers_[service_uuid]->SetScanResponse(ids, decoded_advertise_data,
+                                               decoded_manufacturer_data,
                                                TokenBool(transmit_name));
   return true;
 }
@@ -273,13 +289,15 @@ bool UnixIPCHost::OnMessage() {
         return OnSetCharacteristicValue(tokens[1], tokens[2], tokens[3]);
       break;
     case 5:
-      if (tokens[0] == kSetAdvertisementCommand)
-        return OnSetAdvertisement(tokens[1], tokens[2], tokens[3], tokens[4]);
-      if (tokens[0] == kSetScanResponseCommand)
-        return OnSetScanResponse(tokens[1], tokens[2], tokens[3], tokens[4]);
       if (tokens[0] == kAddCharacteristicCommand)
         return OnAddCharacteristic(tokens[1], tokens[2], tokens[3], tokens[4]);
       break;
+    case 6:
+      if (tokens[0] == kSetAdvertisementCommand)
+        return OnSetAdvertisement(tokens[1], tokens[2], tokens[3], tokens[4], tokens[5]);
+      if (tokens[0] == kSetScanResponseCommand)
+        return OnSetScanResponse(tokens[1], tokens[2], tokens[3], tokens[4], tokens[5]);
+      break;
     default:
       break;
   }
index 4bcfad0..3661c20 100644 (file)
@@ -76,12 +76,14 @@ class UnixIPCHost {
   bool OnSetAdvertisement(const std::string& service_uuid,
                           const std::string& advertise_uuids,
                           const std::string& advertise_data,
+                          const std::string& manufacturer_data,
                           const std::string& transmit_name);
 
   // Applies settings to scan response.
   bool OnSetScanResponse(const std::string& service_uuid,
                          const std::string& advertise_uuids,
                          const std::string& advertise_data,
+                         const std::string& manufacturer_data,
                          const std::string& transmit_name);
 
   // Starts service (advertisement and connections)