# BLE and a complete BLE Mesh stack, in pure Kern, verified on hardware

> On main since rc2: BLE and a complete BLE Mesh stack, in pure Kern, verified on hardware. Kern reaches the device tier without a C dependency.

Source: https://kern-lang.eu/releases/ble-mesh-in-pure-kern

On main since rc2

## Release notes

Kern reaches the device tier without a C dependency. `sys.hci` drives a Bluetooth controller over `HCI_CHANNEL_USER`, claiming the adapter exclusively the way a from-scratch host stack does, which is what mesh needs because it wants precise control of scanning and advertising rather than sharing with the kernel. It is verified against a real controller: `hci_local_version` returned HCI 5.2 and matched `hciconfig` exactly, revision included. `sys.ble` adds active LE scanning (parsing advertising reports into address, RSSI, flags, local name, manufacturer data and service UUIDs, deduplicated and merged with scan responses) and the advertising bearer that mesh provisioning rides on.

On top of that the **BLE Mesh stack is complete**: network layer with obfuscation, AES-CCM, replay protection, IV index, segmentation and relay; the access layer and a Generic OnOff model for real device messages; Secure Network Beacon; commissioning, revocation and configuration; Heartbeat publication and subscription for topology discovery; Friendship, so a Low Power Node can sleep while a Friend queues its messages; and the Proxy protocol with PDUs and SAR.

Provisioning is **P-256 ECDH written from scratch in Kern**, deliberately on 16-bit limbs rather than 32, because Kern integer arithmetic is overflow-checked and traps, so a 32×32 limb product would abort. It is verified against authority rather than itself: point doubling matches the standard vector in both coordinates, a derived public key matches one generated by OpenSSL, and the shared secret matches `openssl pkeyutl -derive`. Scalar multiplication is constant-time, which closes the provisioning timing side channel, and an invalid-curve hole found during the work was fixed.

The whole stack is pure Kern over the unsafe systems tier, no new C, **TCB unchanged**. Alongside it, `sys.bluetooth` gained a real RFCOMM implementation and `sys.wifi` stopped being a stub, which together retire the last stubs in the standard library.
