How Can I Establish A L2Capp Interrupt Channel Connection?
Asked Answered
D

1

7

Im trying to open a L2Cap HID Channel And Interrupt channel so I can send HID commands to a bluetooth device.

I've done all my service advertising and device paring and established a baseband connection.

The Hid Control channel opens fine. When I try to create my kBluetoothL2CAPPSMHIDInterrupt connection

l2capChannelQueueSpaceAvailable

delegate method called (not sure what this means) followed by

l2capChannelOpenComplete

but the connection closes immediately calling

l2capChannelClosed

How can I correctly open these connection?

I've spent a long time digging through the IOBlueTooth framework and the bluetooth.org HID spec but theres barely any helpful information (that I can find at least).

When i trace out my L2Cap channels I see some null values for

mIncomingDataListener

and

mEventDataListener

. I dont know how to set these or if they have anything to do with my problem.... just speculating.

The code snippet below is my attempt so far to make the connections after a connection to the device has been established.

-(void)establishL2CappConnections:(IOBluetoothDevice*)device
{
    IOReturn r;
    IOBluetoothL2CAPChannel *ch1;
    r = [device openL2CAPChannelSync:&ch1
                             withPSM:(BluetoothL2CAPPSM)kBluetoothL2CAPPSMHIDControl
                            delegate:self];
    self.mL2CappChannel=ch1;
    NSLog(@"r == %i",r);

    IOBluetoothL2CAPChannel *ch2;
    r = [device openL2CAPChannelSync:&ch2
                             withPSM:(BluetoothL2CAPPSM)kBluetoothL2CAPPSMHIDInterrupt
                            delegate:self];
    self.mL2CappInterruptChannel=ch2;
    NSLog(@"r == %i",r);


}

Edit:1

I've attached my packet logs. It's strange, a request for

kBluetoothL2CAPPSMSDP 0x0001

gets made without me requesting it and then everything starts disconnecting.

BT Packet Logs

Distort answered 30/6, 2015 at 11:8 Comment(2)
just an update for interested people. If your sdp service record is incorrect the L2cap connections will not stay open. Also you do not make the kBluetoothL2CAPPSMSDP connection yourself. Only the interrupt and controll onesDistort
did you manage to solve this in the end? I'm trying and failing to create a HID device myself atm but finding good examples on how to do this are my biggest barrier atmNostalgia
R
0

As per your logs its very clear that your device in in Limited Connection mode, its stays Active for 30sec or less. change device settings to make it General Discoverable.

kBluetoothL2CAPPSMSDP 0x0001

means Bit 13 - Limited Discoverable Mode

Playing with the Bluetooth settings will solve your problem

Remus answered 8/7, 2015 at 4:20 Comment(1)
Can you clarify this please? No where in my code do I use kBluetoothL2CAPPSMSDP. It seems to get used automatically when I try to open an interrupt channel. Do you mean change some setting somewhere on my actual mac or in the settings of the device im trying to connect to?Distort

© 2022 - 2024 — McMap. All rights reserved.