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 Sep 29, 2023
1 parent 9616b92 commit 81f6bbb
Show file tree
Hide file tree
Showing 4 changed files with 535 additions and 0 deletions.
254 changes: 254 additions & 0 deletions nimble/host/include/host/ble_audio_broadcast.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
/*
* 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_broadcast_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;

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

/** Broadcast name */
const uint8_t *name;

/** Broadcast name length */
uint8_t name_len;
};

struct ble_broadcast_update_params {
/** New BLE address to use for advertising */
ble_addr_t *addr;

/** Updated parameters of Extended advertising */
struct ble_gap_ext_adv_params *extended_params;

/** Updated parameters of Periodic advertising */
struct ble_gap_periodic_adv_params *periodic_params;

/** New Broadcast name */
const uint8_t *name;

/** New Broadcast name length */
uint8_t name_len;
};

typedef int ble_audio_broadcast_destroy_fn(struct ble_broadcast_big *big,
void *arg);

/** 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_broadcast_big *big;

/** Broadcast ID */
uint32_t broadcast_id;

/** Broadcast ID */
uint8_t big_id;

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

/**
* @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 base_params Pointer to a `ble_broadcast_base_params`
* structure that defines BIG, extended
* advertising and periodic advertising
* configuration.
* @param config_out Pointer to a `ble_broadcast_base_config`
* structure to return configuration of created
* BASE advertisement.
* @param destroy_cb Optional callback to be called when BASE
* advertisement is destroyed.
* @param 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(struct ble_broadcast_create_params *base_params,
struct ble_broadcast_base_config *config_out,
ble_audio_broadcast_destroy_fn *destroy_cb,
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.
*
* @param 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(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.
*
* @param 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(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 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(struct ble_broadcast_base_config *base_config);

/**
* @brief Update advertisements for given BASE configuration
*
* This function can be used to update extended and periodic advertisements
* for that are used to broadcast with BASE configuration. 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 params Pointer to a `ble_broadcast_update_params`
* structure.
*
* @return 0 on success;
* A non-zero value on failure.
*/
int ble_audio_broadcast_update(struct ble_broadcast_update_params *params);

/** 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 params Pointer to a `ble_broadcast_subgroup_params`
* structure, containing information about new
* subgroup
* @param big Pointer to a `ble_broadcast_big` structure,
* that will be extended by the new subgroup
* @param sub Pointer to a `ble_broadcast_subgroup`
* structure, that will be filled out with
* supplied configuration
*
* @return 0 on success;
* A non-zero value on failure.
*/
int ble_audio_broadcast_build_sub(struct ble_broadcast_subgroup_params params,
struct ble_audio_big *big,
struct ble_audio_subgroup *sub);

/** 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 params Pointer to a `ble_broadcast_bis_params`
* structure, containing information about new
* BIS
* @param sub Pointer to a `ble_broadcast_subgroup` structure,
* that will be extended by the new BIS
* @param bis Pointer to a `ble_broadcast_bis`
* structure, that will be filled out with
* supplied configuration
*
* @return 0 on success;
* A non-zero value on failure.
*/
int ble_audio_broadcast_build_bis(struct ble_broadcast_bis_params params,
struct ble_audio_subgroup *sub,
struct ble_audio_bis *bis);
#endif
139 changes: 139 additions & 0 deletions nimble/host/include/host/ble_audio_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* 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_COMMON_
#define H_BLE_AUDIO_COMMON_

#include "stdint.h"
#include "os/queue.h"

#define BROADCAST_AUDIO_ANNOUNCEMENT_SVC_UUID 0x1852

struct ble_audio_codec_id {
/** Coding Fromat */
uint8_t format;

/** Company ID */
uint16_t company_id;

/** Vendor Specific Codec ID */
uint16_t vendor_specific;
};

struct ble_audio_bis {
/** Pointer to next BIS in subgroup */
STAILQ_ENTRY(ble_audio_bis) next;

/** BIS index */
uint8_t idx;

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

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

typedef int ble_audio_broadcast_sub_free_fn(void *cb_args);

struct ble_audio_subgroup {
/** Pointer to next subgroup in BIG */
STAILQ_ENTRY(ble_audio_subgroup) next;

/** Number of BISes in subgroup */
uint8_t bis_cnt;

/** Codec ID */
struct ble_audio_codec_id codec_id;

/** 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;

/** Link list of BISes */
STAILQ_HEAD(, ble_audio_bis) bises;
};

struct ble_audio_big {
/** Broadcast ID */
uint32_t broadcast_id : 24;

/** Presentation Delay */
uint8_t presentation_delay[3];

/** Number of subgroups in BIG */
uint8_t num_subgroups;

/** Link list of subgroups */
STAILQ_HEAD(, ble_audio_subgroup) subs;
};

struct ble_audio_codec_config_params {
/** Mandatory field, codec sampling frequency. */
uint8_t sampling_freq;

/** Mandatory field, codec frame duration. */
uint8_t frame_duration;

/**
* Optional field, bitfield with mapped Audio Locations.
* Set to 0 to omit in Codec Specific Configuration LTV construction.
*/
uint32_t audio_channel_alloc;

/** Mandatory field, codec frame duration. */
uint16_t octets_per_codec_frame;

/**
* Optional field, codec frame duration.
* Set to 0 to omit in Codec Specific Configuration LTV construction.
*/
uint8_t codec_frame_blocks_per_sdu;
};

/**
* @brief Build Codec Specific Configuration LTV structure
*
* This function packs Codec Specific Configuration settings into LTV format.
*
* @param params Pointer to a `ble_audio_codec_config_params`
* struct that contains Codec Specific
* Configuration.
* @param codec_config_out Pointer to a memory that will be filled with
* Codec Specific Configuration LTV structure.
* Memory size must be sufficient to fit
* expected LTV structure size.
* @param codec_config_out_len Total length of constructed Codec Specific
* Configuration.
*
* @return 0 on success;
* A non-zero value on failure.
*/
int ble_audio_build_codec_config(struct ble_audio_codec_config_params *params,
uint8_t *codec_config_out,
uint8_t codec_config_out_len);
#endif /* H_BLE_AUDIO_COMMON_ */
Loading

0 comments on commit 81f6bbb

Please sign in to comment.