Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] BLE Basic Infrastructure #788

Open
wants to merge 58 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
55b1b8c
Initial commit of BLE support.
bakerstu Mar 3, 2024
fe9215b
Add some BLE tests.
bakerstu Mar 4, 2024
1495a9e
Move from std::string to std::vector container.
bakerstu Mar 4, 2024
8a489bd
Add scan data tests.
bakerstu Mar 4, 2024
b951632
Add more tests.
bakerstu Mar 6, 2024
131eecc
Fill in update() API logic.
bakerstu Mar 6, 2024
3e14e2b
Move advertisements to use std::basic_string.
bakerstu Mar 6, 2024
3f748b7
Test advertisement updates.
bakerstu Mar 10, 2024
0af56e9
Add helpers for grabbing out specific advertisement payload fields.
bakerstu Mar 10, 2024
8415877
Fix include path.
bakerstu Mar 10, 2024
ee21a1e
Add start of OpenLCB BLE advertisement definition.
bakerstu Mar 10, 2024
1b82301
Fix trivial comment.
bakerstu Mar 10, 2024
638457e
Fix math bug.
bakerstu Mar 10, 2024
21f6309
Add OpenLCB BLE advertisement tests.
bakerstu Mar 10, 2024
2ac3e9a
OpenLCB specific BLE definitions.
bakerstu Mar 16, 2024
f3d66cf
Remove redundant parentheses scope.
bakerstu Mar 16, 2024
02da9bb
Add PIP API to SimpleStack.
bakerstu Mar 16, 2024
fae313a
Small updates to openlcb::BLEService.
bakerstu Mar 16, 2024
3fec216
Update BLE definitions.
bakerstu Mar 17, 2024
211cbfb
Add include guards.
bakerstu Mar 17, 2024
9a7c9d3
Update the openlcb::BLEService attributes table.
bakerstu Mar 17, 2024
aabeef6
Add comment.
bakerstu Mar 17, 2024
0c6d45a
Only append name if non-null and length > 0.
bakerstu Mar 18, 2024
8161eed
Add simple BLE connections management structures.
bakerstu Jun 16, 2024
cf0f099
Add OpenLCB BLE Gatt Client manager.
bakerstu Jun 16, 2024
633cdd4
Merge branch 'master' into bakerstu-ble-basics
balazsracz Jun 18, 2024
a8d7880
Merge branch 'master' into bakerstu-ble-basics
balazsracz Jul 4, 2024
2f73be9
Adds more convenient read API to databuffer.
balazsracz Jul 6, 2024
efb7fb4
Fix uninitialized variable warning.
balazsracz Jul 6, 2024
47e7270
Merge remote-tracking branch 'origin/bracz-databuffer-read-api' into …
balazsracz Jul 6, 2024
92a448c
Adds skeleton of BLE hub port base class.
balazsracz Jul 7, 2024
269b602
Adds hub port to the client object.
balazsracz Jul 7, 2024
3380f15
Adds an abstract class for BLE protocol engines. This is needed for p…
balazsracz Jul 8, 2024
550ab81
Updates the HUbPOrt to derive from the proper abstract base class
balazsracz Jul 8, 2024
0b91ddd
Removes misguided attempt to implement the sending inside this class.
balazsracz Jul 8, 2024
5d55772
Adds fuzz test to data buffer.
balazsracz Jul 9, 2024
2bb1adc
Adds accessor to lookup client by connection and output handle.
balazsracz Jul 12, 2024
ea69db8
Ensures that try_append_to will always complete for an empty data buf…
balazsracz Jul 12, 2024
a18d627
Adds implementation for input data for BLEHubPort.
balazsracz Jul 12, 2024
3490bbb
Adds more fuzz testing capability to the data buffer test.
balazsracz Jul 13, 2024
acd069d
Fix some crashing cornercases.
balazsracz Jul 13, 2024
ee002f4
Adds utility function to find clients by the inbound handle.
balazsracz Jul 13, 2024
3511406
Adds more fuzz test debugging.
balazsracz Jul 13, 2024
8107eb5
Expands the cases where try_append_from succeeds.
balazsracz Jul 13, 2024
58de008
Adds a debugging facility that verifies that data buffer unrefs are c…
balazsracz Jul 13, 2024
a23c54e
Finishes fuzz tests.
balazsracz Jul 13, 2024
90ce34c
Rewrite data read advance to be much simpler.
balazsracz Jul 13, 2024
bb31bbc
Fixes crashes in the duffer append code.
balazsracz Jul 13, 2024
32c32fe
Add API for getting the current active connection count.
bakerstu Jul 13, 2024
131ea5f
Bump task stack for TWAI watchdog task.
balazsracz Jul 13, 2024
fadeff5
Ensure we are using the ESP32's logging facility for ESP_PLATFORM.
balazsracz Jul 13, 2024
2c943bd
Fix bugs that caused data loss over BLE:
balazsracz Jul 13, 2024
41c0a9f
Fix bug when we take bytes from an appendable data buffer.
balazsracz Jul 13, 2024
83f3507
Fixes bug in tracking pending bytes in the queue.
balazsracz Jul 14, 2024
658a002
Releases the notifiable of the first buffer faster.
balazsracz Jul 14, 2024
ff56b5f
Fixes bug in counting pending bytes.
balazsracz Jul 14, 2024
2459361
Fix bug that might be the cause of the disconnect crash.
balazsracz Jul 18, 2024
109a67d
Fix comment.
bakerstu Jul 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions etc/config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ ifndef MAKE_INC_CONFIG_MK
MAKE_INC_CONFIG_MK := 1

ifneq ($(TARGET),bare.pruv3)
CORELIBS := console utils executor os dcc openlcb withrottle
CORELIBS := console utils executor os dcc openlcb withrottle ble

LINKCORELIBS = -lconsole -lopenlcb -lwithrottle -ldcc -lexecutor -lutils -lexecutor -los
LINKCORELIBS = -lconsole -lopenlcb -lwithrottle -ldcc -lexecutor -lutils -lexecutor -los -lble
endif

endif # MAKE_INC_CONFIG_MK
168 changes: 168 additions & 0 deletions src/ble/Advertisement.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/** @copyright
* Copyright (c) 2024, Stuart Baker
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are strictly prohibited without written consent.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file Advertisement.cxx
*
* Advertisement definition.
*
* @author Stuart Baker
* @date 2 March 2024
*/

#include "ble/Advertisement.hxx"

namespace ble
{

//
// Advertisement::concat_service_data_128()
//
std::basic_string<uint8_t> Advertisement::concat_service_data_128(
const uint8_t uuid[16], const void *buf, size_t size)
{
const uint8_t *data = static_cast<const uint8_t*>(buf);
std::basic_string<uint8_t> result(uuid, uuid + 16);
result.append(data, size);
return result;
}

//
// Advertisement::prepend()
//
int Advertisement::prepend(
Field field, Defs::AdvType type, const void *buf, size_t size, bool clip)
{
const uint8_t *data = static_cast<const uint8_t*>(buf);
std::basic_string<uint8_t> *d;
size_t max;

switch (field)
{
default:
case Field::DATA:
d = &data_;
max = extended_ ?
MAX_EXT_DATA_PAYLOAD_SIZE : MAX_SCAN_DATA_PAYLOAD_SIZE;
break;
case Field::SCAN_DATA:
HASSERT(!extended_);
d = &scanData_;
max = MAX_DATA_PAYLOAD_SIZE;
break;
}

size_t space = std::min((size + 2), (max - d->size()));
if (space < (size + 2) && clip == false)
{
// Data doesn't fit and clipping is not allowed.
return -1;
}
d->insert(0, 1, space - 1);
d->insert(1, 1, static_cast<uint8_t>(type));
d->insert(2, data, space - 2);
return space;
}

//
// Advertisement::append()
//
int Advertisement::append(
Field field, Defs::AdvType type, const void *buf, size_t size, bool clip)
{
const uint8_t *data = static_cast<const uint8_t*>(buf);
std::basic_string<uint8_t> *d;
size_t max;

switch (field)
{
default:
case Field::DATA:
d = &data_;
max = extended_ ?
MAX_EXT_DATA_PAYLOAD_SIZE : MAX_SCAN_DATA_PAYLOAD_SIZE;
break;
case Field::SCAN_DATA:
HASSERT(!extended_);
d = &scanData_;
max = MAX_DATA_PAYLOAD_SIZE;
break;
}

size_t space = std::min((size + 2), (max - d->size()));
if (space < (size + 2) && clip == false)
{
// Data doesn't fit and clipping is not allowed.
return -1;
}
d->push_back(space - 1);
d->push_back(static_cast<uint8_t>(type));
d->append(data, space - 2);
return space;
}

//
// Advertisement::update()
//
int Advertisement::update(Field field, Defs::AdvType type, const void *buf,
size_t size, unsigned instance, bool exact_size,
bool clip)
{
const uint8_t *data = static_cast<const uint8_t*>(buf);
std::basic_string<uint8_t> *d;
size_t max;

switch (field)
{
default:
case Field::DATA:
d = &data_;
max = extended_ ?
MAX_EXT_DATA_PAYLOAD_SIZE : MAX_SCAN_DATA_PAYLOAD_SIZE;
break;
case Field::SCAN_DATA:
HASSERT(!extended_);
d = &scanData_;
max = MAX_DATA_PAYLOAD_SIZE;
break;
}

uint8_t len;
ssize_t pos = Defs::adv_find_data(*d, type, &len, instance);
if (pos < 0)
{
// No matching advertising data found.
return -1;
}
if (exact_size && len != size)
{
// Found the data, but it is the wrong size.
return -1;
}
size_t space = std::min((size + 2), (max - d->size()) + (len + 2));
if (space < size && clip == false)
{
// Data doesn't fit and clipping is not allowed.
return -1;
}
d->at(pos) = space - 1;
d->replace(pos + 2, len, data, space - 2);
return space;
}

} // namespace ble
Loading
Loading