Exceptions

WHAD BLE domain exceptions

These exceptions are raised by Bluetooth Low Energy connectors and other related classes to notify the main Python code that something unexpected happened and must be taken care of.

Bluetooth Low Energy domain exceptions

exception whad.ble.exceptions.ConnectionLostException(connection=None)[source]

This exception is raised when a connection is unexpectedly terminated.

exception whad.ble.exceptions.InvalidAccessAddressException[source]

Exception raised when an invalid access address is used.

exception whad.ble.exceptions.InvalidHandleValueException[source]

Exception raised when an invalid handle value is used.

exception whad.ble.exceptions.InvalidSerialPortException[source]

Exception raised whan an invalid serial port is provided

exception whad.ble.exceptions.InvalidUUIDException[source]

Exception raised when an invalid UUID is used.

exception whad.ble.exceptions.MissingCryptographicMaterial[source]

Raise this exception if a decryption is attempted without having cryptographic material available.

exception whad.ble.exceptions.NotConnected(peripheral=None)[source]

This exception is raised when a peripheral is used while not connected.

exception whad.ble.exceptions.NotSynchronized[source]

This exception is raised when a connection is used while not synchronized.

exception whad.ble.exceptions.PeripheralNotFound(peripheral=None)[source]

This exception is raised when a targeted peripheral cannot be found.

BLE ATT exceptions

These exceptions are raised by WHAD’s BLE stack when an error has been encountered during a specific GATT operation.

Att Exceptions

exception whad.ble.stack.att.exceptions.AttError(request, handle)[source]

ATT generic exception

class whad.ble.stack.att.exceptions.AttErrorCode[source]

ATT error codes

exception whad.ble.stack.att.exceptions.AttributeNotFoundError(request, handle)[source]

Exception raised when an attribute cannot be found.

exception whad.ble.stack.att.exceptions.AttributeNotLongError(request, handle)[source]

Raised a read long operation is performed on a not-long attribute.

exception whad.ble.stack.att.exceptions.InsufficientAuthenticationError(request, handle)[source]

Authentication required

exception whad.ble.stack.att.exceptions.InsufficientAuthorizationError(request, handle)[source]

Exception raised if an authorization is required

exception whad.ble.stack.att.exceptions.InsufficientEncryptionError(request, handle)[source]

Raised on insufficient encryption.

exception whad.ble.stack.att.exceptions.InsufficientEncryptionKeySize(request, handle)[source]

Raised when wrong key size is used

exception whad.ble.stack.att.exceptions.InsufficientResourcesError(request, handle)[source]

Raised to notify an error of resources

exception whad.ble.stack.att.exceptions.InvalidAttrValueLength(request, handle)[source]

Raised when an invalid length is used on an attribute

exception whad.ble.stack.att.exceptions.InvalidHandleValueError(request, handle)[source]

Exception raised when an invalid handle value is provided.

exception whad.ble.stack.att.exceptions.InvalidOffsetError(request, handle)[source]

Exception raised when an invalid offset is provided to a read or write operation

exception whad.ble.stack.att.exceptions.InvalidPduError(request, handle)[source]

Exception raised when an invalid PDU is processed

exception whad.ble.stack.att.exceptions.PrepareQueueFullError(request, handle)[source]

Raised when a prepare write queue is full.

exception whad.ble.stack.att.exceptions.ReadNotPermittedError(request, handle)[source]

Exception raised when a read operation is performed while not permitted

exception whad.ble.stack.att.exceptions.UnlikelyError(request, handle)[source]

Raised when an unlikely error is triggered

exception whad.ble.stack.att.exceptions.UnsupportedGroupTypesError(request, handle)[source]

Raised when an unsupported group type is requested.

exception whad.ble.stack.att.exceptions.UnsupportedRequestError(request, handle)[source]

Exception raised when an unsupported request is received

exception whad.ble.stack.att.exceptions.WriteNotPermittedError(request, handle)[source]

Exception raised when a write operation is performed while not allowed

whad.ble.stack.att.exceptions.error_response_to_exc(error_code, request, handle) AttError[source]

Convert error code to corresponding exception.

Parameters:
  • error_code (int) – ATT error code

  • request (int) – Request that lead to this error code

  • handle (int) – related handle

Returns:

corresponding exception

Return type:

AttError

Hooking exceptions

These exceptions are used to force WHAD’s BLE stack to behave specifically when they are raised in a hook, like forcing a specific value to be returned when a characteristic is read or force a GATT client to authenticate before accessing a specific characteristic.

Exceptions are used in this specific case as a way to divert from the expected behavior and force the BLE stack to return a specific response to a GATT server. This is not really how exceptions are designed for, but it does improve hooks readability.

Bluetooth Low Energy domain exceptions

exception whad.ble.exceptions.HookDontForward[source]

Raise this exception in a hook to avoid forwarding.

exception whad.ble.exceptions.HookReturnAccessDenied[source]

Raise this exception in a hook to return an error (access not allowed)

exception whad.ble.exceptions.HookReturnAuthentRequired[source]

Raise this exception in a hook to ask for authentication.

exception whad.ble.exceptions.HookReturnAuthorRequired[source]

Raise this exception in a hook to notify an Authorization is required to access an attribute.

exception whad.ble.exceptions.HookReturnGattError(request, handle, error)[source]

Raise this exception in a hook to return a GATT error.

property error: int

Error code

property handle: int

Related attribute GATT handle value

property request

Corresponding GATT request

exception whad.ble.exceptions.HookReturnNotFound[source]

Raise this exception in a hook to indicate the requested object has not been found.

exception whad.ble.exceptions.HookReturnValue(value: bytes)[source]

Raise this exception in a hook to return a specific value to the caller.

property value: bytes

Return value