diff --git a/Sources/BluetoothLinux/HCI.swift b/Sources/BluetoothLinux/HCI.swift index bcbe395..2bf0faa 100755 --- a/Sources/BluetoothLinux/HCI.swift +++ b/Sources/BluetoothLinux/HCI.swift @@ -283,7 +283,7 @@ internal struct HCIDeviceInformation { var name: (CChar, CChar, CChar, CChar, CChar, CChar, CChar, CChar) = (0, 0, 0, 0, 0, 0, 0, 0) /// bdaddr_t bdaddr; - var address: Address = Address() + var address: BluetoothAddress = BluetoothAddress() /// uint32_t flags; var flags: UInt32 = 0 diff --git a/Sources/BluetoothLinux/HostController.swift b/Sources/BluetoothLinux/HostController.swift index e19b566..3764008 100644 --- a/Sources/BluetoothLinux/HostController.swift +++ b/Sources/BluetoothLinux/HostController.swift @@ -27,7 +27,7 @@ public final class HostController: BluetoothHostControllerInterface { public let identifier: Identifier /// The Bluetooth Address of the controller. - public let address: Address + public let address: BluetoothAddress // MARK: - Internal Properties @@ -44,12 +44,12 @@ public final class HostController: BluetoothHostControllerInterface { public init(identifier: Identifier) throws { self.identifier = identifier - self.address = try Address(deviceIdentifier: identifier) + self.address = try BluetoothAddress(deviceIdentifier: identifier) self.internalSocket = try HCIOpenDevice(identifier) } /// Initializes the Bluetooth controller with the specified address. - public init(address: Address) throws { + public init(address: BluetoothAddress) throws { guard let deviceIdentifier = try HCIGetRoute(address) else { throw Error.adapterNotFound } @@ -90,7 +90,7 @@ public extension HostController { // MARK: - Address Extensions -public extension Address { +public extension BluetoothAddress { /// Extracts the Bluetooth address from the device ID. /// @@ -200,7 +200,7 @@ internal func HCIIdentifierOfDevice(_ flagFilter: HCIDeviceFlag = HCIDeviceFlag( return result } -internal func HCIGetRoute(_ address: Address? = nil) throws -> UInt16? { +internal func HCIGetRoute(_ address: BluetoothAddress? = nil) throws -> UInt16? { return try HCIIdentifierOfDevice { (dd, deviceIdentifier) in @@ -238,7 +238,7 @@ internal func HCIDeviceInfo(_ deviceIdentifier: UInt16) throws -> HCIDeviceInfor return deviceInfo } -internal func HCIDeviceAddress(_ deviceIdentifier: UInt16) throws -> Address { +internal func HCIDeviceAddress(_ deviceIdentifier: UInt16) throws -> BluetoothAddress { let deviceInfo = try HCIDeviceInfo(deviceIdentifier) @@ -275,7 +275,5 @@ internal func HCITestBit(_ flag: HCI.DeviceFlag, _ options: UInt32) -> Bool { // MARK: - Darwin Stubs #if os(OSX) || os(iOS) - - var SOCK_CLOEXEC: CInt { stub() } - +var SOCK_CLOEXEC: CInt { stub() } #endif diff --git a/Sources/BluetoothLinux/L2CAP.swift b/Sources/BluetoothLinux/L2CAP.swift index 3220b52..9f8838a 100644 --- a/Sources/BluetoothLinux/L2CAP.swift +++ b/Sources/BluetoothLinux/L2CAP.swift @@ -40,7 +40,7 @@ public final class L2CAPSocket: L2CAPSocketProtocol { } /// Create a new L2CAP socket on the HostController with the specified identifier. - public init(controllerAddress: Address, + public init(controllerAddress: BluetoothAddress, protocolServiceMultiplexer: UInt16 = 0, channelIdentifier: UInt16 = ATT.CID, addressType: AddressType? = .lowEnergyPublic, @@ -71,7 +71,7 @@ public final class L2CAPSocket: L2CAPSocketProtocol { } /// Creates a server socket for an L2CAP connection. - public static func lowEnergyServer(controllerAddress: Address = .any, + public static func lowEnergyServer(controllerAddress: BluetoothAddress = .any, isRandom: Bool = false, securityLevel: SecurityLevel = .low) throws -> L2CAPSocket { @@ -87,8 +87,8 @@ public final class L2CAPSocket: L2CAPSocketProtocol { } /// Creates a client socket for an L2CAP connection. - public static func lowEnergyClient(controllerAddress: Address = .any, - destination: (address: Address, type: AddressType), + public static func lowEnergyClient(controllerAddress: BluetoothAddress = .any, + destination: (address: BluetoothAddress, type: AddressType), securityLevel: SecurityLevel = .low) throws -> L2CAPSocket { let socket = try L2CAPSocket(controllerAddress: controllerAddress, @@ -128,7 +128,7 @@ public final class L2CAPSocket: L2CAPSocketProtocol { /// Create the underlying socket for the L2CAP. @inline(__always) - private static func createSocket(controllerAddress: Address, + private static func createSocket(controllerAddress: BluetoothAddress, protocolServiceMultiplexer: UInt16, channelIdentifier: UInt16, addressType: AddressType?) throws -> (CInt, sockaddr_l2) { @@ -164,9 +164,9 @@ public final class L2CAPSocket: L2CAPSocketProtocol { // MARK: - Accessors /// Bluetooth address - public var address: Address { + public var address: BluetoothAddress { - return Address(littleEndian: internalAddress.l2_bdaddr) + return BluetoothAddress(littleEndian: internalAddress.l2_bdaddr) } public var addressType: AddressType { @@ -240,7 +240,7 @@ public final class L2CAPSocket: L2CAPSocketProtocol { } /// Connect to another L2CAP server. - public func openConnection(to address: Address, + public func openConnection(to address: BluetoothAddress, type addressType: AddressType = .lowEnergyPublic) throws { // Set up destination address @@ -415,7 +415,7 @@ let L2CAP_OPTIONS: CInt = 0x01 struct sockaddr_l2 { var l2_family: sa_family_t = 0 var l2_psm: CUnsignedShort = 0 - var l2_bdaddr: Address = .zero + var l2_bdaddr: BluetoothAddress = .zero var l2_cid: CUnsignedShort = 0 var l2_bdaddr_type: UInt8 = 0 init() { } diff --git a/Sources/BluetoothLinux/Scan.swift b/Sources/BluetoothLinux/Scan.swift index ce085de..2cb6389 100644 --- a/Sources/BluetoothLinux/Scan.swift +++ b/Sources/BluetoothLinux/Scan.swift @@ -89,7 +89,7 @@ public extension HostController { public struct InquiryResult { /// Device Address - public var address = Address() + public var address = BluetoothAddress() public var pscanRepMode: UInt8 = 0