Skip to content

Commit

Permalink
Option to advertise service UUID in main ble adv packet (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
ojousima authored Jan 31, 2024
1 parent c84cf1c commit 2555fc5
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 12 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/sonar-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ jobs:
with:
submodules: recursive

- name: Set up Sonar Scanner 4.40
run: |
export SONAR_SCANNER_VERSION=4.4.0.2170
export SONAR_SCANNER_HOME=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux
curl --create-dirs -sSLo $HOME/.sonar/sonar-scanner.zip https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux.zip
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
echo "$SONAR_SCANNER_HOME/bin" >> $GITHUB_PATH
curl --create-dirs -sSLo $HOME/.sonar/build-wrapper-linux-x86.zip https://sonarcloud.io/static/cpp/build-wrapper-linux-x86.zip
unzip -o $HOME/.sonar/build-wrapper-linux-x86.zip -d $HOME/.sonar/
echo "$HOME/.sonar/build-wrapper-linux-x86" >> $GITHUB_PATH
# Setup java 17 to be default (sonar-scanner requirement as of 5.x)
- uses: actions/setup-java@v3
with:
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'

- name: Install sonar-scanner and build-wrapper
uses: sonarsource/sonarcloud-github-c-cpp@v2

- name: Download Nordic SDK
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,34 @@ rd_status_t ri_adv_channels_enable (const ri_radio_channels_t channel);
* @retval 0 if argument is NULL of manufacturer ID not found
* @return BLE Manufacturer ID, e.g. 0x0499 for Ruuvi Innovation
*/

uint16_t ri_adv_parse_manuid (uint8_t * const data,
const size_t data_length);

/**
* @brief Set to true to enable advertising 16-bit service UUID in primary advertisement
* packet.
*
* Bluetooth Service UUID lets scanner apps note that your firmware is providing a specific
* service over BLE GATT. Be sure to configure @ref ri_adv_set_service_uuid, otherwise
* your program violates Bluetooth license terms. You must have the license to use the
* configured UUID.
*
* When enabled, the field takes 3 bytes of space in advertisement.
*
* @param[in] enable_uuid true to enable Service UUID advertisement, false to disable.
*/
void ri_adv_enable_uuid (const bool enable_uuid);

/**
* @brief Configure Bluetooth GATT Service UUID to advertise in primary advertisement packet.
*
* Bluetooth Service UUID lets scanner apps note that your firmware is providing a specific
* service over BLE GATT. Be sure to enable @ref ri_adv_enable_uuid.
*
* When enabled, the field takes 3 bytes of space in advertisement.
*
* @param[in] uuid 16-bit UUID to advertise, e.g. 0xFC98 for "Ruuvi Innovations Sensor Data"
*/
void ri_adv_set_service_uuid (const uint16_t uuid);

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ static uint8_t m_adv_handle = BLE_GAP_ADV_SET_HANDLE_NOT_SET;
static bool m_advertisement_is_init = false;
/** @brief Flag for advertising in process **/
static bool m_advertising = false;
/** @brief flag for including Ruuvi Sensor data service UUID in the advertisement **/
static bool m_include_service_uuid = false;
/** @brief 16-bit Bluetooth Service UUID to advertise, Ruuvi's UUID by default. */
static uint16_t m_service_uuid = 0xFC98;

/**< Universally unique service identifier of Nordic UART Service */
#if RUUVI_NRF5_SDK15_GATT_ENABLED
Expand Down Expand Up @@ -301,6 +305,11 @@ static rd_status_t format_adv (const ri_comm_message_t * const p_message,
| BLE_GAP_ADV_FLAG_LE_GENERAL_DISC_MODE;
// Build manufacturer specific data
ble_advdata_manuf_data_t manuf_specific_data;
// Build UUID data
ble_uuid_t m_adv_uuids[] =
{
{m_service_uuid, BLE_UUID_TYPE_BLE}
};
// Preserve const of data passed to us.
uint8_t manufacturer_data[RI_COMM_MESSAGE_MAX_LENGTH];
memcpy (manufacturer_data, p_message->data, p_message->data_length);
Expand All @@ -311,6 +320,12 @@ static rd_status_t format_adv (const ri_comm_message_t * const p_message,
advdata.flags = flags;
advdata.p_manuf_specific_data = &manuf_specific_data;

if (m_include_service_uuid)
{
advdata.uuids_more_available.p_uuids = m_adv_uuids;
advdata.uuids_more_available.uuid_cnt = 1;
}

// If manufacturer data is not set, assign "UNKNOWN"
if (0 == m_manufacturer_id)
{
Expand Down Expand Up @@ -789,4 +804,14 @@ uint16_t ri_adv_parse_manuid (uint8_t * const data,
}
}

void ri_adv_enable_uuid (const bool enable_uuid)
{
m_include_service_uuid = enable_uuid;
}

void ri_adv_set_service_uuid (const uint16_t uuid)
{
m_service_uuid = uuid;
}

#endif
2 changes: 1 addition & 1 deletion src/ruuvi_driver_enabled_modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#define RUUVI_DRIVER_ENABLED_MODULES_H

/** @brief SemVer string, must match latest tag. */
#define RUUVI_DRIVERS_SEMVER "3.9.3"
#define RUUVI_DRIVERS_SEMVER "3.10.0"

#ifdef CEEDLING
# define ENABLE_DEFAULT 1
Expand Down

0 comments on commit 2555fc5

Please sign in to comment.