Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions right/src/config_parser/parse_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#ifdef __ZEPHYR__
#include "usb_commands/usb_command_get_new_pairings.h"
#include "bt_manager.h"
#include "bt_pair.h"
#include "state_sync.h"
#else
Expand Down Expand Up @@ -257,6 +258,16 @@ parser_error_t parseConfig(config_buffer_t *buffer)
secondaryRoles_AdvancedStrategyTimeoutType = ReadUInt8(buffer);
}

// Version 15:

bool bt_AlwaysAdvertise = Cfg.Bt_AlwaysAdvertise;
bool bt_KeepConnectionsAlive = Cfg.Bt_KeepConnectionsAlive;

if (DataModelVersion.major >= 15) {
bt_AlwaysAdvertise = ReadBool(buffer);
bt_KeepConnectionsAlive = ReadBool(buffer);
}

// HostConnection configuration

if (VERSION_AT_LEAST(DataModelVersion, 8, 1, 0)) {
Expand Down Expand Up @@ -418,6 +429,13 @@ parser_error_t parseConfig(config_buffer_t *buffer)
}
}

// Version 15

if (DataModelVersion.major >= 15) {
Cfg.Bt_AlwaysAdvertise = bt_AlwaysAdvertise;
Cfg.Bt_KeepConnectionsAlive = bt_KeepConnectionsAlive;
}

// Version 8


Expand All @@ -439,6 +457,7 @@ parser_error_t parseConfig(config_buffer_t *buffer)
BtPair_AllocateUnregisteredBonds();
BtConn_UpdateHostConnectionPeerAllocations();
UsbCommand_UpdateNewPairingsFlag();
BtManager_StartScanningAndAdvertisingAsync(false, "parse_config - bluetooth settings applied");
#endif
WormCfg->devMode = Cfg.DevMode;
LedManager_FullUpdate();
Expand Down
16 changes: 15 additions & 1 deletion right/src/host_connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ host_connection_t HostConnections[HOST_CONNECTION_COUNT_MAX] = {
},
};

host_known_t HostConnections_IsKnownBleAddress(const bt_addr_le_t *address) {
host_known_t HostConnections_LookupBleAddress(const bt_addr_le_t *address, uint8_t *outConnectionId) {
if (outConnectionId) {
*outConnectionId = ConnectionId_Invalid;
}

for (int i = 0; i < HOST_CONNECTION_COUNT_MAX; i++) {
host_connection_type_t type = HostConnections[i].type;
switch (type) {
Expand All @@ -43,12 +47,18 @@ host_known_t HostConnections_IsKnownBleAddress(const bt_addr_le_t *address) {
break;
case HostConnectionType_UnregisteredBtHid:
if (BtAddrEq(address, &HostConnections[i].bleAddress)) {
if (outConnectionId) {
*outConnectionId = ConnectionId_HostConnectionFirst + i;
}
return HostKnown_Unregistered;
}
break;
case HostConnectionType_Dongle:
case HostConnectionType_BtHid:
if (BtAddrEq(address, &HostConnections[i].bleAddress)) {
if (outConnectionId) {
*outConnectionId = ConnectionId_HostConnectionFirst + i;
}
return HostKnown_Registered;
}
break;
Expand All @@ -66,6 +76,10 @@ host_known_t HostConnections_IsKnownBleAddress(const bt_addr_le_t *address) {
return HostKnown_Unknown;
}

host_known_t HostConnections_IsKnownBleAddress(const bt_addr_le_t *address) {
return HostConnections_LookupBleAddress(address, NULL);
}

host_connection_t* HostConnection(uint8_t connectionId) {
if (connectionId < ConnectionId_HostConnectionFirst || connectionId > ConnectionId_HostConnectionLast) {
return NULL;
Expand Down
1 change: 1 addition & 0 deletions right/src/host_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
// Functions:

host_known_t HostConnections_IsKnownBleAddress(const bt_addr_le_t *address);
host_known_t HostConnections_LookupBleAddress(const bt_addr_le_t *address, uint8_t *outConnectionId);
host_connection_t* HostConnection(uint8_t connectionId);

void HostConnections_ListKnownBleConnections();
Expand Down
7 changes: 6 additions & 1 deletion right/src/usb_commands/usb_command_get_device_property.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ void UsbCommand_GetDeviceProperty(const uint8_t *GenericHidOutBuffer, uint8_t *G
} break;
case DevicePropertyId_NewPairings:
#ifdef __ZEPHYR__
UsbCommand_GetNewPairings(GetUsbRxBufferUint8(2), GenericHidOutBuffer, GenericHidInBuffer);
UsbCommand_GetNewPairings(GetUsbRxBufferUint8(2), false, GenericHidOutBuffer, GenericHidInBuffer);
#endif
break;
case DevicePropertyId_NewPairingsWithSlots:
#ifdef __ZEPHYR__
UsbCommand_GetNewPairings(GetUsbRxBufferUint8(2), true, GenericHidOutBuffer, GenericHidInBuffer);
#endif
break;
default:
Expand Down
1 change: 1 addition & 0 deletions right/src/usb_commands/usb_command_get_device_property.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
DevicePropertyId_PairedRightPeerBleAddress = 10,
DevicePropertyId_PairingStatus = 11,
DevicePropertyId_NewPairings = 12,
DevicePropertyId_NewPairingsWithSlots = 13,
} device_property_t;

typedef enum {
Expand Down
51 changes: 39 additions & 12 deletions right/src/usb_commands/usb_command_get_new_pairings.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,66 @@
#include "usb_protocol_handler.h"
#include "bt_conn.h"
#include <zephyr/bluetooth/addr.h>
#include "connections.h"
#include "host_connection.h"

#define ADDRESS_COUNT_PER_PAGE 10
#define ADDRESS_AND_SLOT_COUNT_PER_PAGE 8

#define HEADER_LENGTH 2

typedef struct {
const uint8_t *OutBuffer;
uint8_t *InBuffer;
uint8_t pageIdxOffset;
uint8_t writeOffset;
uint8_t addressCount;
bool withSlots;
bool dryRun;
} CommandUserData;

static uint8_t entryLength(bool withSlots) {
return withSlots ? BLE_ADDR_LEN + 1 : BLE_ADDR_LEN;
}

static uint8_t entriesPerPage(bool withSlots) {
return withSlots ? ADDRESS_AND_SLOT_COUNT_PER_PAGE : ADDRESS_COUNT_PER_PAGE;
}

static void bt_foreach_bond_cb(const struct bt_bond_info *info, void *user_data)
{
CommandUserData *data = (CommandUserData *)user_data;
uint8_t *GenericHidInBuffer = data->InBuffer;

if ((data->writeOffset + BLE_ADDR_LEN + 1) >= USB_COMMAND_BUFFER_LENGTH) {
return;
}
uint8_t connectionId;

if (HostConnections_IsKnownBleAddress(&info->addr) != HostKnown_Unregistered) {
if (HostConnections_LookupBleAddress(&info->addr, &connectionId) != HostKnown_Unregistered) {
return;
}

Bt_NewPairedDevice = true;

data->addressCount++;
uint8_t addressIdx = data->addressCount++;

if (data->dryRun) {
return;
}

if (addressIdx < data->pageIdxOffset || addressIdx >= data->pageIdxOffset + entriesPerPage(data->withSlots)) {
return;
}

if (!data->dryRun && data->addressCount >= data->pageIdxOffset && data->addressCount < data->pageIdxOffset+ADDRESS_COUNT_PER_PAGE) {
SetUsbTxBufferBleAddress(data->writeOffset, &info->addr);
data->writeOffset += BLE_ADDR_LEN;
if (data->writeOffset + entryLength(data->withSlots) > USB_COMMAND_BUFFER_LENGTH) {
return;
}

SetUsbTxBufferBleAddress(data->writeOffset, &info->addr);
data->writeOffset += BLE_ADDR_LEN;

if (data->withSlots) {
SetUsbTxBufferUint8(data->writeOffset, connectionId - ConnectionId_HostConnectionFirst);
data->writeOffset += 1;
}
}

void UsbCommand_UpdateNewPairingsFlag() {
Expand All @@ -46,21 +71,23 @@ void UsbCommand_UpdateNewPairingsFlag() {
.OutBuffer = NULL,
.InBuffer = NULL,
.pageIdxOffset = 0,
.writeOffset = 2,
.writeOffset = HEADER_LENGTH,
.addressCount = 0,
.withSlots = false,
.dryRun = true,
};

bt_foreach_bond(BT_ID_DEFAULT, bt_foreach_bond_cb, &data);
}

void UsbCommand_GetNewPairings(uint8_t page, const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) {
void UsbCommand_GetNewPairings(uint8_t page, bool withSlots, const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer) {
CommandUserData data = {
.OutBuffer = GenericHidOutBuffer,
.InBuffer = GenericHidInBuffer,
.pageIdxOffset = ADDRESS_COUNT_PER_PAGE*page,
.writeOffset = 2,
.pageIdxOffset = entriesPerPage(withSlots)*page,
.writeOffset = HEADER_LENGTH,
.addressCount = 0,
.withSlots = withSlots,
.dryRun = false,
};

Expand Down
3 changes: 2 additions & 1 deletion right/src/usb_commands/usb_command_get_new_pairings.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
// Includes:

#include <stdint.h>
#include <stdbool.h>

// Typedefs:

// Functions:

void UsbCommand_UpdateNewPairingsFlag();
void UsbCommand_GetNewPairings(uint8_t page, const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer);
void UsbCommand_GetNewPairings(uint8_t page, bool withSlots, const uint8_t *GenericHidOutBuffer, uint8_t *GenericHidInBuffer);

#endif

Expand Down
4 changes: 2 additions & 2 deletions scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"shelljs": "^0.8.4"
},
"firmwareVersion": "17.2.0",
"deviceProtocolVersion": "4.18.1",
"deviceProtocolVersion": "4.19.0",
"moduleProtocolVersion": "4.3.0",
"dongleProtocolVersion": "2.0.0",
"userConfigVersion": "14.0.0",
"userConfigVersion": "15.0.0",
"hardwareConfigVersion": "1.0.0",
"smartMacrosVersion": "3.15.0",
"devices": [
Expand Down