<commit_before>//
//  CInterop.swift
//  
//
//  Created by <NAME> on 16/10/21.
//

import Bluetooth
import BluetoothHCI
import SystemPackage
import CBluetoothLinux

public extension CInterop {
    
    struct HCISocketAddress: Equatable, Hashable {
        
        public var family: CInterop.SocketAddressFamily //sa_family_t()
        public var device: UInt16
        public var channel: UInt16
        
        public init(
            device: UInt16 = 0,
            channel: UInt16 = 0
        ) {
            self.family = .init(CInterop.HCISocketAddress.family.rawValue)
            self.device = device
            self.channel = channel
        }
    }
}

extension CInterop.HCISocketAddress: CSocketAddress {
    
    @usableFromInline
    static var family: SocketAddressFamily { .bluetooth }
}

public extension CInterop {
    
    /// `sockaddr_l2` L2CAP socket address (not packed)
    struct L2CAPSocketAddress: Equatable, Hashable {
        var l2_family: sa_family_t = 0
        var l2_psm: CUnsignedShort = 0
        var l2_bdaddr: BluetoothAddress = .zero
        var l2_cid: CUnsignedShort = 0
        var l2_bdaddr_type: UInt8 = 0
        init() { }
    }
}

extension CInterop.L2CAPSocketAddress: CSocketAddress {
    
    @usableFromInline
    static var family: SocketAddressFamily { .bluetooth }
}

public extension CInterop {
    
    /// `l2cap_conninfo` L2CAP Connection Information
    struct L2CAPConnectionInfo {
        public var handle: UInt16
        public var deviceClass: (UInt8, UInt8, UInt8)
        public init(handle: UInt16 = 0,
                    deviceClass: (UInt8, UInt8, UInt8) = (0,0,0)) {
            self.handle = handle
            self.deviceClass = deviceClass
        }
    }
}

public extension CInterop {
    
    /// `l2cap_options` L2CAP Socket Options
    struct L2CAPSocketOptions {
        
        public var outputMaximumTransmissionUnit: UInt16 // omtu
        public var inputMaximumTransmissionUnit: UInt16 // imtu
        public var flushTo: UInt16 // flush_to
        public var mode: UInt8
        public var fcs: UInt8
        public var maxTX: UInt8 // max_tx
        public var txwinSize: UInt8 // txwin_size
        
        public init() {
            self.outputMaximumTransmissionUnit = 0
            self.inputMaximumTransmissionUnit = 0
            self.flushTo = 0
            self.mode = 0
            self.fcs = 0
            self.maxTX = 0
            self.txwinSize = 0
        }
    }
}

public extension CInterop {
    
    /// `bt_power` Bluetooth power options
    struct BluetoothPower {
        public var forceActive: UInt8
        public init(forceActive: UInt8 = 0) {
            self.forceActive = forceActive
        }
    };
}
    
public extension CInterop {

    /// `bt_security` Bluetooth security level (not packed)
    struct BluetoothSocketSecurity: Equatable, Hashable {
        var level: UInt8 = 0
        var key_size: UInt8 = 0
        init() { }
    }
}

/* Ioctl requests structures */

public extension CInterop {
    
    /// `hci_dev_list_req`
    struct HCIDeviceList {
        
        /// uint16_t dev_num;
        public private(set) var numberOfDevices: UInt16
        
        /// struct hci_dev_req dev_req[0];    /* hci_dev_req structures */
        /// 16 elements
        public private(set) var list: (Element, Element, Element, Element, Element, Element, Element, Element, Element, Element, Element, Element, Element, Element, Element, Element)
        
        init() {
            self.numberOfDevices = 0
            self.list = (Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element())
        }
    }<commit_msg>Updated `CInterop`<commit_after>//
//  CInterop.swift
//  
//
//  Created by <NAME> on 16/10/21.
//

import Bluetooth
import BluetoothHCI
import SystemPackage
import CBluetoothLinux

public extension CInterop {
    
    /// `sockaddr_hci`
    struct HCISocketAddress: Equatable, Hashable {
        
        public var family: CInterop.SocketAddressFamily //sa_family_t()
        public var device: UInt16
        public var channel: UInt16
        
        public init(
            device: UInt16 = 0,
            channel: UInt16 = 0
        ) {
            self.family = .init(CInterop.HCISocketAddress.family.rawValue)
            self.device = device
            self.channel = channel
        }
    }
}

extension CInterop.HCISocketAddress: CSocketAddress {
    
    @usableFromInline
    static var family: SocketAddressFamily { .bluetooth }
}

public extension CInterop {
    
    /// `sockaddr_l2` L2CAP socket address (not packed)
    struct L2CAPSocketAddress: Equatable, Hashable {
        var l2_family: sa_family_t = 0
        var l2_psm: CUnsignedShort = 0
        var l2_bdaddr: BluetoothAddress = .zero
        var l2_cid: CUnsignedShort = 0
        var l2_bdaddr_type: UInt8 = 0
        init() { }
    }
}

extension CInterop.L2CAPSocketAddress: CSocketAddress {
    
    @usableFromInline
    static var family: SocketAddressFamily { .bluetooth }
}

public extension CInterop {
    
    /// `sockaddr_rc` RFCOMM socket address
    struct RFCOMMSocketAddress: Equatable, Hashable {
        
        public let family: CInterop.SocketAddressFamily
        public var address: BluetoothAddress
        public var channel: UInt8
        
        public init(address: BluetoothAddress = .zero, channel: UInt8 = 0) {
            self.family = .init(Self.family.rawValue)
            self.address = address
            self.channel = channel
        }
    }
}

extension CInterop.RFCOMMSocketAddress: CSocketAddress {
    
    @usableFromInline
    static var family: SocketAddressFamily { .bluetooth }
}

public extension CInterop {
    
    /// `sockaddr_sco` SCO Socket Address
    struct SCOSocketAddress: Equatable, Hashable {
        public let family: CInterop.SocketAddressFamily
        public var address: BluetoothAddress
        public init(address: BluetoothAddress = .zero) {
            self.family = .init(Self.family.rawValue)
            self.address = address
        }
    }
}

extension CInterop.SCOSocketAddress: CSocketAddress {
    
    @usableFromInline
    static var family: SocketAddressFamily { .bluetooth }
}

public extension CInterop {
    
    /// `l2cap_conninfo` L2CAP Connection Information
    struct L2CAPConnectionInfo {
        public var handle: UInt16
        public var deviceClass: (UInt8, UInt8, UInt8)
        public init(handle: UInt16 = 0,
                    deviceClass: (UInt8, UInt8, UInt8) = (0,0,0)) {
            self.handle = handle
            self.deviceClass = deviceClass
        }
    }
}

public extension CInterop {
    
    /// `l2cap_options` L2CAP Socket Options
    struct L2CAPSocketOptions {
        
        public var outputMaximumTransmissionUnit: UInt16 // omtu
        public var inputMaximumTransmissionUnit: UInt16 // imtu
        public var flushTo: UInt16 // flush_to
        public var mode: UInt8
        public var fcs: UInt8
        public var maxTX: UInt8 // max_tx
        public var txwinSize: UInt8 // txwin_size
        
        public init() {
            self.outputMaximumTransmissionUnit = 0
            self.inputMaximumTransmissionUnit = 0
            self.flushTo = 0
            self.mode = 0
            self.fcs = 0
            self.maxTX = 0
            self.txwinSize = 0
        }
    }
}

public extension CInterop {
    
    /// `bt_power` Bluetooth power options
    struct BluetoothPower {
        public var forceActive: UInt8
        public init(forceActive: UInt8 = 0) {
            self.forceActive = forceActive
        }
    };
}
    
public extension CInterop {

    /// `bt_security` Bluetooth security level (not packed)
    struct BluetoothSocketSecurity: Equatable, Hashable {
        var level: UInt8 = 0
        var key_size: UInt8 = 0
        init() { }
    }
}

public extension CInterop {
    
    /// `rfcomm_conninfo` RFCOMM Connection Information
    struct RFCOMMConnectionInfo {
        public var handle: UInt16
        public var deviceClass: (UInt8, UInt8, UInt8)
        public init(handle: UInt16 = 0,
                    deviceClass: (UInt8, UInt8, UInt8) = (0,0,0)) {
            self.handle = handle
            self.deviceClass = deviceClass
        }
    }
}

public extension CInterop {
    
    /// `rfcomm_dev_req`
    struct RFCOMMDeviceRequest {
        
    }
}

public extension CInterop {
    
    /// `sco_conninfo` SCO Connection Information
    struct SCOConnectionInfo {
        public var handle: UInt16
        public var deviceClass: (UInt8, UInt8, UInt8)
        public init(handle: UInt16 = 0,
                    deviceClass: (UInt8, UInt8, UInt8) = (0,0,0)) {
            self.handle = handle
            self.deviceClass = deviceClass
        }
    }
}

public extension CInterop {
    
    /// `hci_dev_list_req`
    struct HCIDeviceList {
        
        /// uint16_t dev_num;
        public private(set) var numberOfDevices: UInt16
        
        /// struct hci_dev_req dev_req[0];    /* hci_dev_req structures */
        /// 16 elements
        public private(set) var list: (Element, Element, Element, Element, Element, Element, Element, Element, Element, Element, Element, Element, Element, Element, Element, Element)
        
        init() {
            self.numberOfDevices = 0
            self.list = (Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element(), Element())
        }
    }
{'fraction_non_alphanumeric': 0.08613532586135327, 'fraction_numerical': 0.020236612702366128, 'mean_word_length': 2.0749840459476707, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2550176', 'n_tokens_mistral': 2916, 'n_tokens_neox': 2806, 'n_words': 740}