1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
use std::fmt;

#[repr(u8)]
#[derive(FromPrimitive, ToPrimitive, Copy, Clone, Debug)]
pub enum CommandStatus {
    Success = 0x00,
    UnknownCommand = 0x01,
    NotConnected = 0x02,
    Failed = 0x03,
    ConnectFailed = 0x04,
    AuthenticationFailed = 0x05,
    NotPaired = 0x06,
    NoResources = 0x07,
    Timeout = 0x08,
    AlreadyConnected = 0x09,
    Busy = 0x0A,
    Rejected = 0x0B,
    NotSupported = 0x0C,
    InvalidParams = 0x0D,
    Disconnected = 0x0E,
    NotPowered = 0x0F,
    Cancelled = 0x10,
    InvalidIndex = 0x11,
    RFKilled = 0x12,
    AlreadyPaired = 0x13,
    PermissionDenied = 0x14,
}

#[repr(u16)]
#[derive(Eq, PartialEq, FromPrimitive, ToPrimitive, Copy, Clone, Debug)]
pub enum Command {
    ReadVersionInfo = 0x0001,
    ReadSupportedCommands,
    ReadControllerIndexList,
    ReadControllerInfo,
    SetPowered,
    SetDiscoverable,
    SetConnectable,
    SetFastConnectable,
    SetPairable,
    SetLinkSecurity,
    SetSecureSimplePairing,
    SetHighSpeed,
    SetLowEnergy,
    SetDeviceClass,
    SetLocalName,
    AddUUID,
    RemoveUUID,
    LoadLinkKeys,
    LoadLongTermKeys,
    Disconnect,
    GetConnections,
    PinCodeReply,
    PinCodeNegativeReply,
    SetIOCapability,
    PairDevice,
    CancelPairDevice,
    UnpairDevice,
    UserConfirmationReply,
    UserConfirmationNegativeReply,
    UserPasskeyReply,
    UserPasskeyNegativeReply,
    ReadLocalOutOfBand,
    AddRemoteOutOfBand,
    RemoveRemoteOutOfBand,
    StartDiscovery,
    StopDiscovery,
    ConfirmName,
    BlockDevice,
    UnblockDevice,
    SetDeviceID,
    SetAdvertising,
    SetBREDR,
    SetStaticAddress,
    SetScanParameters,
    SetSecureConnections,
    SetDebugKeys,
    SetPrivacy,
    LoadIdentityResolvingKeys,
    GetConnectionInfo,
    GetClockInfo,
    AddDevice,
    RemoveDevice,
    LoadConnectionParameters,
    ReadUnconfiguredControllerIndexList,
    ReadControllerConfigInfo,
    SetExternalConfig,
    SetPublicAddress,
    StartServiceDiscovery,
    ReadLocalOutOfBandExtended,
    ReadExtendedControllerIndexList,
    ReadAdvertisingFeatures,
    AddAdvertising,
    RemoveAdvertising,
    GetAdvertisingSizeInfo,
    StartLimitedDiscovery,
    ReadExtendedControllerInfo,
    SetAppearance,
    GetPhyConfig,
    SetPhyConfig,
    LoadBlockedKeys,
}

impl fmt::LowerHex for CommandStatus {
    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        write!(f, "{:x}", *self as u8)
    }
}