Skip to content

Commit

Permalink
net: openthread: Add implementation of TCAT advertisement.
Browse files Browse the repository at this point in the history
Adds implementation of tcat advertisement API.

Signed-off-by: Przemyslaw Bida <[email protected]>
  • Loading branch information
canisLupus1313 committed Jun 7, 2024
1 parent 0aaaa44 commit 41da90d
Showing 1 changed file with 50 additions and 4 deletions.
54 changes: 50 additions & 4 deletions modules/openthread/platform/ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include <zephyr/net/openthread.h>

/* OpenThread BLE driver API */
#include <openthread/error.h>
#include <openthread/platform/ble.h>
#include <openthread/tcat.h>

/* Zephyr Logging */

Expand Down Expand Up @@ -100,13 +102,17 @@ static struct bt_conn_cb conn_callbacks = {.connected = connected,
.le_param_req = le_param_req,
.le_param_updated = le_param_updated};

static const struct bt_data ad[] = {
static uint8_t service_data[OT_TCAT_ADVERTISEMENT_MAX_LEN] = {0};
static const uint8_t service_data_size = ARRAY_SIZE(service_data);

static struct bt_data ad[] = {
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
BT_DATA(BT_DATA_SVC_DATA16, service_data, service_data_size),
};

static const struct bt_data sd[] = {
static struct bt_data sd[] = {
BT_DATA_BYTES(BT_DATA_UUID16_ALL, BT_UUID_16_ENCODE(TOBLE_SERVICE_UUID)),
BT_DATA(BT_DATA_SVC_DATA16, service_data, service_data_size),
};

/* Zephyr BLE Message Queue and Thread */
Expand Down Expand Up @@ -388,12 +394,52 @@ static void bt_ready(int err)
k_sem_give(&ot_plat_ble_init_semaphore); /* BLE stack up an running */
}

void otPlatBleGetLinkCapabilities(otInstance *aInstance,
otBleLinkCapabilities *aBleLinkCapabilities)
{
ARG_UNUSED(aInstance);

aBleLinkCapabilities->mGattNotifications = 1;
aBleLinkCapabilities->mL2CapDirect = 0;
aBleLinkCapabilities->mRsv = 0;
}

bool otPlatBleSupportsMultiRadio(otInstance *aInstance)
{
OT_UNUSED_VARIABLE(aInstance);

return false;
}

otError otPlatBleGetAdvertisementBuffer(otInstance *aInstance, uint8_t **aAdvertisementBuffer)
{
ARG_UNUSED(aInstance);

*aAdvertisementBuffer = service_data;

return OT_ERROR_NONE;
}

otError otPlatBleGapAdvSetData(otInstance *aInstance, uint8_t *aAdvertisementData,
uint16_t aAdvertisementLen)
{
ARG_UNUSED(aInstance);

if (aAdvertisementLen > OT_TCAT_ADVERTISEMENT_MAX_LEN || aAdvertisementData == NULL) {
LOG_ERR("Invalid TCAT Advertisement parameters advlen: %d", aAdvertisementLen);
return OT_ERROR_INVALID_ARGS;
}

ad[1].data_len = (uint8_t)aAdvertisementLen;
sd[1].data_len = (uint8_t)aAdvertisementLen;
return OT_ERROR_NONE;
}

otError otPlatBleGapAdvStart(otInstance *aInstance, uint16_t aInterval)
{
ARG_UNUSED(aInstance);
ARG_UNUSED(aInterval);

/* TO DO advertisement format change */
int err = bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd));

if (err != 0 && err != -EALREADY) {
Expand Down

0 comments on commit 41da90d

Please sign in to comment.