BLE Debugging and Error Handling#
The Bluetooth Low Energy (BLE) stack returns error codes to indicate the success or failure of operations. Understanding and handling these errors is essential for robust BLE applications.
Error Code Format#
Return Values:
0 (RSI_SUCCESS): Operation completed successfully
Non-Zero Values: Error codes indicating specific failure reasons
Error Callbacks: Some errors are delivered asynchronously through event callbacks
Error Code Sources:
Synchronous Errors: Returned directly from API function calls
Asynchronous Errors: Delivered through error event callbacks (for example,
rsi_ble_event_error_resp_t,rsi_ble_on_gatt_error_resp_t)Status Codes: Referenced in API documentation, see WiSeConnect Status Codes
Common BLE Error Codes#
Firmware / Wi-Fi SDK Errors:
0x0103: Firmware timeoutCause: Firmware did not respond to a command within the expected time window
Resolution: Check Network Processor (NWP)/host interface health, retry the command, and verify power/coex configuration
Connection Errors:
0x4D04: BLE not connectedCause: Attempted operation on a device that is not connected
Resolution: Verify device state using
rsi_ble_get_device_state()before performing operations (returns overall state only; track per-connection through connection events)
0x4D05: BLE socket not availableCause: No available connection slot
Resolution: Check connection limits, close unused connections, or increase connection limit configuration
0x4D08: Profile record fullCause: Maximum number of GATT profiles/services reached
Resolution: Remove unused services or increase profile/attribute count configuration within the supported limit (also bounded by available memory configuration)
0x4D0C: Feature not enabled or configuration bit not setCause: A required feature bit is not set in the BLE feature bitmap. For example,
rsi_ble_mtu_exchange_resp()returns0x4D0CwhenRSI_BLE_MTU_EXCHANGE_FROM_HOSTis not set.Resolution: Enable the required feature bit during stack initialization
GATT Operation Errors:
0x4A01: Invalid HandleCause: Attribute handle is out of valid range or doesn't exist
Resolution: Verify handle value, ensure service/characteristic discovery completed
0x4A02: Read not permittedCause: Characteristic does not have read property or insufficient permissions
Resolution: Check characteristic properties and security requirements
0x4A03: Write not permittedCause: Characteristic does not have write property or insufficient permissions
Resolution: Check characteristic properties and security requirements
0x4A05: Insufficient authenticationCause: Operation requires authentication but device is not authenticated
Resolution: Complete pairing/authentication before performing operation
0x4A06: Request not supportedCause: Requested operation is not supported by the characteristic
Resolution: Check characteristic properties and supported operations
0x4A08: Insufficient authorizationCause: Operation requires authorization but device is not authorized
Resolution: Complete authorization process before performing operation
0x4A0A: Attribute not foundCause: Requested attribute (service/characteristic) does not exist
Resolution: Verify UUID and ensure service discovery completed
0x4A0C: Insufficient encryption key sizeCause: Encryption key size is insufficient for the operation
Resolution: Use appropriate encryption key size (typically 16 bytes for BLE). The minimum accepted size can be configured through
rsi_ble_vendor_set_SMP_min_enc_keysize().
0x4A0F: Insufficient encryptionCause: Operation requires encryption but connection is not encrypted
Resolution: Enable encryption on the connection before performing operation
0x4E60: Invalid Handle RangeCause: Attribute handle is out of valid range
Resolution: Verify handle value and ensure it's within valid range
0x4E62: Invalid Parameters (typically GATT/BLE-buffer scope per neighboring codes)Cause: One or more function parameters passed to a BLE API are invalid
Resolution: Check parameter values (handles, lengths, addresses, etc.)
0x4E64: BLE Buffer already in useCause: Buffer is currently being used by another operation
Resolution: Wait for current operation to complete, or use different buffer
0x4E65: Invalid Attribute Length When Small Buffer Mode is ConfiguredCause: Data length exceeds configured buffer size
Resolution: Reduce data length or reconfigure buffer mode
SMP (Security) Errors:
0x4B01: SMP Passkey entry failed0x4B02: SMP OOB not available0x4B03: SMP Authentication Requirements0x4B04: SMP confirm value failed0x4B05: SMP Pairing not supported0x4B06: SMP Encryption key size insufficient0x4B07: SMP command not supported0x4B08: SMP pairing failed0x4B09: SMP repeated attempts0x4B0A: SMP Invalid parameters0x4B0B: DHKEY Check Failed0x4B0C: SMP Numeric Comparison Failed0x4BFD: SMP Invalid Keys Generated0x4BFE: SMP Identical Public Key
General Error Codes:
0x0007: SAPI / Wi-Fi SDK timeout (SL_STATUS_TIMEOUT)Cause: A WiSeConnect SDK API timed out waiting for a response from the firmware (SAPI-level timeout). Commonly seen when the firmware is busy, the host-firmware bus is stalled, or the command response never arrives.
Resolution: Check host-firmware connectivity (bus/interface health), verify firmware is not stuck in a previous operation, ensure prior commands completed, and retry after re-initialization if the condition persists
0x4E0C: Command disallowedCause: Command cannot be run in current state
Resolution: Check current state and ensure prerequisites are met
0x4046: Invalid Arguments (GAP scope)Cause: One or more function arguments passed to a GAP-layer API are invalid
Resolution: Verify all argument values and types
-4: Buffer not available to serve the commandCause: No buffer available for the command
Resolution: Wait for buffers to become available or reduce command rate
Error Handling Best Practices#
Check Return Values: Always check return values from BLE API functions
Compare against
RSI_SUCCESS(0) to determine successHandle non-zero return values appropriately
Handle Errors Gracefully: Implement appropriate error handling for each error code
Provide meaningful error messages for debugging
Implement fallback behavior where appropriate
Log errors for troubleshooting
Use Error Callbacks: Register and handle error event callbacks
rsi_ble_on_gatt_error_resp_t: GATT error response received (asynchronous client APIs)rsi_ble_event_error_resp_t: General BLE error eventrsi_bt_event_smp_failed_t: Pairing/security operation failed
Validate Parameters: Validate parameters before calling BLE APIs
Check handle values are within valid range
Verify data lengths are within limits
Ensure device addresses are properly formatted
Connection State: Verify connection state before performing connection-dependent operations
Use
rsi_ble_get_device_state()for overall device state only. To know which connections are active, trackrsi_ble_event_conn_status_t/rsi_ble_event_enhance_conn_status_tand disconnect events in the application (no API returns the connection list).Handle disconnection events appropriately
Resource Management: Monitor and manage resources to prevent exhaustion
Track active connections and close unused connections
Monitor buffer usage
Manage GATT profiles/services efficiently
Retry Logic: Implement retry logic for transient errors where appropriate
Connection failures may be transient (device out of range)
Buffer unavailability may be temporary
Use exponential backoff for retries
Error Logging: Log errors for debugging and troubleshooting
Include error code, operation context, and relevant parameters
Use appropriate log levels (error, warning, and debug)
iOS Peer Interoperability: When the peer device is iOS, configure BLE connection parameters per Apple's Bluetooth Accessory Design Guidelines — mismatched intervals, latency, or supervision timeout commonly trigger iOS-side disconnects.
Error Recovery Strategies#
Connection Errors:
Re-establish connection if device is still in range
Verify device is advertising and discoverable
Check connection limits and available resources
Implement connection timeout handling
Handle Errors:
Re-discover services/characteristics if handles become invalid
Verify handles are valid before use
After a successful discovery, cache the handles
Buffer Errors:
Wait for buffer availability before retrying
Reduce data size if possible
Increase buffer configuration if frequently occurring
Implement queueing mechanism for high-frequency operations
Resource Errors:
Free unused resources (connections, services, buffers)
Reduce connection count if at limit
Reconfigure limits based on application needs
Monitor resource usage proactively
Security Errors:
Retry pairing with different method if supported
Verify pairing capabilities match between devices
Check encryption requirements and key sizes
Ensure proper authentication/authorization flow
Error Event Callbacks#
GATT Error Callback:
rsi_ble_on_gatt_error_resp_t: Invoked when a GATT error response is receivedProvides device address, handle, and error code
Used for asynchronous client API operations
General Error Event:
rsi_ble_event_error_resp_t: General BLE error event structureContains device address, handle, and error code
Used for various BLE error conditions
SMP Error Event:
rsi_bt_event_smp_failed_t: Pairing/security operation failedProvides failure reason code
Used for security-related errors
Debugging Methodology#
Logging: Record error codes, operation context, and relevant parameters (see Error Handling Best Practices).
Connection State: Track
rsi_ble_event_conn_status_t/rsi_ble_event_enhance_conn_status_tand disconnect events; usersi_ble_get_device_state()only for overall device state.Mode and tooling: For host–NWP integration paths and mode-specific behavior, see Processing modes. For trace and debug options, use the WiSeConnect SDK documentation for your release and target.
APIs Used in This Section#
Topic | APIs / symbols | Reference |
|---|---|---|
GAP — device and connection state |
| |
GATT — MTU exchange (feature bit) |
| |
SMP — minimum encryption key size |
| |
Error events — callbacks |
| |
WiSeConnect status codes | Return values and error codes (documented per release) |
Note: Error codes may vary by SDK version. See WiSeConnect Status Codes for the complete list and version-specific codes. See the BLE API Reference guide for API-specific return values.