Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 3 additions & 5 deletions Sources/BluetoothHCI/HCIAcceptConnectionRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

public extension BluetoothHostControllerInterface {

/// Accept Connection Command
Expand Down Expand Up @@ -57,19 +55,19 @@ public struct HCIAcceptConnectionRequest: HCICommandParameter {
self.role = role
}

public var data: Data {
public func append<Data: DataContainer>(to data: inout Data) {

let addressBytes = address.littleEndian.bytes

return Data([
data += [
addressBytes.0,
addressBytes.1,
addressBytes.2,
addressBytes.3,
addressBytes.4,
addressBytes.5,
role.rawValue
])
]
}
}

Expand Down
2 changes: 0 additions & 2 deletions Sources/BluetoothHCI/HCIAuthenticationComplete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

/// Authentication Complete Event
///
/// The Authentication Complete event occurs when authentication has been completed for the specified connection. The Connection_Handle must be a Connection_Handle for an ACL connection.
Expand Down
6 changes: 2 additions & 4 deletions Sources/BluetoothHCI/HCIAuthenticationRequested.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

// MARK: - Method

public extension BluetoothHostControllerInterface {
Expand Down Expand Up @@ -51,10 +49,10 @@ public struct HCIAuthenticationRequested: HCICommandParameter {
self.handle = handle
}

public var data: Data {
public func append<Data: DataContainer>(to data: inout Data) {

let handleBytes = handle.littleEndian.bytes

return Data([handleBytes.0, handleBytes.1])
data += [handleBytes.0, handleBytes.1]
}
}
6 changes: 2 additions & 4 deletions Sources/BluetoothHCI/HCIChangeConnectionPacketType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

// MARK: - Method

public extension BluetoothHostControllerInterface {
Expand Down Expand Up @@ -56,12 +54,12 @@ public struct HCIChangeConnectionPacketType: HCICommandParameter {
self.packetType = packetType
}

public var data: Data {
public func append<Data: DataContainer>(to data: inout Data) {

let handleBytes = handle.littleEndian.bytes

let packetTypeBytes = packetType.rawValue.littleEndian.bytes

return Data([handleBytes.0, handleBytes.1, packetTypeBytes.0, packetTypeBytes.1])
data += [handleBytes.0, handleBytes.1, packetTypeBytes.0, packetTypeBytes.1]
}
}
15 changes: 11 additions & 4 deletions Sources/BluetoothHCI/HCICommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2016 PureSwift. All rights reserved.
//

import Foundation

/// HCI Command.
public protocol HCICommand: RawRepresentable, Hashable, CustomStringConvertible {

Expand Down Expand Up @@ -49,8 +47,17 @@ public protocol HCICommandParameter {

static var command: Command { get }

/// Converts command parameter to raw bytes.
var data: Data { get }
/// Append the command parameter bytes into the buffer.
func append<Data: DataContainer>(to data: inout Data)
}

public extension DataContainer {

/// Initialize data with contents of command parameter.
init<T: HCICommandParameter>(_ value: T) {
self.init()
value.append(to: &self)
}
}

/// The return value (not event) returned by an HCI command.
Expand Down
2 changes: 0 additions & 2 deletions Sources/BluetoothHCI/HCICommandComplete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

/// HCI Command Complete
@frozen
public struct HCICommandComplete: HCIEventParameter {
Expand Down
2 changes: 0 additions & 2 deletions Sources/BluetoothHCI/HCICommandStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

/// HCI Command Status Event
@frozen
public struct HCICommandStatus: HCIEventParameter {
Expand Down
2 changes: 0 additions & 2 deletions Sources/BluetoothHCI/HCIConnectionComplete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

/// Connection Complete Event
///
/// The Connection Complete event indicates to both of the Hosts forming the connection that a new connection has been established. This event also indicates to the Host, which issued the Create_Connection, or Accept_Connection_ Request or Reject_Connection_Request command and then received a Command Status event, if the issued command failed or was successful.
Expand Down
2 changes: 0 additions & 2 deletions Sources/BluetoothHCI/HCIConnectionPacketTypeChange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

/// The Connection Packet Type Changed event is used to indicate that the process has completed of the Link Manager changing which packet types can be used for the connection. This allows current connections to be dynamically modified to support different types of user data. The Packet_Type event parameter specifies which packet types the Link Manager can use for the connection identified by the Connection_Handle event parameter for sending L2CAP data or voice. The Packet_Type event parameter does not decide which packet types the LM is allowed to use for sending LMP PDUs.
@frozen
public struct HCIConnectionPacketTypeChange: HCIEventParameter {
Expand Down
2 changes: 0 additions & 2 deletions Sources/BluetoothHCI/HCIConnectionRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

/// Connection Request Event
///
/// The Connection Request event is used to indicate that a new incoming connection is trying to be established. The connection may either be accepted or rejected. If this event is masked away and there is an incoming connection attempt and the BR/EDR Controller is not set to auto-accept this connection attempt, the BR/EDR Controller shall automatically refuse the connection attempt. When the Host receives this event and the link type parameter is ACL, it should respond with either an Accept_Connection_Request or Reject_Connection_Request command before the timer Conn_Accept_Timeout expires. If the link type is SCO or eSCO, the Host should reply with the Accept_Synchronous_Connection_Request or the Reject_Synchronous_Connection_Request command. If the link type is SCO, the Host may respond with Accept_Connection_Request command. If the event is responded to with Accept_Connection_Request command, then the default parameter settings of the Accept_Synchronous_Connection_Request command (see Section 7.1.27 on page 504) should be used by the local Link Manager when negotiating the SCO link parameters. In that case, the Connection Complete event and not the Synchronous Connection Complete event, shall be returned on completion of the connection.
Expand Down
8 changes: 3 additions & 5 deletions Sources/BluetoothHCI/HCICreateConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

// MARK: - Method

public extension BluetoothHostControllerInterface {
Expand Down Expand Up @@ -82,22 +80,22 @@ public struct HCICreateConnection: HCICommandParameter {
self.allowRoleSwitch = allowRoleSwitch
}

public var data: Data {
public func append<Data: DataContainer>(to data: inout Data) {

let addressBytes = address.littleEndian.bytes

let packetTypeBytes = packetType.littleEndian.bytes

let clockOffsetBytes = clockOffset.rawValue.littleEndian.bytes

return Data([
data += [
addressBytes.0, addressBytes.1, addressBytes.2, addressBytes.3, addressBytes.4, addressBytes.5, // address
packetTypeBytes.0, packetTypeBytes.1, // packet type
pageScanRepetitionMode.rawValue, // page scan repetition mode
reserved.rawValue, // reserved
clockOffsetBytes.0, clockOffsetBytes.1, // clock offset
allowRoleSwitch.rawValue
]) // allow role switch
] // allow role switch
}
}

Expand Down
6 changes: 2 additions & 4 deletions Sources/BluetoothHCI/HCICreateConnectionCancel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

// MARK: - Method

public extension BluetoothHostControllerInterface {
Expand Down Expand Up @@ -44,11 +42,11 @@ public struct HCICreateConnectionCancel: HCICommandParameter {
self.address = address
}

public var data: Data {
public func append<Data: DataContainer>(to data: inout Data) {

let addressBytes = address.littleEndian.bytes

return Data([addressBytes.0, addressBytes.1, addressBytes.2, addressBytes.3, addressBytes.4, addressBytes.5])
data += [addressBytes.0, addressBytes.1, addressBytes.2, addressBytes.3, addressBytes.4, addressBytes.5]
}
}

Expand Down
8 changes: 3 additions & 5 deletions Sources/BluetoothHCI/HCIDeleteStoredLinkKey.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

// MARK: - Method

public extension BluetoothHostControllerInterface {
Expand Down Expand Up @@ -49,19 +47,19 @@ public struct HCIDeleteStoredLinkKey: HCICommandParameter {
self.deleteFlag = deleteFlag
}

public var data: Data {
public func append<Data: DataContainer>(to data: inout Data) {

let addressBytes = address.littleEndian.bytes

return Data([
data += [
addressBytes.0,
addressBytes.1,
addressBytes.2,
addressBytes.3,
addressBytes.4,
addressBytes.5,
deleteFlag.rawValue
])
]
}
}

Expand Down
6 changes: 2 additions & 4 deletions Sources/BluetoothHCI/HCIDisconnect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

// MARK: - Method

public extension BluetoothHostControllerInterface {
Expand Down Expand Up @@ -53,11 +51,11 @@ public struct HCIDisconnect: HCICommandParameter {
self.error = error
}

public var data: Data {
public func append<Data: DataContainer>(to data: inout Data) {

let connectionBytes = connectionHandle.littleEndian.bytes

return Data([connectionBytes.0, connectionBytes.1, error.rawValue])
data += [connectionBytes.0, connectionBytes.1, error.rawValue]
}
}

Expand Down
2 changes: 0 additions & 2 deletions Sources/BluetoothHCI/HCIDisconnectionComplete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

/// Disconnection Complete Event
///
/// The Disconnection Complete event occurs when a connection is terminated. The status parameter indicates if the disconnection was successful or not. The reason parameter indicates the reason for the disconnection if the disconnection was successful. If the disconnection was not successful, the value of the reason parameter can be ignored by the Host. For example, this can be the case if the Host has issued the Disconnect command and there was a parameter error, or the command was not presently allowed, or a Connection_Handle that didn’t correspond to a connection was given.
Expand Down
2 changes: 0 additions & 2 deletions Sources/BluetoothHCI/HCIEncryptionChange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

/// Encryption Change Event
///
/// The Encryption Change event is used to indicate that the change of the encryption mode has been completed.
Expand Down
2 changes: 0 additions & 2 deletions Sources/BluetoothHCI/HCIEncryptionKeyRefreshComplete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

/// Encryption Key Refresh Complete Event
///
/// The Encryption Key Refresh Complete event is used to indicate to the Host that the encryption key was
Expand Down
4 changes: 2 additions & 2 deletions Sources/BluetoothHCI/HCIError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
// Copyright © 2017 PureSwift. All rights reserved.
//

import Foundation

/// Bluetooth HCI Errors
///
/// If an HCI Command that should generate a Command Complete event generates an error
Expand Down Expand Up @@ -537,8 +539,6 @@ extension HCIError: CustomStringConvertible {

#if canImport(Darwin)

import Foundation

extension HCIError: CustomNSError {

public static var errorDomain: String {
Expand Down
2 changes: 0 additions & 2 deletions Sources/BluetoothHCI/HCIEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2016 PureSwift. All rights reserved.
//

import Foundation

/// HCI Event Opcode
public protocol HCIEvent: RawRepresentable, Hashable, CustomStringConvertible {

Expand Down
2 changes: 0 additions & 2 deletions Sources/BluetoothHCI/HCIExitPeriodicInquiryMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

// MARK: - Method

public extension BluetoothHostControllerInterface {
Expand Down
8 changes: 3 additions & 5 deletions Sources/BluetoothHCI/HCIHoldMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

/// Hold Mode Command
///
/// The Hold_Mode command is used to alter the behavior of the Link Manager, and have it place the ACL baseband connection associated by the specified Connection_Handle into the hold mode. The Hold_Mode_Max_Interval and Hold_Mode_Min_Interval command parameters specify the length of time the Host wants to put the connection into the hold mode. The local and remote devices will negotiate the length in the hold mode. The Hold_Mode_Max_ Interval parameter is used to specify the maximum length of the Hold interval for which the Host may actually enter into the hold mode after negotiation with the remote device. The Hold interval defines the amount of time between when the Hold Mode begins and when the Hold Mode is completed. The Hold_ Mode_Min_Interval parameter is used to specify the minimum length of the Hold interval for which the Host may actually enter into the hold mode after the negotiation with the remote device. Therefore the Hold_Mode_Min_Interval cannot be greater than the Hold_Mode_Max_Interval. The BR/EDR Controller will return the actual Hold interval in the Interval parameter of the Mode Change event, if the command is successful. This command enables the Host to support a low-power policy for itself or several other BR/EDR Controllers, and allows the devices to enter Inquiry Scan, Page Scan, and a number of other possible actions.
Expand Down Expand Up @@ -37,7 +35,7 @@ public struct HCIHoldMode: HCICommandParameter {
self.interval = interval
}

public var data: Data {
public func append<Data: DataContainer>(to data: inout Data) {

// Connection_Handle
let handleBytes = connectionHandle.littleEndian.bytes
Expand All @@ -48,14 +46,14 @@ public struct HCIHoldMode: HCICommandParameter {
// Hold_Mode_Min_Interval
let intervalMinBytes = interval.rawValue.lowerBound.littleEndian.bytes

return Data([
data += [
handleBytes.0,
handleBytes.1,
intervalMaxBytes.0,
intervalMaxBytes.1,
intervalMinBytes.0,
intervalMinBytes.1
])
]
}
}

Expand Down
2 changes: 0 additions & 2 deletions Sources/BluetoothHCI/HCIIOCapabilityRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
// Copyright © 2018 PureSwift. All rights reserved.
//

import Foundation

/// The IO Capability Request event is used to indicate that the IO capabilities of the Host are required for a simple pairing process. The Host shall respond with an IO_Capability_Request_Reply command. This event shall only be generated if simple pairing has been enabled with the Write_Simple_Pairing_Mode command.
@frozen
public struct HCIIOCapabilityRequest: HCIEventParameter {
Expand Down
Loading
Loading