Ejemplo n.º 1
0
        public byte[] SetConnectionType(L2CAP.PSM connectionType, byte lsb, byte msb, ushort dcid = 0)
        {
            switch (connectionType)
            {
            case L2CAP.PSM.HID_Command:

                _l2CapCommandHandle[0] = new BthHandle(lsb, msb);
                _l2CapCommandHandle[1] = new BthHandle(Dcid++);

                return(_l2CapCommandHandle[1].Bytes);

            case L2CAP.PSM.HID_Interrupt:

                CanStartService = true;

                _l2CapInterruptHandle[0] = new BthHandle(lsb, msb);
                _l2CapInterruptHandle[1] = new BthHandle(Dcid++);

                return(_l2CapInterruptHandle[1].Bytes);

            case L2CAP.PSM.HID_Service:

                IsServiceStarted = true;
                CanStartService  = false;

                _l2CapServiceHandle[0] = new BthHandle(lsb, msb);
                _l2CapServiceHandle[1] = new BthHandle(dcid);

                return(_l2CapServiceHandle[1].Bytes);
            }

            throw new ArgumentException("Invalid L2CAP Connection Type");
        }
Ejemplo n.º 2
0
        public BthConnection(BthHandle hciHandle)
        {
            InitializeComponent();

            HciHandle     = hciHandle;
            DeviceAddress = PhysicalAddress.None;
        }
Ejemplo n.º 3
0
        public int HCI_Disconnect(BthHandle handle)
        {
            var buffer = new byte[6];

            buffer[3] = handle.Bytes[0];
            buffer[4] = (byte)(handle.Bytes[1] ^ 0x20);
            buffer[5] = 0x13;

            return(HCI_Command(HCI.Command.HCI_Disconnect, buffer));
        }
Ejemplo n.º 4
0
        private int HCI_Set_Connection_Encryption(BthHandle Handle)
        {
            var buffer = new byte[6];

            buffer[3] = Handle.Bytes[0];
            buffer[4] = (byte)(Handle.Bytes[1] ^ 0x20);
            buffer[5] = 0x01;

            return(HCI_Command(HCI.Command.HCI_Set_Connection_Encryption, buffer));
        }
Ejemplo n.º 5
0
        private void Remove(byte lsb, byte msb)
        {
            var connection = new BthHandle(lsb, msb);

            if (!_connected.ContainsKey(connection))
            {
                return;
            }

            _connected[connection].Stop();
            _connected.Remove(connection);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Returns an existing Bluetooth connection based on an incoming buffer.
        /// </summary>
        /// <param name="lsb">Least significant bit in byte stream.</param>
        /// <param name="msb">Most significant bit in byte stream.</param>
        /// <returns>The Bluetooth connection, null if not found.</returns>
        private BthDevice GetConnection(byte lsb, byte msb)
        {
            var hande = new BthHandle(lsb, msb);

            return((!_connected.Any() | !_connected.ContainsKey(hande)) ? null : _connected[hande]);
        }
Ejemplo n.º 7
0
 public BthConnection(BthHandle hciHandle)
 {
     HciHandle     = hciHandle;
     DeviceAddress = PhysicalAddress.None;
 }
Ejemplo n.º 8
0
 public L2CapDataPacket(byte[] buffer)
 {
     RawBytes = buffer;
     Handle   = new BthHandle(RawBytes[0], RawBytes[1]);
 }
Ejemplo n.º 9
0
        public BthConnection(BthHandle hciHandle)
        {
            InitializeComponent();

            HciHandle = hciHandle;
        }