element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Code Exchange
  • Technologies
  • More
Code Exchange
Forum Implementing Bluetooth technology - in C/C++ code.
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Code Exchange to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 15 replies
  • Subscribers 45 subscribers
  • Views 2584 views
  • Users 0 members are here
  • bluetooth
  • library
  • bluez
Related

Implementing Bluetooth technology - in C/C++ code.

anneranch
anneranch 10 months ago

I am looking for discussion on how to implement Bluetooth technology in C/C++ code.

My main concern is toi do this reliably and repeatedly.

I am basically using very old HCI approach, implementing  "bluez" "library" .

The code works, despite lack of documentation of "bluez library".

My "in words" question is

How  does "local  Bluetooth adapter " implements / enables  "scan" for remote Bluetooth device ,

how is "paring" and  "connect"  used dur9ing this process.]

The answer must be in "bluez"  library , however I am unable to "step thru " its code - too convoluted  and

not documented.

( I will post the link to C code when it became beneficial for detailed discussion )

 My secondary concern is

how to analyze and then  implement

"replacing USB serial cable  " witht Bluetooth technology / connecti0on?

Let's see how the forum sill respond and then I could give details for the secondary issue.

  • Sign in to reply
  • Cancel

Top Replies

  • shabaz
    shabaz 10 months ago +4
    The pairing, connect etc are all done by GAP messages. In the diagram below, you can see that those messages are ultimately converted down to a payload that is wrapped with a header and checksum, and then…
Parents
  • shabaz
    shabaz 10 months ago


    The pairing, connect etc are all done by GAP messages. In the diagram below, you can see that those messages are ultimately converted down to a payload that is wrapped with a header and checksum, and then launched over the air to the remote device. There will be a state machine that is executed on both devices, to get through the entire negotiation sequences, i.e. the protocol is implemented with those state machines. Everything in the large blue box is within the Bluez library. It is indeed complicated to follow and has poor documentation, but it does work, and there's not much choice, it is what it is. It would be a very large effort to write your own implementation from scratch, because there are tens of thousands of pages of Bluetooth documentation to look through.

    Regarding the second question, there are several manufacturers who have implemented this in firmware for their devices. It's very old technology, google 'serial port profile'. If you wish to do it using modern BLE (i.e. Bluetooth LE) then the answer is usually proprietary, since it's not defined in the standard. You could look at typical example devices like Silabs
    BGM220P, and the website offers example code to implement serial communication over BLE ( https://github.com/SiliconLabs/bluetooth_applications/tree/ea5d14cc4884a6d8f5c3af4345d430716433e72d/bluetooth_serial_port_profile  ) . But because that's proprietary, you'd have to hope there are drivers for it for the PC (or whatever hardware you are using), if you're not using their devices at both ends of the communication link. 

    image

    • Cancel
    • Vote Up +4 Vote Down
    • Sign in to reply
    • Cancel
  • anneranch
    anneranch 10 months ago in reply to shabaz

    Thanks for replies , but that is NOT what I am asking about.

    This approach is all wonderful theory  of "Bluetooth stack", no argument there. I am asking for how to follow the "Bluetooth stack" process using  ACTUAL C code.

    Here is a "work in progress" code snippet :

    pET->start();
    dev_id = hci_get_route(NULL);
    text = "dev_id \t";
    text += QString::number(dev_id);
    m_ui->textEdit_37->setText(text);
    m_ui->textEdit_52->append(text);

    sock = hci_open_dev( dev_id );
    if (dev_id < 0 || sock < 0) {

    ...

    // actuall scan restart timer
    pET->start();

    num_rsp = hci_inquiry(dev_id, len, max_rsp, NULL, &ii, flags);
    if( num_rsp < 0 )
    {
    text = "\t\t\tERROR no devices found ";
    m_ui->textEdit_37->append(text); // local
    m_ui->textEdit_52->append(text); // TRACE

    So my question would be :
    "how do "hci_get_route" and "hci_inquiry"  functions implements / fits into the above "blue box" ,  or similar "blue box" for standard Bluetooth stack?

    PS.

    I understand there are differences between "standard" and "LE" Bluetooth implementation. I am pretty much stuck with "standard" due to my available hardware.

    PPS.

    I am still searching for current bluez version source code to analyze "hci_inquiry"  function...

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • shabaz
    shabaz 10 months ago in reply to anneranch

    Thats a pretty rude response from you when someone is trying to help.

    It is not my fault you have trouble articulating what you actually want to know.

    So my answer will be brief, and you can figure out the rest yourself.

    Your snippet of code is already at the lowest level in the BlueZ stack. The aircraft has not taken off yet. The code is operating at the bottom of the blue box.

    You're not going to be able to see the C code of what then occurs at a lower level, because that's going to run within hardware/firmware on the Bluetooth processor, not the PC. The state machine that churns away to work at that lower level is inside the Bluetooth processor.

    You can google for an explanation of HCI to understand this. No links, because I'm leaving that to you to figure out. You might also want to pick up some competence at responding in a polite manner.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • shabaz
    shabaz 10 months ago in reply to anneranch

    Thats a pretty rude response from you when someone is trying to help.

    It is not my fault you have trouble articulating what you actually want to know.

    So my answer will be brief, and you can figure out the rest yourself.

    Your snippet of code is already at the lowest level in the BlueZ stack. The aircraft has not taken off yet. The code is operating at the bottom of the blue box.

    You're not going to be able to see the C code of what then occurs at a lower level, because that's going to run within hardware/firmware on the Bluetooth processor, not the PC. The state machine that churns away to work at that lower level is inside the Bluetooth processor.

    You can google for an explanation of HCI to understand this. No links, because I'm leaving that to you to figure out. You might also want to pick up some competence at responding in a polite manner.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube