Skip to content

Commit

Permalink
BLE: Cleanup enum duplicates in gap/Types.h
Browse files Browse the repository at this point in the history
  • Loading branch information
pan- committed Nov 26, 2018
1 parent 884d870 commit 78d4a9b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 56 deletions.
4 changes: 2 additions & 2 deletions features/FEATURE_BLE/ble/gap/AdvertisingParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class AdvertisingParameters {
* @note If value in input are out of range, they will be normalized.
*/
AdvertisingParameters(
advertising_type_t advType = advertising_type_t::ADV_CONNECTABLE_UNDIRECTED,
advertising_type_t advType = advertising_type_t::CONNECTABLE_UNDIRECTED,
adv_interval_t minInterval = adv_interval_t(DEFAULT_ADVERTISING_INTERVAL_MIN),
adv_interval_t maxInterval = adv_interval_t(DEFAULT_ADVERTISING_INTERVAL_MAX)
) :
Expand All @@ -151,7 +151,7 @@ class AdvertisingParameters {
_includeHeaderTxPower(false)
{
/* Min interval is slightly larger than in other modes. */
if (_advType == advertising_type_t::ADV_NON_CONNECTABLE_UNDIRECTED) {
if (_advType == advertising_type_t::NON_CONNECTABLE_UNDIRECTED) {
_minInterval = adv_interval_t(std::max(_minInterval.value(), GAP_ADV_PARAMS_INTERVAL_MIN_NONCON));
_maxInterval = adv_interval_t(std::max(_maxInterval.value(), GAP_ADV_PARAMS_INTERVAL_MIN_NONCON));
}
Expand Down
60 changes: 22 additions & 38 deletions features/FEATURE_BLE/ble/gap/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,29 @@ typedef Duration<uint16_t, 1250, Range<0x06, 0x0C80> > conn_interval_t;
*
* @note this time should be no larger than (1 + ConnLatency) * ConnIntervalMax * 2
*/
typedef Duration<uint16_t, 10000, Range<0x0A, 0x0C80> > supervision_timeout_t;
typedef Duration<uint16_t, 10000, Range<0x0A, 0x0C80> > supervision_timeout_t;

/**
* Duration of a connection event.
*
* The duration is in unit of 625µs and ranges from 0x0 to 0xFFFF .
*/
typedef Duration<uint16_t, 625, Range< 0, 0xFFFF> > conn_event_length_t;
typedef Duration<uint16_t, 625, Range<0, 0xFFFF> > conn_event_length_t;

/**
* Time after which a periodic sync link is considered loss if the receiver hasn't
* receive anything from the advertiser.
*
* The duration is in unit of 10 milliseconds and ranges from 0x0A to 0x4000.
*/
typedef Duration<uint16_t, 10000, Range<0x0A, 0x4000> > sync_timeout_t;
typedef Duration<uint16_t, 10000, Range<0x0A, 0x4000> > sync_timeout_t;

/**
* Interval between two periodic advertsising events.
*
* The duration is in unit of 1.250ms and ranges from 0x06 to 0xFFFF.
*/
typedef Duration<uint16_t, 1250, Range<0x06, 0xFFFF> > periodic_interval_t;
typedef Duration<uint16_t, 1250, Range<0x06, 0xFFFF> > periodic_interval_t;

/**
* Number of connection events that can be skipped by the slave.
Expand Down Expand Up @@ -155,38 +155,42 @@ struct advertising_type_t : SafeEnum<advertising_type_t, uint8_t> {
*
* @see Vol 3, Part C, Section 9.3.4 and Vol 6, Part B, Section 2.3.1.1.
*/
ADV_CONNECTABLE_UNDIRECTED = 0x00,
ADV_IND = 0x00,
CONNECTABLE_UNDIRECTED = 0x00,

/**
* Device is connectable and expects connection from a specific peer.
* (3.75 ms or smaller Advertising Interval)
* @see Vol 3, Part C, Section 9.3.3 and Vol 6, Part B, Section 2.3.1.2.
*/
ADV_CONNECTABLE_DIRECTED = 0x01,
ADV_DIRECT_IND = 0x01,
CONNECTABLE_DIRECTED = 0x01,

/**
* Device is scannable but not connectable.
*
* @see Vol 6, Part B, Section 2.3.1.4.
*/
ADV_SCANNABLE_UNDIRECTED = 0x02,
ADV_SCAN_IND = 0x02,
SCANNABLE_UNDIRECTED = 0x02,

/**
* Device is not connectable and not scannable.
*
* @see Vol 3, Part C, Section 9.3.2 and Vol 6, Part B, Section 2.3.1.3.
*/
ADV_NON_CONNECTABLE_UNDIRECTED = 0x03,
ADV_NONCONN_IND = 0x03,
NON_CONNECTABLE_UNDIRECTED = 0x03,

/**
* Device is connectable and expects connection from a specific peer (sent at long user set intervals).
*/
ADV_CONNECTABLE_DIRECTED_LOW_DUTY = 0x04,
CONNECTABLE_DIRECTED_LOW_DUTY = 0x04,

#if !defined(DOXYGEN_ONLY)
// used by the PAL; naming in line with the the spec.
ADV_IND = 0x00,
ADV_DIRECT_IND = 0x01,
ADV_SCAN_IND = 0x02,
ADV_NONCONN_IND = 0x03,
ADV_DIRECT_IND_LOW_DUTY_CYCLE = 0x04
#endif
};

/**
Expand Down Expand Up @@ -329,7 +333,7 @@ struct advertising_event_t {
*/
bool complete() const
{
return data_status().value() == advertising_data_status_t::COMPLETE;
return data_status() == advertising_data_status_t::COMPLETE;
}

/** Is there more data coming.
Expand All @@ -338,7 +342,7 @@ struct advertising_event_t {
*/
bool more_data_to_come() const
{
return data_status().value() == advertising_data_status_t::INCOMPLETE_MORE_DATA;
return data_status() == advertising_data_status_t::INCOMPLETE_MORE_DATA;
}

/** Is the payload truncated.
Expand All @@ -347,7 +351,7 @@ struct advertising_event_t {
*/
bool truncated() const
{
return data_status().value() == advertising_data_status_t::INCOMPLETE_DATA_TRUNCATED;
return data_status() == advertising_data_status_t::INCOMPLETE_DATA_TRUNCATED;
}

private:
Expand Down Expand Up @@ -535,13 +539,11 @@ struct own_address_type_t : SafeEnum<own_address_type_t, uint8_t> {
/**
* Use the public device address.
*/
PUBLIC_ADDRESS = 0x00,
PUBLIC = 0x00,

/**
* Use the random device address.
*/
RANDOM_ADDRESS = 0x01,
RANDOM = 0x01,

/**
Expand Down Expand Up @@ -577,10 +579,7 @@ struct target_peer_address_type_t : SafeEnum<target_peer_address_type_t, uint8_t
/// enumeration of target_peer_address_type_t values.
enum type {
PUBLIC = 0x00, /**< Public Device Address or Public Identity Address. */
PUBLIC_ADDRESS = 0x00,

RANDOM = 0x01, /**< Random Device Address or Random (static) Identity Address. */
RANDOM_ADDRESS = 0x01
};

/**
Expand Down Expand Up @@ -708,11 +707,6 @@ struct connection_role_t : SafeEnum<connection_role_t, uint8_t> {
*/
CENTRAL = 0x00,

/**
* @see CENTRAL
*/
MASTER = 0x00,

/**
* Peripheral Role.
*
Expand All @@ -721,12 +715,7 @@ struct connection_role_t : SafeEnum<connection_role_t, uint8_t> {
*
* @note A peripheral is a broadcaster.
*/
PERIPHERAL = 0x01,

/**
* @see PERIPHERAL
*/
SLAVE = 0x01
PERIPHERAL = 0x01
};

/**
Expand Down Expand Up @@ -761,25 +750,21 @@ struct local_disconnection_reason_t : SafeEnum<local_disconnection_reason_t, uin
* GAP or GATT failed to authenticate the peer.
*/
AUTHENTICATION_FAILURE = 0x05,
AUTHENTICATION_FAILLURE = 0x05,

/**
* Connection terminated by the user.
*/
USER_TERMINATION = 0x13,
REMOTE_USER_TERMINATED_CONNECTION = 0x13,

/**
* Connection termination due to low resources.
*/
LOW_RESOURCES = 0x14,
REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_LOW_RESOURCES = 0x14,

/**
* Connection termination due to power off.
*/
POWER_OFF = 0x15,
REMOTE_DEVICE_TERMINATED_CONNECTION_DUE_TO_POWER_OFF = 0x15,

/**
* Remote feature not supported
Expand All @@ -794,7 +779,6 @@ struct local_disconnection_reason_t : SafeEnum<local_disconnection_reason_t, uin
/**
* Connection parameters were unacceptable.
*/
CONN_INTERVAL_UNACCEPTABLE = 0x3B,
UNACCEPTABLE_CONNECTION_PARAMETERS = 0x3B
};

Expand Down Expand Up @@ -849,7 +833,7 @@ struct disconnection_reason_t : SafeEnum<disconnection_reason_t, uint8_t> {
/**
* Connection parameters were unacceptable.
*/
CONN_INTERVAL_UNACCEPTABLE = 0x3B
UNACCEPTABLE_CONNECTION_PARAMETERS = 0x3B
};

/**
Expand Down
2 changes: 1 addition & 1 deletion features/FEATURE_BLE/ble/pal/GapEvents.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ struct GapConnectionCompleteEvent : public GapEvent {
connection_handle(connection_handle),
role(role),
peer_address_type(
peer_address_type == advertising_peer_address_type_t::PUBLIC_ADDRESS ?
peer_address_type == advertising_peer_address_type_t::PUBLIC ?
peer_address_type_t::PUBLIC :
peer_address_type_t::RANDOM
),
Expand Down
20 changes: 10 additions & 10 deletions features/FEATURE_BLE/source/generic/GenericGap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ ble_error_t GenericGap::startRadioScan(const GapScanningParams &scanningParams)

pal::own_address_type_t own_address_type = get_own_address_type(CENTRAL_SCAN /* central, can use non resolvable address for scan requests */);

if (_privacy_enabled && (own_address_type == pal::own_address_type_t::RANDOM_ADDRESS)) {
if (_privacy_enabled && (own_address_type == pal::own_address_type_t::RANDOM)) {
// Use non-resolvable static random address
set_random_address_rotation(true);
}
Expand Down Expand Up @@ -1227,7 +1227,7 @@ ble_error_t GenericGap::startAdvertising(const GapAdvertisingParams &params)

pal::own_address_type_t own_address_type = get_own_address_type(address_use_type);

if (_privacy_enabled && (own_address_type == pal::own_address_type_t::RANDOM_ADDRESS)) {
if (_privacy_enabled && (own_address_type == pal::own_address_type_t::RANDOM)) {
// Use non-resolvable static random address
set_random_address_rotation(true);
}
Expand All @@ -1243,7 +1243,7 @@ ble_error_t GenericGap::startAdvertising(const GapAdvertisingParams &params)
/* advertising_interval_max */ params.getIntervalInADVUnits(),
(pal::advertising_type_t::type) params.getAdvertisingType(),
own_address_type,
pal::advertising_peer_address_type_t::PUBLIC_ADDRESS,
pal::advertising_peer_address_type_t::PUBLIC,
ble::address_t(),
pal::advertising_channel_map_t::ALL_ADVERTISING_CHANNELS,
_advertising_filter_policy
Expand Down Expand Up @@ -1473,7 +1473,7 @@ BLE_DEPRECATED_API_USE_END()
bool needs_authentication = false;

if (_privacy_enabled &&
e.role.value() == e.role.SLAVE &&
e.role.value() == e.role.PERIPHERAL &&
e.peer_address_type == peer_address_type_t::RANDOM
) {
// Apply privacy policy if in peripheral mode for non-resolved addresses
Expand All @@ -1490,7 +1490,7 @@ BLE_DEPRECATED_API_USE_END()
// Reject connection request - the user will get notified through a callback
_pal_gap.disconnect(
e.connection_handle,
pal::disconnection_reason_t::AUTHENTICATION_FAILLURE
pal::disconnection_reason_t::AUTHENTICATION_FAILURE
);
return;

Expand All @@ -1508,7 +1508,7 @@ BLE_DEPRECATED_API_USE_END()
}
}

if (e.role.value() == e.role.SLAVE) {
if (e.role.value() == e.role.PERIPHERAL) {
_advertising_timeout.detach();
_pal_gap.advertising_enable(false);

Expand All @@ -1534,7 +1534,7 @@ BLE_DEPRECATED_API_USE_END()

processConnectionEvent(
e.connection_handle,
e.role.value() == e.role.MASTER ? ::Gap::CENTRAL : ::Gap::PERIPHERAL,
e.role.value() == e.role.CENTRAL ? ::Gap::CENTRAL : ::Gap::PERIPHERAL,
e.peer_address_type,
e.peer_address.data(),
_address_type,
Expand Down Expand Up @@ -1606,7 +1606,7 @@ pal::own_address_type_t GenericGap::get_own_address_type(AddressUseType_t addres

// An non resolvable private address should be generated
if (use_non_resolvable_address) {
return pal::own_address_type_t::RANDOM_ADDRESS;
return pal::own_address_type_t::RANDOM;
}

switch (_address_type) {
Expand All @@ -1619,9 +1619,9 @@ pal::own_address_type_t GenericGap::get_own_address_type(AddressUseType_t addres

switch (_address_type) {
case BLEProtocol::AddressType::PUBLIC:
return pal::own_address_type_t::PUBLIC_ADDRESS;
return pal::own_address_type_t::PUBLIC;
default:
return pal::own_address_type_t::RANDOM_ADDRESS;
return pal::own_address_type_t::RANDOM;
}
}

Expand Down
10 changes: 5 additions & 5 deletions features/FEATURE_BLE/source/generic/GenericSecurityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,8 +1100,8 @@ void GenericSecurityManager::on_security_entry_retrieved(

_pal.add_device_to_resolving_list(
identity->identity_address_is_public ?
address_type_t::PUBLIC_ADDRESS :
address_type_t::RANDOM_ADDRESS,
address_type_t::PUBLIC :
address_type_t::RANDOM,
identity->identity_address,
identity->irk
);
Expand All @@ -1117,8 +1117,8 @@ void GenericSecurityManager::on_identity_list_retrieved(
for (size_t i = 0; i < count; ++i) {
_pal.add_device_to_resolving_list(
identity_list[i].identity_address_is_public ?
address_type_t::PUBLIC_ADDRESS :
address_type_t::RANDOM_ADDRESS,
address_type_t::PUBLIC :
address_type_t::RANDOM,
identity_list[i].identity_address,
identity_list[i].irk
);
Expand Down Expand Up @@ -1564,7 +1564,7 @@ void GenericSecurityManager::on_keys_distributed_bdaddr(

_db->set_entry_peer_bdaddr(
cb->db_entry,
(peer_address_type == advertising_peer_address_type_t::PUBLIC_ADDRESS),
(peer_address_type == advertising_peer_address_type_t::PUBLIC),
peer_identity_address
);
}
Expand Down

0 comments on commit 78d4a9b

Please sign in to comment.