
Renik
Comprehensive embedded device configuration library for no_std environments.
Renik provides robust configuration structures for embedded devices, featuring complete Wi-Fi connectivity management, advanced Bluetooth device lifecycle management with finite state machine (FSM) support, and secure device identification. All structures are designed for no_std environments with #[repr(C)] memory layout for reliable serialization and persistent storage.
Features
- Wi-Fi Configuration: Store and manage Wi-Fi network credentials with
WifiConfig - Complete Bluetooth Management: Full device lifecycle management including:
- Individual device information with pairing data (
BluetoothDeviceInfo) - Multi-device list management up to 10 devices (
BluetoothDeviceList) - Real-time connection state tracking with FSM (
BluetoothConnectionState) - Connection phase management with
BluetoothConnectionPhaseenum - Type-safe connection handles with validation (
ConnHandle) - Low-level connection parameters (
BluetoothConnectionParams) - Security and authentication data (
BluetoothSecurityInfo)
- Individual device information with pairing data (
- Device Identity: Secure device identification and authentication with
DeviceInfo - Memory Safe: Fixed-size buffers with length tracking prevent overflows
- Serializable:
#[repr(C)]layout ensures consistent cross-platform serialization - Embedded Ready: Full
no_stdcompatibility with minimal dependencies - Production Ready: Comprehensive error handling and validation
- State Management: Advanced finite state machine for Bluetooth connection phases
Quick Start
Add this to your Cargo.toml:
[]
= "0.7.0"
Wi-Fi Configuration
use WifiConfig;
// Create a new Wi-Fi configuration
let config = new?;
// Validate and use
if config.is_valid
Bluetooth Device Management
Individual Device Configuration
use BluetoothDeviceInfo;
// Create a Bluetooth device configuration
let mac_address = ;
let mut device = new?;
// Set pairing information
device.set_pairing_key?;
device.set_class_of_device; // Audio device
// Set device flags
device.add_flag;
device.add_flag;
device.add_flag;
device.add_flag;
// Check device status
if device.is_paired && device.supports_auto_reconnect
Managing Multiple Devices
use ;
// Create device list (supports up to 10 devices)
let mut device_list = default;
// Add multiple devices
let speaker_mac = ;
let speaker = new?;
let mouse_mac = ;
let mouse = new?;
device_list.add_device?;
device_list.add_device?;
// Iterate through devices
for i in 0..device_list.len
Connection State Management with FSM
use ;
// Track connection state with finite state machine
let mut connection_state = default;
// Set remote device
let mac_addr = ;
let device = new?;
connection_state.set_remote_device;
// Advance through connection phases using FSM
assert!;
assert!;
assert!;
// Invalid transitions are rejected
assert!; // Invalid: must authenticate first
// Continue through authentication
assert!;
assert!;
assert!;
assert!;
// Check current phase and state
let current_phase = connection_state.connection_phase;
println!;
println!;
println!;
println!;
// Type-safe connection handles
let handle = new; // Validates range 0x0000-0x0EFF
connection_state.set_connection_handle;
println!;
Connection Phase States
The Bluetooth FSM supports the following connection phases:
- Idle: Initial state, no connection attempt
- Discovery: Discovering available devices
- Connecting: Initiating connection to specific device
- Connected: Basic connection established (not authenticated)
- Authenticating: Authentication in progress
- SettingUpEncryption: Setting up encrypted communication
- FullyConnected: Connected, authenticated, and encrypted
- ServiceDiscovery: Discovering available services
- Ready: Connection ready for use
- Maintaining: Connection maintenance mode
- Reconnecting: Attempting to reconnect after connection loss
- Failed: Connection failed
- Disconnecting: Graceful disconnection in progress
Device Information
use DeviceInfo;
// Create device identity configuration
let device_info = new?;
if device_info.is_valid
Advanced Bluetooth Features
Connection Parameters
use ;
// Create connection parameters
let mut params = default;
params.set_connection_handle;
params.set_connection_interval; // 30ms (24 * 1.25ms)
params.set_connection_latency;
params.set_supervision_timeout; // 2000ms (200 * 10ms)
params.set_rssi; // Good signal strength
// Update device with connection parameters
let mac_addr = ;
let mut device = new?;
device.update_connection_params;
Security Information
use ;
// Create security information
let mut security = default;
security.set_link_key;
security.set_link_key_valid;
security.set_authenticated;
security.set_encrypted;
security.set_security_level; // High security
// Update device with security information
let mac_addr = ;
let mut device = new?;
device.update_security_info;
Persistent Storage
All configuration structures can be serialized for persistent storage:
use ;
use File;
use ;
// Create and configure device list
let mut device_list = default;
let mac_address = ;
let device = new?;
device_list.add_device?;
// Serialize to bytes
let list_bytes = unsafe ;
// Save to persistent storage
let mut file = create?;
file.write_all?;
// Later: Load from storage
let mut file = open?;
let mut loaded_bytes = vec!;
file.read_exact?;
let loaded_list: BluetoothDeviceList = unsafe ;
// Use loaded device list for reconnection
for i in 0..loaded_list.len
Structure Sizes
All structures are optimized for embedded use with predictable memory footprints:
WifiConfig: 104 bytes (32B SSID + 64B password + metadata)BluetoothDeviceInfo: ~200 bytes (includes connection params and security info)BluetoothDeviceList: ~2KB (10 devices + metadata)BluetoothConnectionState: ~220 bytes (device info + FSM state)BluetoothConnectionParams: 32 bytes (connection timing and quality metrics)BluetoothSecurityInfo: 32 bytes (authentication and encryption data)ConnHandle: 2 bytes (type-safe u16 wrapper with validation)BluetoothConnectionPhase: 1 byte (enum with u8 representation)DeviceInfo: 164 bytes (32B hardware ID + 128B secret + metadata)
Bluetooth Device Types
BluetoothDeviceInfo automatically categorizes devices based on Class of Device:
DEVICE_TYPE_COMPUTER: Desktop/laptop computersDEVICE_TYPE_PHONE: Mobile phones and smartphonesDEVICE_TYPE_AUDIO: Headphones, speakers, audio devicesDEVICE_TYPE_PERIPHERAL: Keyboards, mice, input devicesDEVICE_TYPE_IMAGING: Cameras, printers, scannersDEVICE_TYPE_WEARABLE: Smartwatches, fitness trackersDEVICE_TYPE_TOY: Gaming devices, toysDEVICE_TYPE_NETWORK: Network access pointsDEVICE_TYPE_UNKNOWN: Unrecognized or uncategorized devices
Bluetooth Device Flags
BluetoothDeviceInfo supports comprehensive device capability and status flags:
FLAG_PAIRED: Device is paired and authenticatedFLAG_TRUSTED: Device is trusted for automatic connectionsFLAG_AUDIO: Device supports audio profiles (A2DP, HFP, etc.)FLAG_INPUT: Device supports input (HID profile - keyboards, mice)FLAG_FILE_TRANSFER: Device supports file transfer (OBEX, FTP)FLAG_CONNECTED: Device is currently connectedFLAG_AUTO_RECONNECT: Device supports automatic reconnectionFLAG_RECENTLY_DISCOVERED: Device was discovered in recent scan
Error Handling
The library provides comprehensive error handling with specific error types:
Error::CredentialLengthExceeded: Wi-Fi SSID (>32 bytes) or password (>64 bytes) too longError::IdentityLengthExceeded: Device hardware ID (>32 bytes) or secret (>128 bytes) too longError::InvalidBluetoothDeviceInfo: Bluetooth device name (>32 bytes) or pairing key (>64 bytes) too longError::DeviceListFull: Bluetooth device list already contains maximum devices (10)Error::IndexOutOfBounds: Attempted to access device at invalid index
All functions return Result<T, Error> for proper error handling:
use ;
match new
Use Cases
Embedded Bluetooth Audio Systems: Store paired speaker/headphone configurations with automatic reconnection capabilities.
IoT Device Management: Maintain device identity and Wi-Fi credentials across power cycles.
Wearable Devices: Manage connections to multiple peripherals (phones, sensors, accessories) with efficient storage.
Industrial Automation: Persistent device pairing for sensors, actuators, and control systems.
Home Automation: Store and manage connections to various smart home devices.
License
The MIT License (MIT) Copyright © 2025 rttf.dev
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.