How to establish an L2Capp interrupt channel connection?

I am trying to open the L2Cap HID Channel and Interrupt so that I can send HID commands to a Bluetooth device.

I performed all my advertising and device processing and established a connection to the main network.

The Hid Control channel opens normally. When I try to create my kbluetoothL2CAPPSMHIDInterrupt connection

l2capChannelQueueSpaceAvailable

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

l2capChannelOpenComplete

but the connection closes immediately, causing

l2capChannelClosed

How can I open this connection correctly?

I have been digging in the IOBlueTooth infrastructure and the bluetooth.org HID specification for a long time, but I have almost no useful information (which I can find at least).

When I trace my L2Cap channels, I see a few null values โ€‹โ€‹for

mIncomingDataListener

and

mEventDataListener

. I don't know how to install them or if they have anything to do with my problem ... just speculating.

The code snippet below is my attempt to make connections after establishing a connection with the device.

-(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 plugged in my package logs. It's weird request for

kBluetoothL2CAPPSMSDP 0x0001

is created without my request, and then everything starts to trip.

BT Package Logs

+6
source share
1 answer

According to your logs, itโ€™s very clear that your device is in limited connection mode, it remains active for 30 seconds or less. Change your deviceโ€™s settings to make it public.

kBluetoothL2CAPPSMSDP 0x0001

means bit 13 - limited detection mode

Playing with Bluetooth settings will solve your problem.

0
source

Source: https://habr.com/ru/post/990004/


All Articles