-
Notifications
You must be signed in to change notification settings - Fork 12
[WIP] Added HCI Commands #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
carlos21
wants to merge
26
commits into
master
Choose a base branch
from
feature/add-hci-commands
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 e1ebf9c
#47 separated core files from hcitool to CoreHCI
carlos21 8110f8a
#47 added InquiryCommand and tests
carlos21 56b2180
#98 added documentation and improving HCIInquiry
carlos21 1a06eaf
#47 added InquiryCancelCommand and tests
carlos21 3055386
#47 added PeriodicInquiryModeCommand
carlos21 50e4a2f
#47
carlos21 87b306f
#47
carlos21 89b6b36
testing HCIInquiry command
carlos21 748c9f8
testing Inquiry
carlos21 c4d5dd4
Updating hcitool after changing Bluetooth
carlos21 47a34d1
removing unnecessary prints
carlos21 d57c39d
added create connection cancel command and tests
carlos21 8536bbf
added RequestremoteName command
carlos21 1795672
updated RemoteRemoteName
carlos21 224ddb1
added ReadDataBlockSizeCommand
carlos21 e8a8768
changed create connection
carlos21 2269696
printing connection handle hex in Linux
carlos21 01c5538
added SetConnectionEncryptionCommand
carlos21 35722ae
added ReadRemoteSupportedFeaturesCommand
carlos21 8fc1d76
Added ReadRemoteVersionInformation
carlos21 d958875
Fixed ReadRemoteSupportedFeaturesCommand
carlos21 17c681b
Fixed ReadRemoteVersionInformationCommand
carlos21 8321552
added ReadClockoffset
carlos21 f623348
added ReadAuthenticationRequestedCommand and ReadLMPHandleCommand
carlos21 6760c32
fixed AuthenticationRequestedCommand
carlos21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "autoPin": true, | ||
| "pins": [ | ||
|
|
||
| ], | ||
| "version": 1 | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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] | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.