Giter Club home page Giter Club logo

Comments (5)

FTaluk avatar FTaluk commented on June 26, 2024

Hi,
I figured it out. Actually, I created a simple work-around. The setAdvertising() method Mgmt.cpp file has been modified. This method now disables the "setAdvertising" command and then uses "addAdvertising Command" to make use of a custom AD-Payload. I used only one instance, zero for all time related parameters, zero for all flags. I didn't use the scan response field. The whole raw-advertising data is provied as adv_data. This worked for me.

from gobbledegook.

stez-mind avatar stez-mind commented on June 26, 2024

For those interested, I also did something similar as the FTaluk solution.

I'll have to think more how to include this in a way that's generic enough for making a PR but in the meanwhile, here's my implementation in Mgmt.cpp that calls addAdvertising adding one 128-bit service UUID and a 8 chars short name into the advertisement packet:

// Start advertising with custom data
// Advertisement packet will contain: flags, shortName, uuid
bool Mgmt::addAdvertising(std::string shortName, const uint8_t* uuid)
{
    constexpr size_t ADVERTISING_SHORTNAME_MAX_LEN = 8;
    constexpr size_t ADVERTISING_UUID_LEN = 16;
    constexpr size_t ADVERTISING_MAX_DATALEN = 2 + ADVERTISING_SHORTNAME_MAX_LEN + 2 + ADVERTISING_UUID_LEN;

    struct SRequest : HciAdapter::HciHeader
    {
        uint8_t  instance;
        uint32_t flags;
        uint16_t duration;
        uint16_t timeout;
        uint8_t  advDataLen;
        uint8_t  scanRspLen;
        uint8_t  data[ADVERTISING_MAX_DATALEN];
    } __attribute__((packed));

    SRequest request;
    request.code = Mgmt::EAddAdvertisingCommand;
    request.controllerId = controllerIndex;
    request.dataSize = sizeof(SRequest) - sizeof(HciAdapter::HciHeader);

    request.instance = 1u;
    request.flags = 3u; // Connectable && Discoverable, see Bluez/lib/mgmt.h
    request.duration = 0;
    request.timeout = 0;

    size_t shortNameEffectiveLen = std::min(ADVERTISING_SHORTNAME_MAX_LEN, shortName.length());
    request.advDataLen = ADVERTISING_MAX_DATALEN - (ADVERTISING_SHORTNAME_MAX_LEN - shortNameEffectiveLen);
    request.scanRspLen = 0;

    request.data[0] = static_cast<uint8_t>(ADVERTISING_UUID_LEN + 1);
    request.data[1] = 0x07; // Incomplete UUID list
    memcpy(&request.data[2], uuid, ADVERTISING_UUID_LEN);

    request.data[2+ADVERTISING_UUID_LEN] = static_cast<uint8_t>(1 + shortNameEffectiveLen);
    request.data[3+ADVERTISING_UUID_LEN] = 0x08;  // Set short name
    memcpy(&request.data[4+ADVERTISING_UUID_LEN], shortName.c_str(), shortNameEffectiveLen);

    if (!HciAdapter::getInstance().sendCommand(request))
    {
	Logger::warn(SSTR << "  + Failed to start advertising with UUID");
	return false;
    }

    return true;
}

from gobbledegook.

xuio avatar xuio commented on June 26, 2024

@stez-mind can you give more detail about the usage of Mgmt::addAdvertising?
It is not working for me. You have to do Mgmt::setAdvertising(0) after, right?

from gobbledegook.

stez-mind avatar stez-mind commented on June 26, 2024

Hi @xuio,
sorry it has been quite a long time since I worked on this.

I just checked my implementation and I was not calling explicitly Mgmt::setAdvertising(0) directly from the C++ sources but I remember that I was doing a few tasks separately with a script calling hcitool.

from gobbledegook.

xuio avatar xuio commented on June 26, 2024

@stez-mind Thanks for answering!

Can you share the context in which you call Mgmt::addAdvertising(...). Thanks!

from gobbledegook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.