Skip to content

Commit

Permalink
nimble/host: broadcast and Auracast API proposal
Browse files Browse the repository at this point in the history
This is proposal of API that could be used to create BASE configuration manage\
its broadcast (setup extended advertising, periodic advertising and
BASE advertisements, stop, resume, terminate and modify them)
  • Loading branch information
KKopyscinski committed Oct 3, 2023
1 parent 9616b92 commit b5e0bab
Show file tree
Hide file tree
Showing 4 changed files with 579 additions and 0 deletions.
247 changes: 247 additions & 0 deletions nimble/host/include/host/ble_audio_broadcast.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

#ifndef H_BLE_AUDIO_BROADCAST_
#define H_BLE_AUDIO_BROADCAST_

#include <stdint.h>
#include "host/ble_gap.h"
#include "host/ble_iso.h"
#include "host/ble_audio_common.h"

struct ble_broadcast_create_params {
/** BIG to broadcast */
struct ble_audio_big *big;

/** BLE address to use for advertising */
ble_addr_t *addr;

/** Parameters used to configure Extended advertising */
struct ble_gap_ext_adv_params *extended_params;

/** Parameters used to configure Periodic advertising */
struct ble_gap_periodic_adv_params *periodic_params;

/** Broadcast name - null terminated.
* Set NULL to not include in advertising
*/
const char *name;

/** Advertising instance */
uint8_t adv_instance;

/** BIG parameters */
struct ble_iso_big_params *big_params;

/** Additional data to include in Extended Advertising */
uint8_t *svc_data;
};

typedef int ble_audio_broadcast_destroy_fn(struct ble_audio_big *big,
void *args);

/** BASE configuration describing broadcast advertisement */
struct ble_broadcast_base_config {
/** Advertising instance used by broadcast */
uint8_t adv_instance;

/** Pointer to BIG configuration */
struct ble_audio_big *big;

/** BIG parameters */
struct ble_iso_big_params *big_params;

/**
* Optional callback associated with broadcasting instance, called on
* destroying broadcast
*/
ble_audio_broadcast_destroy_fn *destroy_cb;

/** Pointer to args for `destroy_cb` */
void *args;
};

/**
* @brief Create Broadcast Audio Source Endpoint and configure advertising
* instance
*
* This function configures advertising instance for extended and periodic
* advertisements to be ready for broadcast with BASE configuration.
*
* @param[in] params Pointer to a `ble_broadcast_base_params`
* structure that defines BIG, extended
* advertising and periodic advertising
* configuration.
* @param[out] config_out Pointer to a `ble_broadcast_base_config`
* structure to return configuration of created
* BASE advertisement.
* @param[in] destroy_cb Optional callback to be called when BASE
* advertisement is destroyed.
* @param[in] args Optional arguments to be passed to `destroy_cb`
* @param[in] gap_cb GAP event callback to be associated with BASE
* advertisement.
*
* @return 0 on success;
* A non-zero value on failure.
*/
int ble_audio_broadcast_create(const struct ble_broadcast_create_params
*params,
struct ble_broadcast_base_config *config_out,
ble_audio_broadcast_destroy_fn *destroy_cb,
const void *args,
ble_gap_event_fn *gap_cb);

/**
* @brief Start advertisements for given BASE configuration
*
* This function starts BASE advertisement on by enabling extended and periodic
* advertising and creates BIG for this instance.
*
* @param[in] base_config Pointer to a `ble_broadcast_base_config`
* struct that shall be used for broadcast.
*
* @return 0 on success;
* A non-zero value on failure.
*/
int ble_audio_broadcast_start(const struct ble_broadcast_base_config
*base_config);

/**
* @brief Stop advertisements for given BASE configuration
*
* This function stops BASE advertisement by disabling extended and periodic
* advertising. Advertising instance is still configured and ready for resume.
* BIG will be terminated.
*
* @param[in] base_config Pointer to a `ble_broadcast_base_config`
* struct that broadcast shall be stopped for.
*
* @return 0 on success;
* A non-zero value on failure.
*/
int ble_audio_broadcast_stop(const struct ble_broadcast_base_config
*base_config);

/**
* @brief Destroy advertisements for given BASE configuration
*
* This function stops BASE advertisement by disabling extended and periodic
* advertising and terminates them. After return advertising instance is free
* and must be configured again for future advertisements.
*
* @param[in] base_config Pointer to a `ble_broadcast_base_config`
* struct that broadcast shall be terminated for.
*
* @return 0 on success;
* A non-zero value on failure.
*/
int ble_audio_broadcast_destroy(const struct ble_broadcast_base_config *base_config);

/**
* @brief Update advertisements for given BASE configuration
*
* This function can be used to update extended advertisements. This function
* cannot be used to update BASE configuration itself, because BIG cannot be
* changed during it's lifetime. To modify BASE configuration destroy it using
* `ble_audio_broadcast_destroy` and recreate with `ble_audio_broadcast_create`
*
* @param[in] svc_data Pointer to additional service data for
* broadcast advertisement
* @return 0 on success;
* A non-zero value on failure.
*/
int ble_audio_broadcast_update(const uint8_t *svc_data);

/** BIG Subgroup parameters */
struct ble_broadcast_subgroup_params {
/** Subgroup level Codec information */
struct ble_audio_codec_id *codec_info;

/** Subgroup level Codec Specific Configuration */
uint8_t *codec_spec_config;

/** Subgroup level Codec Specific Configuration length */
uint8_t codec_spec_config_len;

/** Subgroup Metadata */
uint8_t *metadata;

/** Subgroup Metadata length*/
uint8_t metadata_len;
};

/**
* @brief Build BIG subgroup structure
*
* This is a helper function can be used to fill out `ble_broadcast_subgroup`
* structure. Created subgroup extends subgroup list in provided BIG.
* This function increases `num_subgroups` in BIG structure.
*
* @param[in] big Pointer to a `ble_audio_big` structure,
* that will be extended by the new subgroup
* @param[in] sub Pointer to a `ble_broadcast_subgroup`
* structure, that will be filled out with
* supplied configuration
* @param[in] params Pointer to a `ble_broadcast_subgroup_params`
* structure, containing information about new
* subgroup
*
* @return 0 on success;
* A non-zero value on failure.
*/
int ble_audio_broadcast_build_sub(const struct ble_audio_big *big,
const struct ble_audio_subgroup *sub,
const struct ble_broadcast_subgroup_params
*params);

/** BIS parameters */
struct ble_broadcast_bis_params {
/** BIS index */
uint8_t idx;

/** BIS level Codec Specific Configuration */
uint8_t *codec_spec_config;

/** BIS level Codec Specific Configuration length */
uint8_t codec_spec_config_len;
};

/**
* @brief Build BIS structure
*
* This is a helper function can be used to fill out `ble_broadcast_bis`
* structure. Created BIS extends BIS list in provided subgroup.
* This function increases `bis_cnt` in subgroup structure.
*
* @param[in] sub Pointer to a `ble_broadcast_subgroup` structure,
* that will be extended by the new BIS
* @param[in] bis Pointer to a `ble_broadcast_bis`
* structure, that will be filled out with
* supplied configuration
* @param[in] params Pointer to a `ble_broadcast_bis_params`
* structure, containing information about new
* BIS
*
* @return 0 on success;
* A non-zero value on failure.
*/
int ble_audio_broadcast_build_bis(struct ble_audio_subgroup *sub,
struct ble_audio_bis *bis,
struct ble_broadcast_bis_params params);
#endif
Loading

0 comments on commit b5e0bab

Please sign in to comment.