2020-03-30 01:44:20 +02:00
|
|
|
/*
|
|
|
|
* NimBLEUtils.cpp
|
|
|
|
*
|
|
|
|
* Created: on Jan 25 2020
|
|
|
|
* Author H2zero
|
2020-05-14 06:03:56 +02:00
|
|
|
*
|
2020-03-30 01:44:20 +02:00
|
|
|
*/
|
|
|
|
|
2021-09-07 05:14:43 +02:00
|
|
|
#include "nimconfig.h"
|
2020-03-30 01:44:20 +02:00
|
|
|
#if defined(CONFIG_BT_ENABLED)
|
|
|
|
|
2024-11-10 21:31:37 +01:00
|
|
|
# include "NimBLEUtils.h"
|
|
|
|
# include "NimBLEAddress.h"
|
|
|
|
# include "NimBLELog.h"
|
2021-12-29 16:08:25 +01:00
|
|
|
|
2024-11-03 02:00:07 +01:00
|
|
|
# if defined(CONFIG_NIMBLE_CPP_IDF)
|
|
|
|
# include "host/ble_hs.h"
|
|
|
|
# else
|
|
|
|
# include "nimble/nimble/host/include/host/ble_hs.h"
|
|
|
|
# endif
|
|
|
|
|
|
|
|
/**** FIX COMPILATION ****/
|
2024-11-10 21:31:37 +01:00
|
|
|
# undef min
|
|
|
|
# undef max
|
2024-11-03 02:00:07 +01:00
|
|
|
/**************************/
|
|
|
|
|
2024-11-10 21:31:37 +01:00
|
|
|
# include <stdlib.h>
|
|
|
|
# include <climits>
|
2020-05-11 04:26:03 +02:00
|
|
|
|
2024-11-13 21:41:02 +01:00
|
|
|
# if defined INC_FREERTOS_H
|
|
|
|
constexpr uint32_t TASK_BLOCK_BIT = (1 << CONFIG_NIMBLE_CPP_FREERTOS_TASK_BLOCK_BIT);
|
|
|
|
# endif
|
|
|
|
|
2020-05-14 06:03:56 +02:00
|
|
|
static const char* LOG_TAG = "NimBLEUtils";
|
2020-03-30 01:44:20 +02:00
|
|
|
|
2024-11-14 02:09:38 +01:00
|
|
|
/**
|
|
|
|
* @brief Construct a NimBLETaskData instance.
|
|
|
|
* @param [in] pInstance An instance of the class that will be waiting.
|
|
|
|
* @param [in] flags General purpose flags for the caller.
|
|
|
|
* @param [in] buf A buffer for data.
|
|
|
|
*/
|
|
|
|
NimBLETaskData::NimBLETaskData(void* pInstance, int flags, void* buf)
|
|
|
|
: m_pInstance{pInstance},
|
|
|
|
m_flags{flags},
|
|
|
|
m_pBuf{buf}
|
|
|
|
# if defined INC_FREERTOS_H
|
|
|
|
,
|
|
|
|
m_pHandle{xTaskGetCurrentTaskHandle()} {
|
|
|
|
}
|
|
|
|
# else
|
|
|
|
{
|
|
|
|
ble_npl_sem* sem = new ble_npl_sem;
|
|
|
|
if (ble_npl_sem_init(sem, 0) != BLE_NPL_OK) {
|
|
|
|
NIMBLE_LOGE(LOG_TAG, "Failed to init semaphore");
|
|
|
|
delete sem;
|
|
|
|
m_pHandle = nullptr;
|
|
|
|
} else {
|
|
|
|
m_pHandle = sem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Destructor.
|
|
|
|
*/
|
|
|
|
NimBLETaskData::~NimBLETaskData() {
|
|
|
|
# if !defined INC_FREERTOS_H
|
|
|
|
if (m_pHandle != nullptr) {
|
|
|
|
ble_npl_sem_deinit(static_cast<ble_npl_sem*>(m_pHandle));
|
|
|
|
delete static_cast<ble_npl_sem*>(m_pHandle);
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
|
2024-11-10 21:31:37 +01:00
|
|
|
/**
|
|
|
|
* @brief Blocks the calling task until released or timeout.
|
|
|
|
* @param [in] taskData A pointer to the task data structure.
|
|
|
|
* @param [in] timeout The time to wait in milliseconds.
|
|
|
|
* @return True if the task completed, false if the timeout was reached.
|
|
|
|
*/
|
|
|
|
bool NimBLEUtils::taskWait(const NimBLETaskData& taskData, uint32_t timeout) {
|
|
|
|
ble_npl_time_t ticks;
|
|
|
|
if (timeout == BLE_NPL_TIME_FOREVER) {
|
|
|
|
ticks = BLE_NPL_TIME_FOREVER;
|
|
|
|
} else {
|
|
|
|
ble_npl_time_ms_to_ticks(timeout, &ticks);
|
|
|
|
}
|
|
|
|
|
|
|
|
# if defined INC_FREERTOS_H
|
2024-11-13 21:41:02 +01:00
|
|
|
uint32_t notificationValue;
|
|
|
|
xTaskNotifyWait(0, TASK_BLOCK_BIT, ¬ificationValue, 0);
|
|
|
|
if (notificationValue & TASK_BLOCK_BIT) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return xTaskNotifyWait(0, TASK_BLOCK_BIT, nullptr, ticks) == pdTRUE;
|
2024-11-10 21:31:37 +01:00
|
|
|
|
|
|
|
# else
|
2024-11-14 02:09:38 +01:00
|
|
|
return ble_npl_sem_pend(static_cast<ble_npl_sem*>(taskData.m_pHandle), ticks) == BLE_NPL_OK;
|
2024-11-10 21:31:37 +01:00
|
|
|
# endif
|
|
|
|
} // taskWait
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Release a task.
|
|
|
|
* @param [in] taskData A pointer to the task data structure.
|
|
|
|
* @param [in] flags A return value to set in the task data structure.
|
|
|
|
*/
|
|
|
|
void NimBLEUtils::taskRelease(const NimBLETaskData& taskData, int flags) {
|
2024-11-13 21:41:02 +01:00
|
|
|
taskData.m_flags = flags;
|
2024-11-10 21:31:37 +01:00
|
|
|
if (taskData.m_pHandle != nullptr) {
|
|
|
|
# if defined INC_FREERTOS_H
|
2024-11-13 21:41:02 +01:00
|
|
|
xTaskNotify(static_cast<TaskHandle_t>(taskData.m_pHandle), TASK_BLOCK_BIT, eSetBits);
|
2024-11-10 21:31:37 +01:00
|
|
|
# else
|
|
|
|
ble_npl_sem_release(static_cast<ble_npl_sem*>(taskData.m_pHandle));
|
|
|
|
# endif
|
|
|
|
}
|
|
|
|
} // taskRelease
|
|
|
|
|
2020-07-09 03:27:26 +02:00
|
|
|
/**
|
|
|
|
* @brief Converts a return code from the NimBLE stack to a text string.
|
|
|
|
* @param [in] rc The return code to convert.
|
|
|
|
* @return A string representation of the return code.
|
|
|
|
*/
|
2020-03-30 01:44:20 +02:00
|
|
|
const char* NimBLEUtils::returnCodeToString(int rc) {
|
2024-11-10 21:31:37 +01:00
|
|
|
# if defined(CONFIG_NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT)
|
|
|
|
switch (rc) {
|
2020-03-30 01:44:20 +02:00
|
|
|
case 0:
|
|
|
|
return "SUCCESS";
|
|
|
|
case BLE_HS_EAGAIN:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Temporary failure; try again";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_EALREADY:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Operation already in progress or complete";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_EINVAL:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "One or more arguments are invalid";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_EMSGSIZE:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Buffer too small";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_ENOENT:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "No matching entry found";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_ENOMEM:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Not enough memory";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_ENOTCONN:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "No open connection with handle";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_ENOTSUP:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Operation disabled at compile time";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_EAPP:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Application error";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_EBADDATA:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Invalid command from peer";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_EOS:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "OS error";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_ECONTROLLER:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Controller error";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_ETIMEOUT:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Operation timed out";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_EDONE:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Operation completed successfully";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_EBUSY:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Busy";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_EREJECT:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Peer rejected request";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_EUNKNOWN:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Unknown failure";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_EROLE:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Operation requires different role";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_ETIMEOUT_HCI:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "HCI request timed out";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_ENOMEM_EVT:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Controller error; not enough memory";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_ENOADDR:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "No identity address";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_ENOTSYNCED:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Host not synced with controller";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_EAUTHEN:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Insufficient authentication";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_EAUTHOR:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Insufficient authorization";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_EENCRYPT:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Insufficient encryption level";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_EENCRYPT_KEY_SZ:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Insufficient key size";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_ESTORE_CAP:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Storage at capacity";
|
2020-03-30 01:44:20 +02:00
|
|
|
case BLE_HS_ESTORE_FAIL:
|
2024-11-10 21:31:37 +01:00
|
|
|
return "Storage IO error";
|
|
|
|
case BLE_HS_EPREEMPTED:
|
|
|
|
return "Host preempted";
|
|
|
|
case BLE_HS_EDISABLED:
|
|
|
|
return "Host disabled";
|
|
|
|
case BLE_HS_ESTALLED:
|
|
|
|
return "CoC module is stalled";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_INVALID_HANDLE):
|
|
|
|
return "Invalid attribute handle";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_READ_NOT_PERMITTED):
|
|
|
|
return "The attribute cannot be read";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_WRITE_NOT_PERMITTED):
|
|
|
|
return "The attribute cannot be written";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_INVALID_PDU):
|
|
|
|
return "Invalid attribute PDU";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_INSUFFICIENT_AUTHEN):
|
|
|
|
return "Insufficient authentication";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_REQ_NOT_SUPPORTED):
|
|
|
|
return "Unsupported request";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_INVALID_OFFSET):
|
|
|
|
return "Invalid offset";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_INSUFFICIENT_AUTHOR):
|
|
|
|
return "Insufficient authorization";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_PREPARE_QUEUE_FULL):
|
|
|
|
return "Prepare write queue full";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_ATTR_NOT_FOUND):
|
|
|
|
return "Attribute not found";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_ATTR_NOT_LONG):
|
|
|
|
return "Long read not supported";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_INSUFFICIENT_KEY_SZ):
|
|
|
|
return "Insufficient encryption key size";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_INVALID_ATTR_VALUE_LEN):
|
|
|
|
return "Invalid attribute value length";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_UNLIKELY):
|
|
|
|
return "Unlikely attribute error";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_INSUFFICIENT_ENC):
|
|
|
|
return "Insufficient encryption";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_UNSUPPORTED_GROUP):
|
|
|
|
return "Not a supported grouping attribute type";
|
|
|
|
case (BLE_HS_ERR_ATT_BASE + BLE_ATT_ERR_INSUFFICIENT_RES):
|
|
|
|
return "Insufficient Resources";
|
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_UNKNOWN_HCI_CMD):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Unknown HCI Command";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_UNK_CONN_ID):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Unknown Connection Identifier";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_HW_FAIL):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Hardware Failure";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_PAGE_TMO):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Page Timeout";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_AUTH_FAIL):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Authentication Failure";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_PINKEY_MISSING):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "PIN or Key Missing";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_MEM_CAPACITY):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Memory Capacity Exceeded";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_CONN_SPVN_TMO):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Connection Timeout";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_CONN_LIMIT):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Connection Limit Exceeded";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_SYNCH_CONN_LIMIT):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Synchronous Connection Limit To A Device Exceeded";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_ACL_CONN_EXISTS):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "ACL Connection Already Exists";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_CMD_DISALLOWED):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Command Disallowed";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_CONN_REJ_RESOURCES):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Connection Rejected due to Limited Resources";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_CONN_REJ_SECURITY):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Connection Rejected Due To Security Reasons";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_CONN_REJ_BD_ADDR):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Connection Rejected due to Unacceptable BD_ADDR";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_CONN_ACCEPT_TMO):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Connection Accept Timeout Exceeded";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_UNSUPPORTED):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Unsupported Feature or Parameter Value";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_INV_HCI_CMD_PARMS):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Invalid HCI Command Parameters";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_REM_USER_CONN_TERM):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Remote User Terminated Connection";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_RD_CONN_TERM_RESRCS):
|
|
|
|
return "Remote Device Terminated Connection; Low Resources";
|
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_RD_CONN_TERM_PWROFF):
|
|
|
|
return "Remote Device Terminated Connection; Power Off";
|
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_CONN_TERM_LOCAL):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Connection Terminated By Local Host";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_REPEATED_ATTEMPTS):
|
|
|
|
return "Repeated Pairing Attempts";
|
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_NO_PAIRING):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Pairing Not Allowed";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_UNK_LMP):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Unknown LMP PDU";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_UNSUPP_REM_FEATURE):
|
|
|
|
return "Unsupported Remote Feature";
|
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_SCO_OFFSET):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "SCO Offset Rejected";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_SCO_ITVL):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "SCO Interval Rejected";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_SCO_AIR_MODE):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "SCO Air Mode Rejected";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_INV_LMP_LL_PARM):
|
|
|
|
return "Invalid LL Parameters";
|
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_UNSPECIFIED):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Unspecified Error";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_UNSUPP_LMP_LL_PARM):
|
|
|
|
return "Unsupported LL Parameter Value";
|
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_NO_ROLE_CHANGE):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Role Change Not Allowed";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_LMP_LL_RSP_TMO):
|
|
|
|
return "LL Response Timeout";
|
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_LMP_COLLISION):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "LMP Error Transaction Collision";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_LMP_PDU):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "LMP PDU Not Allowed";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_ENCRYPTION_MODE):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Encryption Mode Not Acceptable";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_LINK_KEY_CHANGE):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Link Key cannot be Changed";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_UNSUPP_QOS):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Requested QoS Not Supported";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_INSTANT_PASSED):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Instant Passed";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_UNIT_KEY_PAIRING):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Pairing With Unit Key Not Supported";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_DIFF_TRANS_COLL):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Different Transaction Collision";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_QOS_PARM):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "QoS Unacceptable Parameter";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_QOS_REJECTED):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "QoS Rejected";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_CHAN_CLASS):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Channel Classification Not Supported";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_INSUFFICIENT_SEC):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Insufficient Security";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_PARM_OUT_OF_RANGE):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Parameter Out Of Mandatory Range";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_PENDING_ROLE_SW):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Role Switch Pending";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_RESERVED_SLOT):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Reserved Slot Violation";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_ROLE_SW_FAIL):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Role Switch Failed";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_INQ_RSP_TOO_BIG):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Extended Inquiry Response Too Large";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_SEC_SIMPLE_PAIR):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Secure Simple Pairing Not Supported By Host";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_HOST_BUSY_PAIR):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Host Busy - Pairing";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_CONN_REJ_CHANNEL):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Connection Rejected, No Suitable Channel Found";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_CTLR_BUSY):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Controller Busy";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_CONN_PARMS):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Unacceptable Connection Parameters";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_DIR_ADV_TMO):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Directed Advertising Timeout";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_CONN_TERM_MIC):
|
|
|
|
return "Connection Terminated; MIC Failure";
|
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_CONN_ESTABLISHMENT):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Connection Failed to be Established";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_MAC_CONN_FAIL):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "MAC Connection Failed";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_COARSE_CLK_ADJ):
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Coarse Clock Adjustment Rejected";
|
2024-11-10 21:31:37 +01:00
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_TYPE0_SUBMAP_NDEF):
|
|
|
|
return "Type0 Submap Not Defined";
|
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_UNK_ADV_INDENT):
|
|
|
|
return "Unknown Advertising Identifier";
|
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_LIMIT_REACHED):
|
|
|
|
return "Limit Reached";
|
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_OPERATION_CANCELLED):
|
|
|
|
return "Operation Cancelled by Host";
|
|
|
|
case (BLE_HS_ERR_HCI_BASE + BLE_ERR_PACKET_TOO_LONG):
|
|
|
|
return "Packet Too Long";
|
|
|
|
case (BLE_HS_ERR_L2C_BASE + BLE_L2CAP_SIG_ERR_CMD_NOT_UNDERSTOOD):
|
|
|
|
return "Invalid or unsupported incoming L2CAP sig command";
|
|
|
|
case (BLE_HS_ERR_L2C_BASE + BLE_L2CAP_SIG_ERR_MTU_EXCEEDED):
|
|
|
|
return "Incoming packet too large";
|
|
|
|
case (BLE_HS_ERR_L2C_BASE + BLE_L2CAP_SIG_ERR_INVALID_CID):
|
|
|
|
return "No channel with specified ID";
|
|
|
|
case (BLE_HS_ERR_SM_US_BASE + BLE_SM_ERR_PASSKEY):
|
|
|
|
case (BLE_HS_ERR_SM_PEER_BASE + BLE_SM_ERR_PASSKEY):
|
|
|
|
return "Incorrect passkey or the user cancelled";
|
|
|
|
case (BLE_HS_ERR_SM_US_BASE + BLE_SM_ERR_OOB):
|
|
|
|
case (BLE_HS_ERR_SM_PEER_BASE + BLE_SM_ERR_OOB):
|
|
|
|
return "The OOB data is not available";
|
|
|
|
case (BLE_HS_ERR_SM_US_BASE + BLE_SM_ERR_AUTHREQ):
|
|
|
|
case (BLE_HS_ERR_SM_PEER_BASE + BLE_SM_ERR_AUTHREQ):
|
|
|
|
return "Authentication requirements cannot be met due to IO capabilities";
|
|
|
|
case (BLE_HS_ERR_SM_US_BASE + BLE_SM_ERR_CONFIRM_MISMATCH):
|
|
|
|
case (BLE_HS_ERR_SM_PEER_BASE + BLE_SM_ERR_CONFIRM_MISMATCH):
|
|
|
|
return "The confirm value does not match the calculated compare value";
|
|
|
|
case (BLE_HS_ERR_SM_US_BASE + BLE_SM_ERR_PAIR_NOT_SUPP):
|
|
|
|
case (BLE_HS_ERR_SM_PEER_BASE + BLE_SM_ERR_PAIR_NOT_SUPP):
|
|
|
|
return "Pairing is not supported by the device";
|
|
|
|
case (BLE_HS_ERR_SM_US_BASE + BLE_SM_ERR_ENC_KEY_SZ):
|
|
|
|
case (BLE_HS_ERR_SM_PEER_BASE + BLE_SM_ERR_ENC_KEY_SZ):
|
|
|
|
return "Insufficient encryption key size for this device";
|
|
|
|
case (BLE_HS_ERR_SM_US_BASE + BLE_SM_ERR_CMD_NOT_SUPP):
|
|
|
|
case (BLE_HS_ERR_SM_PEER_BASE + BLE_SM_ERR_CMD_NOT_SUPP):
|
|
|
|
return "The SMP command received is not supported on this device";
|
|
|
|
case (BLE_HS_ERR_SM_US_BASE + BLE_SM_ERR_UNSPECIFIED):
|
|
|
|
case (BLE_HS_ERR_SM_PEER_BASE + BLE_SM_ERR_UNSPECIFIED):
|
|
|
|
return "Pairing failed; unspecified reason";
|
|
|
|
case (BLE_HS_ERR_SM_US_BASE + BLE_SM_ERR_REPEATED):
|
|
|
|
case (BLE_HS_ERR_SM_PEER_BASE + BLE_SM_ERR_REPEATED):
|
|
|
|
return "Repeated pairing attempt";
|
|
|
|
case (BLE_HS_ERR_SM_US_BASE + BLE_SM_ERR_INVAL):
|
|
|
|
case (BLE_HS_ERR_SM_PEER_BASE + BLE_SM_ERR_INVAL):
|
|
|
|
return "Invalid command length or parameter";
|
|
|
|
case (BLE_HS_ERR_SM_US_BASE + BLE_SM_ERR_DHKEY):
|
|
|
|
case (BLE_HS_ERR_SM_PEER_BASE + BLE_SM_ERR_DHKEY):
|
|
|
|
return "DHKey check value received doesn't match";
|
|
|
|
case (BLE_HS_ERR_SM_US_BASE + BLE_SM_ERR_NUMCMP):
|
|
|
|
case (BLE_HS_ERR_SM_PEER_BASE + BLE_SM_ERR_NUMCMP):
|
|
|
|
return "Confirm values do not match";
|
|
|
|
case (BLE_HS_ERR_SM_US_BASE + BLE_SM_ERR_ALREADY):
|
|
|
|
case (BLE_HS_ERR_SM_PEER_BASE + BLE_SM_ERR_ALREADY):
|
|
|
|
return "Pairing already in process";
|
|
|
|
case (BLE_HS_ERR_SM_US_BASE + BLE_SM_ERR_CROSS_TRANS):
|
|
|
|
case (BLE_HS_ERR_SM_PEER_BASE + BLE_SM_ERR_CROSS_TRANS):
|
|
|
|
return "Invalid link key for the LE transport";
|
2020-03-30 01:44:20 +02:00
|
|
|
default:
|
|
|
|
return "Unknown";
|
|
|
|
}
|
2024-11-10 21:31:37 +01:00
|
|
|
# else // #if defined(CONFIG_NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT)
|
2021-12-29 16:08:25 +01:00
|
|
|
(void)rc;
|
2020-05-11 04:26:03 +02:00
|
|
|
return "";
|
2024-11-10 21:31:37 +01:00
|
|
|
# endif // #if defined(CONFIG_NIMBLE_CPP_ENABLE_RETURN_CODE_TEXT)
|
2020-05-14 06:03:56 +02:00
|
|
|
}
|
|
|
|
|
2020-03-30 01:44:20 +02:00
|
|
|
/**
|
2020-07-09 03:27:26 +02:00
|
|
|
* @brief Convert the advertising type flag to a string.
|
|
|
|
* @param advType The type to convert.
|
|
|
|
* @return A string representation of the advertising flags.
|
2020-03-30 01:44:20 +02:00
|
|
|
*/
|
|
|
|
const char* NimBLEUtils::advTypeToString(uint8_t advType) {
|
2024-11-10 21:31:37 +01:00
|
|
|
# if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISEMENT_TYPE_TEXT)
|
|
|
|
switch (advType) {
|
|
|
|
case BLE_HCI_ADV_TYPE_ADV_IND: // 0
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Undirected - Connectable / Scannable";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD: // 1
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Directed High Duty - Connectable";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_HCI_ADV_TYPE_ADV_SCAN_IND: // 2
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Non-Connectable - Scan Response Available";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_HCI_ADV_TYPE_ADV_NONCONN_IND: // 3
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Non-Connectable - No Scan Response";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_LD: // 4
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Directed Low Duty - Connectable";
|
|
|
|
default:
|
|
|
|
return "Unknown flag";
|
|
|
|
}
|
2024-11-10 21:31:37 +01:00
|
|
|
# else // #if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISEMENT_TYPE_TEXT)
|
2021-12-29 16:08:25 +01:00
|
|
|
(void)advType;
|
2020-05-11 04:26:03 +02:00
|
|
|
return "";
|
2024-11-10 21:31:37 +01:00
|
|
|
# endif // #if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISEMENT_TYPE_TEXT)
|
2020-03-30 01:44:20 +02:00
|
|
|
} // adFlagsToString
|
|
|
|
|
|
|
|
/**
|
2020-07-09 03:27:26 +02:00
|
|
|
* @brief Convert a GAP event type to a string representation.
|
2020-03-30 01:44:20 +02:00
|
|
|
* @param [in] eventType The type of event.
|
|
|
|
* @return A string representation of the event type.
|
|
|
|
*/
|
|
|
|
const char* NimBLEUtils::gapEventToString(uint8_t eventType) {
|
2024-11-10 21:31:37 +01:00
|
|
|
# if defined(CONFIG_NIMBLE_CPP_ENABLE_GAP_EVENT_CODE_TEXT)
|
2020-03-30 01:44:20 +02:00
|
|
|
switch (eventType) {
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_CONNECT: // 0
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_CONNECT ";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_DISCONNECT: // 1
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_DISCONNECT";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_CONN_UPDATE: // 3
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_CONN_UPDATE";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_CONN_UPDATE_REQ: // 4
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_CONN_UPDATE_REQ";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_L2CAP_UPDATE_REQ: // 5
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_L2CAP_UPDATE_REQ";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_TERM_FAILURE: // 6
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_TERM_FAILURE";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_DISC: // 7
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_DISC";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_DISC_COMPLETE: // 8
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_DISC_COMPLETE";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_ADV_COMPLETE: // 9
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_ADV_COMPLETE";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_ENC_CHANGE: // 10
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_ENC_CHANGE";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_PASSKEY_ACTION: // 11
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_PASSKEY_ACTION";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_NOTIFY_RX: // 12
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_NOTIFY_RX";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_NOTIFY_TX: // 13
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_NOTIFY_TX";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_SUBSCRIBE: // 14
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_SUBSCRIBE";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_MTU: // 15
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_MTU";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_IDENTITY_RESOLVED: // 16
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_IDENTITY_RESOLVED";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_REPEAT_PAIRING: // 17
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_REPEAT_PAIRING";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_PHY_UPDATE_COMPLETE: // 18
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_PHY_UPDATE_COMPLETE";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_EXT_DISC: // 19
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_EXT_DISC";
|
2024-11-10 21:31:37 +01:00
|
|
|
# ifdef BLE_GAP_EVENT_PERIODIC_SYNC // IDF 4.0 does not support these
|
|
|
|
case BLE_GAP_EVENT_PERIODIC_SYNC: // 20
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_PERIODIC_SYNC";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_PERIODIC_REPORT: // 21
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_PERIODIC_REPORT";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_PERIODIC_SYNC_LOST: // 22
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_PERIODIC_SYNC_LOST";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_SCAN_REQ_RCVD: // 23
|
2020-03-30 01:44:20 +02:00
|
|
|
return "BLE_GAP_EVENT_SCAN_REQ_RCVD";
|
2024-11-10 21:31:37 +01:00
|
|
|
case BLE_GAP_EVENT_PERIODIC_TRANSFER: // 24
|
|
|
|
return "BLE_GAP_EVENT_PERIODIC_TRANSFER";
|
|
|
|
case BLE_GAP_EVENT_PATHLOSS_THRESHOLD: // 25
|
|
|
|
return "BLE_GAP_EVENT_PATHLOSS_THRESHOLD";
|
|
|
|
case BLE_GAP_EVENT_TRANSMIT_POWER: // 26
|
|
|
|
return "BLE_GAP_EVENT_TRANSMIT_POWER";
|
|
|
|
case BLE_GAP_EVENT_SUBRATE_CHANGE: // 27
|
|
|
|
return "BLE_GAP_EVENT_SUBRATE_CHANGE";
|
|
|
|
case BLE_GAP_EVENT_VS_HCI: // 28
|
|
|
|
return "BLE_GAP_EVENT_VS_HCI";
|
|
|
|
case BLE_GAP_EVENT_REATTEMPT_COUNT: // 29
|
|
|
|
return "BLE_GAP_EVENT_REATTEMPT_COUNT";
|
|
|
|
case BLE_GAP_EVENT_AUTHORIZE: // 30
|
|
|
|
return "BLE_GAP_EVENT_AUTHORIZE";
|
|
|
|
case BLE_GAP_EVENT_TEST_UPDATE: // 31
|
|
|
|
return "BLE_GAP_EVENT_TEST_UPDATE";
|
|
|
|
case BLE_GAP_EVENT_DATA_LEN_CHG: // 32
|
|
|
|
return "BLE_GAP_EVENT_DATA_LEN_CHG";
|
|
|
|
case BLE_GAP_EVENT_LINK_ESTAB: // 33
|
|
|
|
return "BLE_GAP_EVENT_LINK_ESTAB";
|
|
|
|
# endif
|
2020-03-30 01:44:20 +02:00
|
|
|
default:
|
2024-11-10 21:31:37 +01:00
|
|
|
NIMBLE_LOGD(LOG_TAG, "Unknown event type %d 0x%.2x", eventType, eventType);
|
2020-03-30 01:44:20 +02:00
|
|
|
return "Unknown event type";
|
|
|
|
}
|
2024-11-10 21:31:37 +01:00
|
|
|
# else // #if defined(CONFIG_NIMBLE_CPP_ENABLE_GAP_EVENT_CODE_TEXT)
|
2021-12-29 16:08:25 +01:00
|
|
|
(void)eventType;
|
2020-05-11 04:26:03 +02:00
|
|
|
return "";
|
2024-11-10 21:31:37 +01:00
|
|
|
# endif // #if defined(CONFIG_NIMBLE_CPP_ENABLE_GAP_EVENT_CODE_TEXT)
|
2020-03-30 01:44:20 +02:00
|
|
|
} // gapEventToString
|
|
|
|
|
2024-11-10 21:31:37 +01:00
|
|
|
/**
|
|
|
|
* @brief Create a hexadecimal string representation of the input data.
|
|
|
|
* @param [in] source The start of the binary data.
|
|
|
|
* @param [in] length The length of the data to convert.
|
|
|
|
* @return A string representation of the data.
|
|
|
|
*/
|
|
|
|
std::string NimBLEUtils::dataToHexString(const uint8_t* source, uint8_t length) {
|
2024-11-13 16:40:08 +01:00
|
|
|
constexpr char hexmap[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
|
|
|
std::string str{};
|
2024-11-14 16:21:11 +01:00
|
|
|
str.resize(length << 1);
|
2024-11-10 21:31:37 +01:00
|
|
|
|
|
|
|
for (uint8_t i = 0; i < length; i++) {
|
2024-11-13 16:40:08 +01:00
|
|
|
str[2 * i] = hexmap[(source[i] & 0xF0) >> 4];
|
|
|
|
str[2 * i + 1] = hexmap[source[i] & 0x0F];
|
2024-11-10 21:31:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
2024-11-13 16:40:08 +01:00
|
|
|
} // dataToHexString
|
2024-11-10 21:31:37 +01:00
|
|
|
|
2024-11-03 00:56:23 +01:00
|
|
|
/**
|
|
|
|
* @brief Generate a random BLE address.
|
|
|
|
* @param [in] nrpa True to generate a non-resolvable private address,
|
|
|
|
* false to generate a random static address
|
|
|
|
* @return The generated address or a NULL address if there was an error.
|
|
|
|
*/
|
|
|
|
NimBLEAddress NimBLEUtils::generateAddr(bool nrpa) {
|
|
|
|
ble_addr_t addr{};
|
2024-11-10 21:31:37 +01:00
|
|
|
int rc = ble_hs_id_gen_rnd(nrpa, &addr);
|
2024-11-03 00:56:23 +01:00
|
|
|
if (rc != 0) {
|
|
|
|
NIMBLE_LOGE(LOG_TAG, "Generate address failed, rc=%d", rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NimBLEAddress{addr};
|
|
|
|
} // generateAddr
|
|
|
|
|
2024-11-10 21:31:37 +01:00
|
|
|
#endif // CONFIG_BT_ENABLED
|