Define BLE v5 visibility, admission and bounded publication contracts
This commit is contained in:
1 parent
5deb6de7ee
commit
d00a642c49
3 files changed
+19
-11
No files matched your search
+10
-4
@@ -285,7 +285,8 @@ struct WinState : std::enable_shared_from_this<WinState> {
|
||||
parameters.IsConnectable(true); parameters.IsDiscoverable(broadcast_enabled);
|
||||
DEBUG_INFO(CAT, "BLE WinRT start single GATT advertisement UUID=%s connectable=1 discoverable=%d",
|
||||
service_uuid.c_str(), broadcast_enabled);
|
||||
service_requested = true; publication_deadline = get_time_us() + 20000000;
|
||||
service_requested = true;
|
||||
if (!publication_deadline) publication_deadline = get_time_us() + 20000000;
|
||||
step("GattServiceProvider.StartAdvertising"); provider.StartAdvertising(parameters);
|
||||
}
|
||||
/* Один GATT provider обслуживает и обнаружение, и подключения; отдельного publisher нет. */
|
||||
@@ -304,11 +305,14 @@ struct WinState : std::enable_shared_from_this<WinState> {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (status == GattServiceProviderAdvertisementStatus::Started) {
|
||||
if (status == GattServiceProviderAdvertisementStatus::Started ||
|
||||
status == GattServiceProviderAdvertisementStatus::StartedWithoutAllAdvertisementData) {
|
||||
if (status != GattServiceProviderAdvertisementStatus::Started)
|
||||
DEBUG_WARN(CAT, "BLE WinRT advertising omitted some fields UUID=%s; confirm service UUID on scanner", service_uuid.c_str());
|
||||
publication_deadline = 0; service_ready = true;
|
||||
ble_backend_advertising(owner, broadcast_enabled ? BLE_READY : BLE_CLOSED, "GATT discovery publication applied"); ready();
|
||||
} else if (status == GattServiceProviderAdvertisementStatus::Aborted) radio_error("GATT advertising aborted", error);
|
||||
else if (service_requested) fail("GATT advertisement stopped unexpectedly");
|
||||
else if (service_requested && service_ready) fail("GATT advertisement stopped unexpectedly");
|
||||
}
|
||||
/* Только доступные Win11 API: фактические параметры отделены от запрошенного профиля. */
|
||||
void log_connection(ble_link_id id) {
|
||||
@@ -792,6 +796,7 @@ extern "C" struct ble_backend* ble_backend_create(struct ble_transport* owner, s
|
||||
auto state = std::make_shared<WinState>(); state->owner = owner; state->ua = ua; state->company = cfg->company_id;
|
||||
state->broadcast_size = cfg->initial_advertisement_size;
|
||||
state->broadcast_enabled = state->broadcast_size != 0;
|
||||
state->publication_deadline = get_time_us() + 20000000;
|
||||
char uuid[37]; if (ble_service_uuid_encode(uuid, cfg->node_id)) return nullptr; state->service_uuid = uuid;
|
||||
if (state->broadcast_size > state->broadcast.size()) { DEBUG_ERROR(CAT, "BLE WinRT initial advertisement too large"); return nullptr; }
|
||||
if (state->broadcast_size) std::memcpy(state->broadcast.data(), cfg->initial_advertisement, state->broadcast_size);
|
||||
@@ -827,9 +832,10 @@ extern "C" struct ble_backend* ble_backend_create(struct ble_transport* owner, s
|
||||
if (!adapter.IsLowEnergySupported() || !adapter.IsCentralRoleSupported() || !adapter.IsPeripheralRoleSupported()) {
|
||||
s.fail("adapter lacks BLE central/peripheral support"); return;
|
||||
}
|
||||
s.adapter_ready = true; WinState::diagnostics_tick(&s);
|
||||
s.adapter_ready = true;
|
||||
s.ensure_service();
|
||||
});
|
||||
WinState::diagnostics_tick(state.get());
|
||||
void* memory = u_malloc(sizeof(ble_backend));
|
||||
if (!memory) { DEBUG_ERROR(CAT, "BLE WinRT allocation failed"); state->shutdown(); return nullptr; }
|
||||
return new(memory) ble_backend{state};
|
||||
|
||||
Reference in new issue
Block a user