Skip to content

Commit

Permalink
Updated HCI Command
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Mar 23, 2018
1 parent 5b4f31b commit 8628742
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Sources/HCI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public enum HCIOpcodeGroupField: UInt16 {
case linkPolicy = 0x02

/// Host Controller and Baseband
case hostController = 0x03
case hostControllerBaseband = 0x03

/// Informational Parameters
case informationalParameters = 0x04
Expand Down
3 changes: 0 additions & 3 deletions Sources/HCICommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ public protocol HCICommandParameter {

static var command: HCICommandType { get }

/// Length of the command when encoded to data.
static var length: Int { get }

/// Converts command parameter to raw bytes.
var byteValue: [UInt8] { get }
}
Expand Down
54 changes: 54 additions & 0 deletions Sources/HostControllerBasebandCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// HostControllerCommand.swift
// Bluetooth
//
// Created by Alsey Coleman Miller on 3/23/18.
// Copyright © 2018 PureSwift. All rights reserved.
//

/**
The Controller & Baseband Commands provide access and control to various capabilities of the Bluetooth hardware. These parameters provide control of BR/EDR Controllers and of the capabilities of the Link Manager and Baseband in the BR/EDR Controller, the PAL in an AMP Controller, and the Link Layer in an LE Controller. The Host can use these commands to modify the behavior of the local Controller.
*/
public enum HostControllerBasebandCommand: UInt16, HCICommand {

public static let opcodeGroupField = HCIOpcodeGroupField.hostControllerBaseband

/// Set Event Mask
///
/// Used to control which events are generated by the HCI for the Host.
case setEventMask = 0x0001

/**
Reset Command
The Reset command will reset the Controller and the Link Manager on the BR/ EDR Controller, the PAL on an AMP Controller, or the Link Layer on an LE Controller. If the Controller supports both BR/EDR and LE then the Reset command shall reset the Link Manager, Baseband and Link Layer. The Reset command shall not affect the used HCI transport layer since the HCI transport layers may have reset mechanisms of their own. After the reset is completed, the current operational state will be lost, the Controller will enter standby mode and the Controller will automatically revert to the default values for the parameters for which default values are defined in the specification.
- Note: The Reset command will not necessarily perform a hardware reset. This is implementation defined. On an AMP Controller, the Reset command shall reset the service provided at the logical HCI to its initial state, but beyond this the exact effect on the Controller device is implementation defined and should not interrupt the service provided to other protocol stacks.
The Host shall not send additional HCI commands before the Command Complete event related to the Reset command has been received.
*/
case reset = 0x0003

/**
Set Event Filter Command
Used by the Host to specify different event filters.
The Host may issue this command multiple times to request various conditions for the same type of event filter and for different types of event filters. The event filters are used by the Host to specify items of interest, which allow the BR/EDR Controller to send only events which interest the Host. Only some of the events have event filters. By default (before this command has been issued after power-on or Reset) no filters are set, and the Auto_Accept_Flag is off (incoming connections are not automatically accepted). An event filter is added each time this command is sent from the Host and the Filter_Condition_Type is not equal to 0x00. (The old event filters will not be overwritten). To clear all event filters, the Filter_Type = 0x00 is used. The Auto_Accept_Flag will then be set to off. To clear event filters for only a certain Filter_Type, the Filter_Condition_Type = 0x00 is used.
The Inquiry Result filter allows the BR/EDR Controller to filter out Inquiry Result, Inquiry Result with RSSI, or Extended Inquiry Result events. The Inquiry Result filter allows the Host to specify that the BR/EDR Controller only sends Inquiry Results to the Host if the report meets one of the specified conditions set by the Host. For the Inquiry Result filter, the Host can specify one or more of the following Filter Condition Types:
1. Return responses from all devices during the Inquiry process
2. A device with a specific Class of Device responded to the Inquiry process 3. A device with a specific BD_ADDR responded to the Inquiry process
The Inquiry Result filter is used in conjunction with the Inquiry and Periodic Inquiry command.
The Connection Setup filter allows the Host to specify that the Controller only sends a Connection Complete or Connection Request event to the Host if the event meets one of the specified conditions set by the Host. For the Connection Setup filter, the Host can specify one or more of the following Filter Condition Types:
1. Allow Connections from all devices
2. Allow Connections from a device with a specific Class of Device 3. Allow Connections from a device with a specific BD_ADDR
For each of these conditions, an Auto_Accept_Flag parameter allows the Host to specify what action should be done when the condition is met. The Auto_ Accept_Flag allows the Host to specify if the incoming connection should be auto accepted (in which case the BR/EDR Controller will send the Connection Complete event to the Host when the connection is completed) or if the Host should make the decision (in which case the BR/EDR Controller will send the Connection Request event to the Host, to elicit a decision on the connection).
The Connection Setup filter is used in conjunction with the Read/Write_ Scan_Enable commands. If the local device is in the process of a page scan, and is paged by another device which meets one on the conditions set by the Host, and the Auto_Accept_Flag is off for this device, then a Connection Request event will be sent to the Host by the BR/EDR Controller. A Connection Complete event will be sent later on after the Host has responded to the incoming connection attempt. In this same example, if the Auto_Accept_Flag is on, then a Connection Complete event will be sent to the Host by the Controller. (No Connection Request event will be sent in that case.)
The BR/EDR Controller will store these filters in volatile memory until the Host clears the event filters using the Set_Event_Filter command or until the Reset command is issued. The number of event filters the BR/EDR Controller can store is implementation dependent. If the Host tries to set more filters than the BR/EDR Controller can store, the BR/EDR Controller will return the Memory Full error code and the filter will not be installed.
- Note: The Clear All Filters has no Filter Condition Types or Conditions.
- Note: In the condition that a connection is auto accepted, a Link Key Request event and possibly also a PIN Code Request event and a Link Key Notification event could be sent to the Host by the Controller before the Connection Complete event is sent.
If there is a contradiction between event filters, the latest set event filter will override older ones. An example is an incoming connection attempt where more than one Connection Setup filter matches the incoming connection attempt, but the Auto-Accept_Flag has different values in the different filters.
*/
case setEventFilter = 0x0005
}
89 changes: 89 additions & 0 deletions Sources/HostControllerBasebandCommandParameter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//
// HostControllerBasebandCommandParameter.swift
// Bluetooth
//
// Created by Alsey Coleman Miller on 3/23/18.
// Copyright © 2018 PureSwift. All rights reserved.
//

public extension HostControllerBasebandCommand {

/**
Set Event Filter Command
Used by the Host to specify different event filters.
The Host may issue this command multiple times to request various conditions for the same type of event filter and for different types of event filters. The event filters are used by the Host to specify items of interest, which allow the BR/EDR Controller to send only events which interest the Host. Only some of the events have event filters. By default (before this command has been issued after power-on or Reset) no filters are set, and the Auto_Accept_Flag is off (incoming connections are not automatically accepted). An event filter is added each time this command is sent from the Host and the Filter_Condition_Type is not equal to 0x00. (The old event filters will not be overwritten). To clear all event filters, the Filter_Type = 0x00 is used. The Auto_Accept_Flag will then be set to off. To clear event filters for only a certain Filter_Type, the Filter_Condition_Type = 0x00 is used.
The Inquiry Result filter allows the BR/EDR Controller to filter out Inquiry Result, Inquiry Result with RSSI, or Extended Inquiry Result events. The Inquiry Result filter allows the Host to specify that the BR/EDR Controller only sends Inquiry Results to the Host if the report meets one of the specified conditions set by the Host. For the Inquiry Result filter, the Host can specify one or more of the following Filter Condition Types:
1. Return responses from all devices during the Inquiry process
2. A device with a specific Class of Device responded to the Inquiry process 3. A device with a specific BD_ADDR responded to the Inquiry process
The Inquiry Result filter is used in conjunction with the Inquiry and Periodic Inquiry command.
The Connection Setup filter allows the Host to specify that the Controller only sends a Connection Complete or Connection Request event to the Host if the event meets one of the specified conditions set by the Host. For the Connection Setup filter, the Host can specify one or more of the following Filter Condition Types:
1. Allow Connections from all devices
2. Allow Connections from a device with a specific Class of Device 3. Allow Connections from a device with a specific BD_ADDR
For each of these conditions, an Auto_Accept_Flag parameter allows the Host to specify what action should be done when the condition is met. The Auto_ Accept_Flag allows the Host to specify if the incoming connection should be auto accepted (in which case the BR/EDR Controller will send the Connection Complete event to the Host when the connection is completed) or if the Host should make the decision (in which case the BR/EDR Controller will send the Connection Request event to the Host, to elicit a decision on the connection).
The Connection Setup filter is used in conjunction with the Read/Write_ Scan_Enable commands. If the local device is in the process of a page scan, and is paged by another device which meets one on the conditions set by the Host, and the Auto_Accept_Flag is off for this device, then a Connection Request event will be sent to the Host by the BR/EDR Controller. A Connection Complete event will be sent later on after the Host has responded to the incoming connection attempt. In this same example, if the Auto_Accept_Flag is on, then a Connection Complete event will be sent to the Host by the Controller. (No Connection Request event will be sent in that case.)
The BR/EDR Controller will store these filters in volatile memory until the Host clears the event filters using the Set_Event_Filter command or until the Reset command is issued. The number of event filters the BR/EDR Controller can store is implementation dependent. If the Host tries to set more filters than the BR/EDR Controller can store, the BR/EDR Controller will return the Memory Full error code and the filter will not be installed.
- Note: The Clear All Filters has no Filter Condition Types or Conditions.
- Note: In the condition that a connection is auto accepted, a Link Key Request event and possibly also a PIN Code Request event and a Link Key Notification event could be sent to the Host by the Controller before the Connection Complete event is sent.
If there is a contradiction between event filters, the latest set event filter will override older ones. An example is an incoming connection attempt where more than one Connection Setup filter matches the incoming connection attempt, but the Auto-Accept_Flag has different values in the different filters.
*/
public struct SetEventFilterParameter: HCICommandParameter {

public static let command = HostControllerBasebandCommand.setEventFilter

///
public var filterType: FilterType // Filter_Type

public var byteValue: [UInt8] {

fatalError("\(#function) TODO")
}

public enum FilterType: UInt8 {

/// Clear All Filters
///
/// - Note: In this case, the Filter_Condition_Type and Condition parameters should not be given,
/// they should have a length of 0 octets.
///
/// Filter_Type should be the only parameter.
case clearAll = 0x00

/// Inquiry Result.
case inquiryResult = 0x01

/// Connection Setup
case connectionSetup = 0x02
}

public enum InquiryResultFilterConditionType: UInt8 {

/// Return responses from all devices during the Inquiry process.
///
/// - Note: A device may be reported to the Host in an Inquiry Result, Inquiry Result with RSSI,
/// or Extended Inquiry Result event more than once during an inquiry or inquiry period depending
/// on the implementation.
case all

/// A device with a specific Class of Device responded to the Inquiry process.
case classOfDevice

/// A device with a specific `BD_ADDR` responded to the Inquiry process.
case address
}
}
}
9 changes: 0 additions & 9 deletions Sources/HostControllerCommand.swift

This file was deleted.

Loading

0 comments on commit 8628742

Please sign in to comment.