mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
pkg/nimble/contrib: add utility to convert to BLE HCI phy enum
This commit is contained in:
parent
fc616a9916
commit
439cf969b9
@ -128,26 +128,6 @@ void nimble_autoadv_set_gap_cb(ble_gap_event_fn *cb, void *cb_arg)
|
||||
}
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL_BLE_EXT_ADV
|
||||
static int _get_phy_hci(uint8_t mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case NIMBLE_PHY_1M:
|
||||
return BLE_HCI_LE_PHY_1M;
|
||||
#if IS_USED(MODULE_NIMBLE_PHY_2MBIT)
|
||||
case NIMBLE_PHY_2M:
|
||||
return BLE_HCI_LE_PHY_2M;
|
||||
#endif
|
||||
#if IS_USED(MODULE_NIMBLE_PHY_CODED)
|
||||
case NIMBLE_PHY_CODED:
|
||||
return BLE_HCI_LE_PHY_CODED;
|
||||
#endif
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void nimble_autoadv_start(ble_addr_t *addr)
|
||||
{
|
||||
int rc;
|
||||
@ -172,8 +152,8 @@ void nimble_autoadv_start(ble_addr_t *addr)
|
||||
.own_addr_type = _cfg.own_addr_type,
|
||||
.peer = *addr,
|
||||
.filter_policy = _cfg.filter_policy,
|
||||
.primary_phy = _get_phy_hci(_cfg.phy),
|
||||
.secondary_phy = _get_phy_hci(_cfg.phy),
|
||||
.primary_phy = nimble_riot_get_phy_hci(_cfg.phy),
|
||||
.secondary_phy = nimble_riot_get_phy_hci(_cfg.phy),
|
||||
.tx_power = _cfg.tx_power,
|
||||
.sid = CONFIG_NIMBLE_AUTOADV_INSTANCE,
|
||||
};
|
||||
|
@ -93,6 +93,15 @@ extern uint8_t nimble_riot_own_addr_type;
|
||||
*/
|
||||
void nimble_riot_init(void);
|
||||
|
||||
/**
|
||||
* @brief Converts BLE PHY mode to BLE HCI PHY
|
||||
*
|
||||
* @param[in] mode ble phy mode to convert
|
||||
*/
|
||||
#if MYNEWT_VAL_BLE_EXT_ADV
|
||||
int nimble_riot_get_phy_hci(uint8_t mode);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -197,3 +197,23 @@ void nimble_riot_init(void)
|
||||
assert(res == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL_BLE_EXT_ADV
|
||||
int nimble_riot_get_phy_hci(uint8_t mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case NIMBLE_PHY_1M:
|
||||
return BLE_HCI_LE_PHY_1M;
|
||||
#if IS_USED(MODULE_NIMBLE_PHY_2MBIT)
|
||||
case NIMBLE_PHY_2M:
|
||||
return BLE_HCI_LE_PHY_2M;
|
||||
#endif
|
||||
#if IS_USED(MODULE_NIMBLE_PHY_CODED)
|
||||
case NIMBLE_PHY_CODED:
|
||||
return BLE_HCI_LE_PHY_CODED;
|
||||
#endif
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -684,26 +684,6 @@ int nimble_netif_close(int handle)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL_BLE_EXT_ADV
|
||||
static int _get_phy_hci(uint8_t mode)
|
||||
{
|
||||
switch (mode) {
|
||||
case NIMBLE_PHY_1M:
|
||||
return BLE_HCI_LE_PHY_1M;
|
||||
#if IS_USED(MODULE_NIMBLE_PHY_2MBIT)
|
||||
case NIMBLE_PHY_2M:
|
||||
return BLE_HCI_LE_PHY_2M;
|
||||
#endif
|
||||
#if IS_USED(MODULE_NIMBLE_PHY_CODED)
|
||||
case NIMBLE_PHY_CODED:
|
||||
return BLE_HCI_LE_PHY_CODED;
|
||||
#endif
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static int _accept(const uint8_t *ad, size_t ad_len, const ble_addr_t *addr,
|
||||
const nimble_netif_accept_cfg_t *params)
|
||||
{
|
||||
@ -730,8 +710,8 @@ static int _accept(const uint8_t *ad, size_t ad_len, const ble_addr_t *addr,
|
||||
memset(&p, 0, sizeof(p));
|
||||
|
||||
/* figure out PHY modes */
|
||||
int phy_pri = _get_phy_hci(params->primary_phy);
|
||||
int phy_sec = _get_phy_hci(params->secondary_phy);
|
||||
int phy_pri = nimble_riot_get_phy_hci(params->primary_phy);
|
||||
int phy_sec = nimble_riot_get_phy_hci(params->secondary_phy);
|
||||
if ((phy_pri < 0) || (phy_sec < 0)) {
|
||||
nimble_netif_conn_free(handle, NULL);
|
||||
return -EINVAL;
|
||||
|
Loading…
Reference in New Issue
Block a user