Skip to content

Commit

Permalink
Fix pairing procedure handling
Browse files Browse the repository at this point in the history
  • Loading branch information
datacompboy committed Dec 24, 2024
1 parent fb73419 commit af15799
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ CONFIG_USB_DEVICE_PRODUCT="nRF KAT-VR Receiver"
CONFIG_USB_DEVICE_VID=0xC4F4
CONFIG_USB_DEVICE_PID=0x2F37
# Kat libraries support SN length up to 12 chars with 11 being used now.
CONFIG_USB_DEVICE_SN="ITWILLCHANGE"
CONFIG_USB_DEVICE_SN="TEMPLATE11c"

# Enable settings
CONFIG_NVS=y
Expand Down
2 changes: 1 addition & 1 deletion scripts/install/clone-kat-device.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ if ($dev.serialNumber -ne $newSn) {
# Write the pairing info
$pairing=[IBizLibrary.KATSDKInterfaceHelper]::receiverPairingInfoSave.ReceiverPairingByte
[byte[]]$ans = New-Object byte[] 32
[byte[]]$command = 0x20,0x1f,0x55,0xAA,0x00,0x00,0x20,0x00 + $pairing + $ans
[byte[]]$command = 0x20,0x1f,0x55,0xAA,0x00,0x00,0x20 + $pairing + $ans
[IBizLibrary.KATSDKInterfaceHelper]::SendHIDCommand($dev.serialNumber, $command, 32, $ans, 32)

Write-Host "Congratulations! The device is ready to use."
19 changes: 14 additions & 5 deletions src/kat_usb_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ typedef __PACKED_UNION
}
ansaddrs;
__PACKED_STRUCT
{
uint8_t count;
uint8_t addrs[4][6]; // maximum 4 child MACs fits
uint8_t zero;
}
writeaddrs; // Differs from 'ansaddrs', there is no zero byte before count!
__PACKED_STRUCT
{
uint8_t sensor_id;
uint8_t sensor_type;
Expand Down Expand Up @@ -195,7 +202,7 @@ bool kat_usb_handle_request(uint8_t *buf, int size)

case cGetSN:
pack->data.ansstring.zero = 0;
strncpy(pack->data.ansstring.ans, CONFIG_USB_DEVICE_SN, KAT_USB_PACKET_LEN - 8);
strncpy(pack->data.ansstring.ans, katUsbSerial, KAT_USB_PACKET_LEN - 8);
pack->data.ansstring.ans[sizeof(pack->data.ansstring.ans) - 1] = 0; // ensure null termination
return true;

Expand Down Expand Up @@ -224,16 +231,18 @@ bool kat_usb_handle_request(uint8_t *buf, int size)
return true;

case cWritePairing:
const int wcnt = MIN(ARRAY_SIZE(KatBleDevices), pack->data.ansaddrs.count);
const int wcnt = MIN(ARRAY_SIZE(KatBleDevices), pack->data.writeaddrs.count);
NumKatBleDevices = wcnt;
for (int i = 0; i < wcnt; ++i)
{
BUILD_ASSERT(sizeof(pack->data.ansaddrs.addrs[i]) == sizeof(KatBleDevices[i].a), "Size of BT address should match");
memcpy(&KatBleDevices[i].a, &pack->data.ansaddrs.addrs[i], sizeof(KatBleDevices[i].a));
BUILD_ASSERT(sizeof(pack->data.writeaddrs.addrs[i]) == sizeof(KatBleDevices[i].a), "Size of BT address should match");
memcpy(&KatBleDevices[i].a, &pack->data.writeaddrs.addrs[i], sizeof(KatBleDevices[i].a));
}
kat_ble_update_devices();
kat_settings_async_save();
return false;
// original receiver returns only command confirmation packet, no data
memset(&pack->data.writeaddrs, 0, sizeof(pack->data.writeaddrs));
return true;

case cDeepSleep:
return false;
Expand Down

0 comments on commit af15799

Please sign in to comment.