Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
351a571
#47 Added LESetDataLengthCommand, LEReadSuggestedDefaultDataLengthCom…
carlos21 Jul 24, 2018
e1ebf9c
#47 separated core files from hcitool to CoreHCI
carlos21 Jul 25, 2018
8110f8a
#47 added InquiryCommand and tests
carlos21 Jul 25, 2018
56b2180
#98 added documentation and improving HCIInquiry
carlos21 Jul 25, 2018
1a06eaf
#47 added InquiryCancelCommand and tests
carlos21 Jul 25, 2018
3055386
#47 added PeriodicInquiryModeCommand
carlos21 Jul 26, 2018
50e4a2f
#47
carlos21 Jul 27, 2018
87b306f
#47
carlos21 Jul 27, 2018
89b6b36
testing HCIInquiry command
carlos21 Jul 30, 2018
748c9f8
testing Inquiry
carlos21 Jul 30, 2018
c4d5dd4
Updating hcitool after changing Bluetooth
carlos21 Aug 2, 2018
47a34d1
removing unnecessary prints
carlos21 Aug 2, 2018
d57c39d
added create connection cancel command and tests
carlos21 Aug 3, 2018
8536bbf
added RequestremoteName command
carlos21 Aug 4, 2018
1795672
updated RemoteRemoteName
carlos21 Aug 4, 2018
224ddb1
added ReadDataBlockSizeCommand
carlos21 Aug 6, 2018
e8a8768
changed create connection
carlos21 Aug 6, 2018
2269696
printing connection handle hex in Linux
carlos21 Aug 6, 2018
01c5538
added SetConnectionEncryptionCommand
carlos21 Aug 6, 2018
35722ae
added ReadRemoteSupportedFeaturesCommand
carlos21 Aug 7, 2018
8fc1d76
Added ReadRemoteVersionInformation
carlos21 Aug 8, 2018
d958875
Fixed ReadRemoteSupportedFeaturesCommand
carlos21 Aug 8, 2018
17c681b
Fixed ReadRemoteVersionInformationCommand
carlos21 Aug 8, 2018
8321552
added ReadClockoffset
carlos21 Aug 9, 2018
f623348
added ReadAuthenticationRequestedCommand and ReadLMPHandleCommand
carlos21 Aug 9, 2018
6760c32
fixed AuthenticationRequestedCommand
carlos21 Aug 9, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
github "MillerTechnologyPeru/Rainbow" "73d4ee05e013089cad7f21892c456df52329fc02"
github "PureSwift/Bluetooth" "f4afec53b71694109ecea7569c0c932f5519bd6c"
github "PureSwift/BluetoothDarwin" "858a824a1424e27a354f74bfed8da531591ae5f5"
github "PureSwift/Bluetooth" "2459f22574c8a409f020c6da0a5756deafdce5a6"
github "PureSwift/BluetoothDarwin" "741c86b4fe808df1c7613e34480bee3861bb0ca3"
7 changes: 7 additions & 0 deletions Package.pins
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"autoPin": true,
"pins": [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pins should not be empty.

],
"version": 1
}
17 changes: 4 additions & 13 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ let package = Package(
targets: [
Target(
name: "hcitool",
dependencies: [])
dependencies: ["CoreHCI"]
),
Target(
name: "CoreHCI"
)
]
)

Expand Down
File renamed without changes.
134 changes: 134 additions & 0 deletions Sources/CoreHCI/AuthenticationRequested.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
//
// ReadAuthenticationRequested.swift
// hcitool
//
// Created by Carlos Duclos on 8/9/18.
//
//

//
// ReadLMPHandle.swift
// hcitool
//
// Created by Carlos Duclos on 8/9/18.
//
//

import Bluetooth
import Foundation

public struct AuthenticationRequestedCommand: ArgumentableCommand {

public typealias PacketType = HCICreateConnection.PacketType
public typealias ClockOffset = HCICreateConnection.ClockOffset
public typealias AllowRoleSwitch = HCICreateConnection.AllowRoleSwitch

// MARK: - Properties

public static let commandType: CommandType = .authenticationRequested

public let address: Address

public let packetType: UInt16

public let pageScanRepetitionMode: PageScanRepetitionMode

public let clockOffset: BitMaskOptionSet<ClockOffset>

public let allowRoleSwitch: AllowRoleSwitch

// MARK: - Initialization

public init(address: Address,
packetType: UInt16,
pageScanRepetitionMode: PageScanRepetitionMode,
clockOffset: BitMaskOptionSet<ClockOffset>,
allowRoleSwitch: AllowRoleSwitch) {

self.address = address
self.packetType = packetType
self.pageScanRepetitionMode = pageScanRepetitionMode
self.clockOffset = clockOffset
self.allowRoleSwitch = allowRoleSwitch
}

public init(parameters: [Parameter<Option>]) throws {

guard let addressString = parameters.first(where: { $0.option == .address })?.value
else { throw CommandError.optionMissingValue(Option.address.rawValue) }

guard let address = Address(rawValue: addressString)
else { throw CommandError.invalidOptionValue(option: Option.address.rawValue, value: addressString) }

self.address = address

guard let packetTypeString = parameters.first(where: { $0.option == .packetType })?.value
else { throw CommandError.optionMissingValue(Option.packetType.rawValue) }

guard let packetTypeValue = UInt16(commandLine: packetTypeString)
else { throw CommandError.invalidOptionValue(option: Option.packetType.rawValue, value: packetTypeString) }

self.packetType = packetTypeValue

guard let pageScanRepetitionModeString = parameters.first(where: { $0.option == .pageScanRepetitionMode })?.value
else { throw CommandError.optionMissingValue(Option.pageScanRepetitionMode.rawValue) }

guard let pageScanRepetitionModeValue = UInt8(commandLine: pageScanRepetitionModeString)
else { throw CommandError.invalidOptionValue(option: Option.pageScanRepetitionMode.rawValue, value: pageScanRepetitionModeString) }

self.pageScanRepetitionMode = PageScanRepetitionMode(rawValue: pageScanRepetitionModeValue)

guard let clockOffsetString = parameters.first(where: { $0.option == .clockOffset })?.value
else { throw CommandError.optionMissingValue(Option.clockOffset.rawValue) }

guard let clockOffsetValue = UInt16(commandLine: clockOffsetString)
else { throw CommandError.invalidOptionValue(option: Option.clockOffset.rawValue, value: clockOffsetString) }

self.clockOffset = BitMaskOptionSet<ClockOffset>(rawValue: clockOffsetValue)

guard let allowRoleSwitchString = parameters.first(where: { $0.option == .allowRoleSwitch })?.value
else { throw CommandError.optionMissingValue(Option.allowRoleSwitch.rawValue) }

guard let allowRoleSwitchValue = UInt8(commandLine: allowRoleSwitchString),
let allowRoleSwitch = AllowRoleSwitch(rawValue: allowRoleSwitchValue)
else { throw CommandError.invalidOptionValue(option: Option.allowRoleSwitch.rawValue, value: allowRoleSwitchString) }

self.allowRoleSwitch = allowRoleSwitch
}

// MARK: - Methods

public func execute <Controller: BluetoothHostControllerInterface> (controller: Controller) throws {

let connectionComplete = try controller.createConnection(address: address,
packetType: packetType,
pageScanRepetitionMode: pageScanRepetitionMode,
clockOffset: clockOffset,
allowRoleSwitch: allowRoleSwitch,
timeout: 5000)

let status = try controller.authenticationRequested(handle: connectionComplete.handle)

switch status {
case .success:
print("Success")

case .error(let error):
print("Error:", error.name)
}
}
}

public extension AuthenticationRequestedCommand {

public enum Option: String, OptionProtocol {

case address = "address"
case packetType = "packettype"
case pageScanRepetitionMode = "pagescanrepetitionmode"
case clockOffset = "clockoffset"
case allowRoleSwitch = "allowroleswitch"

public static let all: Set<Option> = [.address, .packetType, .pageScanRepetitionMode, .clockOffset, .allowRoleSwitch]
}
}
Loading