Bluetooth pairing in C on Linux - c

I am looking for information, documentation, sample code or something else about the management of Bluetooth pairing/encryption in C under linux. Where can i find that ?
Regards,
Alban

The dominant bluetooth stack at the moment is Bluez; a good tutorial can be found at An Introduction to Bluetooth Programming

You can use hciconfig, which is a tool supplied as part of BlueZ. The actual pairing / encryption is done inside the BT device, not the host stack. You just configure the BT device using hciconfig to tell it whether to do authentication and encryption.
See hciconfig man page, specifically the auth/noauth and encrypt/noencrypt commands

AFAIK the pairing API is via D-Bus, which can be accessed in C.
See e.g. http://git.kernel.org/?p=bluetooth/bluez.git;a=blob;f=doc/adapter-api.txt;hb=HEAD and http://git.kernel.org/?p=bluetooth/bluez.git;a=blob;f=doc/agent-api.txt;hb=HEAD

Related

develop BLE peripheral using C on intel edison

I am trying to develop a bluetooth LE peripheral in intel-edison, by using C library. The device should be able to :
advertise (GAP)
accept connection (GAP)
support custom GATT service, simply read/write value of characteristic.
I try to use HCI and bluez to implement this. bluez-experiments, intel-edison-playground, which demonstrate how to advertise and scan, can be compiled and run on edison. BLE advertising and scanning do work.
But I have hard time to figure out how to accept connection and support GATT service. I try to search on goolge about the HCI document but have no luck. Can someone provide a snippet of code (c or pseudo or a description)?
Thank you so much!
Andrew
If you download the bluez source you'll find documentation on the hci protocol in /doc/mgmt-api.txt. I'm not using the hci interface myself, and I'm not sure if the developers intend for implementors to use this interface to implement peripherals, so I'm not sure how well this will work.
I went with the DBus API approach for my project, which is outlined in /doc/gatt-api.txt and /doc/advertising-api.txt. This approach involves writing a program which creates DBus objects which support specific org.bluez DBus interfaces (GattService1 which contains GattCharacteristic1 and GattDescriptor1) and the ObjectManager interface to expose everything to bluez. You then use LEAdvertisment1 to define what is advertised and register the advertisement using the LEAdvertisingManger1 interface on the adapter.
I used Qt to simplify the DBus communication parts.
The DBus API for BLE on bluez is still in heavy development, and not all features are supported (I still haven't found a way to start and stop advertising, for example). 5.31 contains a lot of added supported and some critical bug fixes for descriptors, but requires a newer kernel.

establish bluetooth piconet connection between server and two clients using c on linux platform?

I want to establish Bluetooth network where one server can communicate to two clients (ie piconet) using C programm on linux platform, rfcomm based communication.
Can any one please share your guidance or sample source code if have.
I newbie to the bluetooth technology, have not found any useful info or code from internet source so far. so please.
Thank you
Basu
Linux runs open source BlueZ Bluetooth Stack, which works quite well (unless you need Bluetooth Low Energy). You can check out this tutorial: http://people.csail.mit.edu/albert/bluez-intro/c404.html
PS. Mind the GPL license when using #include like in those examples.
Edit:
As for creating piconet specifically, I'm afraid I don't have any snippets. However, after quick search, I would look into using bluez library to open not one but many RFCOMM sockets. So you can listen to and accept multiple connections.

lwIP telnet example?

I'm doing some experiments with lwIP on a small, embedded device. There are some examples that come with lwIP but they do not help me. What I want to implement is a server (using wlIP) that accepts a connection, reads several commands, sends several answers to the connected client and closes only when the connection is interrupted or a special close-command is sent.
So somehow similar to a telnet-server.
Is there an example for lwIP available that demonstrates this behaviour?
Thanks!
I know this is an old question - but I found it when looking for something similar!
If you look in the lwip contrib directory (http://download.savannah.gnu.org/releases/lwip/) there are some example applications - including a tcp (and udp) echo server.
You don't say what device you are using or whether or not you are using an RTOS, so it is hard to provide example code. However, if you are not using an RTOS I would highly recommend you start! My experience of using the lwip raw api (without an rtos) is that it is difficult to read data from the outside world (e.g. using interrupts) without things falling over.
HTH,
Alex

Code sample HID client using Bluez

I'm desperately looking for some C sample source code that describes how to implement a HID client using Bluez. More specifically, I would like to know how to write an application that sends keyboard inputs over bluetooth to another Linux system. (Really, the fact that the receiver is running Linux/Bluez shouldn't matter.)
-Cheers
hidclient http://anselm.hoffmeister.be/computer/hidclient/index.html.en ?
Shamelessly copying from a previous answer of mine:
Some time ago I found this project:
http://nohands.sourceforge.net/index.html
They emulate a full-blown headset with
audio and keyboard controls on the
Linux bluetooth stack. If they can
emulate something like that, you would
probably be able to emulate something
simpler like a keyboard.
Here is full example apply to keyboard and mouse include get report set report virtual unplug function. the client hid is slave side...
http://fatalfeel.blogspot.tw/2013/09/hid-client-of-bluez.html
and you can refer to bluez/android/hidhost.c(Master side) see how to connect to slave

asynchronous serial transmission C

So i'm working on a program, wich is vaguely going to resemble
Br#y's Terminal, but running from the commandline in linux
It will do asynchronous transmission, out the serial (Com) port.
Now i think the Header/library i need for this is the termios.h
Now i've only used posix a little before and i;m finding it rather heavy going digging though manpages/specifactions
http://www.opengroup.org/onlinepubs/007908799/xsh/termios.h.html\
Does anyone know of any good guides to termios?
I would google it myself (i've tired) but i don't understand the content enough to know if a guide is good.
Am i using the right library,even?
There's a wiki book available that covers termios. Yes you are using the right library. It's the only way to manipulate the device to talk over the serial line as it controls it. There is a brief introduction to termios in this blog. Here is another wiki book on serial programming under Linux.
Hope this helps,
Best regards,
Tom.

Resources