0

I have a BLE SoC (QN9021) connected to a linux system (beagle bone running openwrt) via UART interface. I want linux to recognize BLE connected with system and commands like gatttool, hcitool should work with my BLE.

Also, i am using Bluez and i want BlueZ libraries should find and communicates directly with my BLE.

It looks like source files in bluez uses socket() function call to communicate with the bluetooth adapter. I have posted section of hcitool.c source file which includes socket call:

/* Open HCI device.
 * Returns device descriptor (dd). */
int hci_open_dev(int dev_id)
{
struct sockaddr_hci a;
int dd, err;

/* Check for valid device id */
if (dev_id < 0) {
    errno = ENODEV;
    return -1;
}

/* Create HCI socket */
dd = socket(AF_BLUETOOTH, SOCK_RAW | SOCK_CLOEXEC, BTPROTO_HCI);
if (dd < 0)
    return dd;

/* Bind socket to the HCI device */
memset(&a, 0, sizeof(a));
a.hci_family = AF_BLUETOOTH;
a.hci_dev = dev_id;
if (bind(dd, (struct sockaddr *) &a, sizeof(a)) < 0)
    goto failed;

return dd;

failed:
err = errno;
close(dd);
errno = err;

return -1;
}

As previously mentioned, i am connecting BLE SoC via UART. How can i make my BLE recognized as a bluetooth and function call like socket() should open descriptor of my BLE?

abhiarora
  • 9,743
  • 5
  • 32
  • 57
  • 1
    Haven't searched extensively, but I think you'll need to use [`hciattach`](http://manpages.ubuntu.com/manpages/trusty/man8/hciattach.8.html) – Hasturkun Jan 05 '17 at 07:57
  • Can i do it programmatically? – abhiarora Jan 05 '17 at 09:30
  • 1
    You can, but assuming the HCI isn't going anywhere, it's the kind of thing you'd have either an init script or your code execute `hciattach` (since it has some initialization code for certain HCIs). See [hciattach source](http://git.kernel.org/cgit/bluetooth/bluez.git/tree/tools/hciattach.c) if you're interested in the details. – Hasturkun Jan 05 '17 at 13:08
  • Thanks for you answer – abhiarora Jan 10 '17 at 18:46

1 Answers1

1

Does anything show up when you run?

dmesg | grep blue

or

lsmod | grep blue

You need to make sure you have a linux driver for this module, that it's available in your kernel (NXP and TI don't necessarily like to play together) and probably that it's built into your device tree.

You'd probably have better luck using a TI BLE module that has driver support.

RooterTooter
  • 384
  • 1
  • 6
  • I can make linux module for supporting the QN. Please guide me for it. – abhiarora Feb 03 '17 at 16:14
  • Please have a look at my newest question! [My new question](http://stackoverflow.com/questions/41944822/bluetooth-over-uart-using-hciattach) – abhiarora Feb 03 '17 at 16:15