From aa9e17bc61324446b9e0199630fb772b9afb1109 Mon Sep 17 00:00:00 2001 From: Ian Coolidge Date: Wed, 12 Aug 2015 14:53:15 -0700 Subject: [PATCH] service: Allow manufacturer data to be set. Plumbs IPC and stack code for manufacturer data on advertisement or scan response. Change-Id: I4b70506e35f51479bdf4073c31e4cb4f88fa2c98 --- service/gatt_server.cpp | 20 +++++++++++++------- service/gatt_server.h | 10 ++++++---- service/ipc/unix_ipc_host.cpp | 34 ++++++++++++++++++++++++++-------- service/ipc/unix_ipc_host.h | 2 ++ 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/service/gatt_server.cpp b/service/gatt_server.cpp index 7aa930f2a..54a261817 100644 --- a/service/gatt_server.cpp +++ b/service/gatt_server.cpp @@ -567,10 +567,12 @@ bool Server::Initialize(const Uuid &service_id, int *gatt_pipe, CoreStack *bt) { return true; } -bool Server::SetAdvertisement(const std::vector &ids, - const std::vector &service_data, +bool Server::SetAdvertisement(const std::vector& ids, + const std::vector& service_data, + const std::vector& manufacturer_data, bool transmit_name) { std::vector 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 &ids, false, /* no txpower */ 2, 2, /* interval */ 0, /* appearance */ - 0, nullptr, /* no mfg data */ + mutable_manufacturer_data.size(), + reinterpret_cast(mutable_manufacturer_data.data()), mutable_service_data.size(), reinterpret_cast(mutable_service_data.data()), id_data.size(), reinterpret_cast(id_data.data())); @@ -598,10 +601,12 @@ bool Server::SetAdvertisement(const std::vector &ids, return true; } -bool Server::SetScanResponse(const std::vector &ids, - const std::vector &service_data, - bool transmit_name) { +bool Server::SetScanResponse(const std::vector& ids, + const std::vector& service_data, + const std::vector& manufacturer_data, + bool transmit_name) { std::vector 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 &ids, false, /* no txpower */ 2, 2, /* interval */ 0, /* appearance */ - 0, nullptr, /* no mfg data */ + mutable_manufacturer_data.size(), + reinterpret_cast(mutable_manufacturer_data.data()), mutable_service_data.size(), reinterpret_cast(mutable_service_data.data()), id_data.size(), reinterpret_cast(id_data.data())); diff --git a/service/gatt_server.h b/service/gatt_server.h index c61399a50..778b136a4 100644 --- a/service/gatt_server.h +++ b/service/gatt_server.h @@ -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 &ids, - const std::vector &service_data, + bool SetAdvertisement(const std::vector& ids, + const std::vector& service_data, + const std::vector& manufacturer_data, bool transmit_name); // Control the content of service scan response. - bool SetScanResponse(const std::vector &ids, - const std::vector &service_data, + bool SetScanResponse(const std::vector& ids, + const std::vector& service_data, + const std::vector& manufacturer_data, bool transmit_name); // Add an ordinary characteristic for reading and/or writing. diff --git a/service/ipc/unix_ipc_host.cpp b/service/ipc/unix_ipc_host.cpp index bd1570dd3..dc2e9816f 100644 --- a/service/ipc/unix_ipc_host.cpp +++ b/service/ipc/unix_ipc_host.cpp @@ -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 blob_data(decoded_data.begin(), decoded_data.end()); - gatt_servers_[service_uuid]->SetAdvertisement(ids, blob_data, + std::vector decoded_advertise_data(decoded_data.begin(), + decoded_data.end()); + + base::Base64Decode(manufacturer_data, &decoded_data); + std::vector 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 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 blob_data(decoded_data.begin(), decoded_data.end()); - gatt_servers_[service_uuid]->SetScanResponse(ids, blob_data, + std::vector decoded_advertise_data(decoded_data.begin(), + decoded_data.end()); + + base::Base64Decode(manufacturer_data, &decoded_data); + std::vector 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; } diff --git a/service/ipc/unix_ipc_host.h b/service/ipc/unix_ipc_host.h index 4bcfad026..3661c2036 100644 --- a/service/ipc/unix_ipc_host.h +++ b/service/ipc/unix_ipc_host.h @@ -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) -- 2.11.0