Skip to content

Commit

Permalink
升级到SDK17.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Geno [格诺] committed Sep 21, 2021
1 parent 821dbb0 commit a9a9369
Show file tree
Hide file tree
Showing 217 changed files with 13,531 additions and 4,716 deletions.
23 changes: 20 additions & 3 deletions SDK/components/ble/ble_services/nrf_ble_bms/nrf_ble_bms.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
* Copyright (c) 2016 - 2021, Nordic Semiconductor ASA
*
* All rights reserved.
*
Expand Down Expand Up @@ -521,6 +521,8 @@ uint16_t nrf_ble_bms_on_qwr_evt(nrf_ble_bms_t * p_bms,
VERIFY_TRUE(p_evt->attr_handle == p_bms->ctrlpt_handles.value_handle,
(NRF_BLE_QWR_REJ_REQUEST_ERR_CODE));

p_bms->conn_handle = p_qwr->conn_handle;

if (p_evt->evt_type == NRF_BLE_QWR_EVT_AUTH_REQUEST)
{
return on_qwr_auth_req(p_bms, p_qwr, p_evt);
Expand All @@ -545,6 +547,7 @@ void nrf_ble_bms_on_ble_evt(ble_evt_t const * p_ble_evt, void * p_context)
switch (p_ble_evt->header.evt_id)
{
case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
p_bms->conn_handle = p_ble_evt->evt.gatts_evt.conn_handle;
on_rw_auth_req(p_bms, &p_ble_evt->evt.gatts_evt);
break;

Expand Down Expand Up @@ -591,9 +594,23 @@ ret_code_t nrf_ble_bms_init(nrf_ble_bms_t * p_bms, nrf_ble_bms_init_t * p_bms_in
err_code = ctrlpt_char_add(p_bms, p_bms_init);
VERIFY_SUCCESS(err_code);

if (p_bms_init->p_qwr != NULL)
// Allow this for backward compatibility
if ((p_bms_init->p_qwr != NULL) && (p_bms_init->qwr_count == 0))
{
err_code = nrf_ble_qwr_attr_register(p_bms_init->p_qwr, p_bms->ctrlpt_handles.value_handle);
VERIFY_SUCCESS(err_code);
}
else if (p_bms_init->p_qwr && (p_bms_init->qwr_count > 0))
{
for (uint32_t i = 0; i < p_bms_init->qwr_count; i++)
{
err_code = nrf_ble_qwr_attr_register(&p_bms_init->p_qwr[i], p_bms->ctrlpt_handles.value_handle);
VERIFY_SUCCESS(err_code);
}
}
else
{
return nrf_ble_qwr_attr_register(p_bms_init->p_qwr, p_bms->ctrlpt_handles.value_handle);
// Do nothing
}

NRF_LOG_INFO("Init complete.");
Expand Down
7 changes: 5 additions & 2 deletions SDK/components/ble/ble_services/nrf_ble_bms/nrf_ble_bms.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
* Copyright (c) 2016 - 2021, Nordic Semiconductor ASA
*
* All rights reserved.
*
Expand Down Expand Up @@ -221,7 +221,8 @@ typedef struct
nrf_ble_bms_features_t feature; //!< Initial value for features of the service.
security_req_t bms_feature_sec_req; //!< Initial security level for the Feature characteristic.
security_req_t bms_ctrlpt_sec_req; //!< Initial security level for the Control Point characteristic.
nrf_ble_qwr_t * p_qwr; //!< Pointer to the initialized Queued Write context.
nrf_ble_qwr_t * p_qwr; //!< Pointer to the initialized Queued Write contexts.
uint8_t qwr_count; //!< Initialized Queue Write contexts count.
nrf_ble_bms_bond_cbs_t bond_callbacks; //!< Callback functions for deleting bonds.
} nrf_ble_bms_init_t;

Expand Down Expand Up @@ -271,6 +272,8 @@ ret_code_t nrf_ble_bms_init(nrf_ble_bms_t * p_bms, nrf_ble_bms_init_t * p_bms_in
*
* @details Call this function when a link with a peer has been established to
* associate the link to this instance of the module.
*
* @note Currently this function is deprecated.
*
* @param[in] p_bms Pointer to the BMS structure instance to associate.
* @param[in] conn_handle Connection handle to be associated with the given BMS instance.
Expand Down
7 changes: 5 additions & 2 deletions SDK/components/ble/nrf_ble_gatt/nrf_ble_gatt.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2016 - 2020, Nordic Semiconductor ASA
* Copyright (c) 2016 - 2021, Nordic Semiconductor ASA
*
* All rights reserved.
*
Expand Down Expand Up @@ -121,7 +121,6 @@ static ret_code_t data_length_update(uint16_t conn_handle, uint16_t data_length)
*/
static void on_connected_evt(nrf_ble_gatt_t * p_gatt, ble_evt_t const * p_ble_evt)
{
ret_code_t err_code;
uint16_t conn_handle = p_ble_evt->evt.common_evt.conn_handle;
nrf_ble_gatt_link_t * p_link = &p_gatt->links[conn_handle];

Expand Down Expand Up @@ -149,9 +148,12 @@ static void on_connected_evt(nrf_ble_gatt_t * p_gatt, ble_evt_t const * p_ble_ev
break;
}

#if NRF_BLE_GATT_MTU_EXCHANGE_INITIATION_ENABLED
// Begin an ATT MTU exchange if necessary.
if (p_link->att_mtu_desired > p_link->att_mtu_effective)
{
ret_code_t err_code;

NRF_LOG_DEBUG("Requesting to update ATT MTU to %u bytes on connection 0x%x.",
p_link->att_mtu_desired, conn_handle);

Expand All @@ -173,6 +175,7 @@ static void on_connected_evt(nrf_ble_gatt_t * p_gatt, ble_evt_t const * p_ble_ev
nrf_strerror_get(err_code));
}
}
#endif // NRF_BLE_GATT_MTU_EXCHANGE_INITIATION_ENABLED

#if !defined (S112) && !defined(S312) && !defined (S122)
// Send a data length update request if necessary.
Expand Down
104 changes: 12 additions & 92 deletions SDK/components/ble/nrf_ble_scan/nrf_ble_scan.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2018 - 2020, Nordic Semiconductor ASA
* Copyright (c) 2018 - 2021, Nordic Semiconductor ASA
*
* All rights reserved.
*
Expand Down Expand Up @@ -113,52 +113,6 @@ static void nrf_ble_scan_connect_with_target(nrf_ble_scan_t const * co
}


/**@brief Function for decoding the BLE address type.
*
* @param[in] p_addr The BLE address.
*
* @return Address type, or an error if the address type is incorrect, that is it does not match @ref BLE_GAP_ADDR_TYPES.
*
*/
static uint16_t nrf_ble_scan_address_type_decode(uint8_t const * p_addr)
{
uint8_t addr_type = p_addr[0];

// See Bluetooth Core Specification Vol 6, Part B, section 1.3.
addr_type = addr_type >> 6;
addr_type &= 0x03;

// Check address type.
switch (addr_type)
{
case 0:
{
return BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_NON_RESOLVABLE;
}

case 1:
{
return BLE_GAP_ADDR_TYPE_PUBLIC;
}

case 2:
{
return BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE;
}

case 3:
{
return BLE_GAP_ADDR_TYPE_RANDOM_STATIC;
}

default:
{
return BLE_ERROR_GAP_INVALID_BLE_ADDR;
}
}
}


#if (NRF_BLE_SCAN_FILTER_ENABLE == 1)
#if (NRF_BLE_SCAN_ADDRESS_CNT > 0)

Expand All @@ -175,16 +129,14 @@ static uint16_t nrf_ble_scan_address_type_decode(uint8_t const * p_addr)
static bool find_peer_addr(ble_gap_evt_adv_report_t const * const p_adv_report,
ble_gap_addr_t const * p_addr)
{
if (p_addr->addr_type == p_adv_report->peer_addr.addr_type)
// Compare addresses.
if (memcmp(p_addr->addr,
p_adv_report->peer_addr.addr,
sizeof(p_adv_report->peer_addr.addr)) == 0)
{
// Compare addresses.
if (memcmp(p_addr->addr,
p_adv_report->peer_addr.addr,
sizeof(p_adv_report->peer_addr.addr)) == 0)
{
return true;
}
return true;
}

return false;
}

Expand Down Expand Up @@ -230,8 +182,6 @@ static ret_code_t nrf_ble_scan_addr_filter_add(nrf_ble_scan_t * const p_scan_ctx
ble_gap_addr_t * p_addr_filter = p_scan_ctx->scan_filters.addr_filter.target_addr;
uint8_t * p_counter = &p_scan_ctx->scan_filters.addr_filter.addr_cnt;
uint8_t index;
uint16_t addr_type;
uint8_t temp_addr[BLE_GAP_ADDR_LEN];

// If no memory for filter.
if (*p_counter >= NRF_BLE_SCAN_ADDRESS_CNT)
Expand All @@ -248,37 +198,16 @@ static ret_code_t nrf_ble_scan_addr_filter_add(nrf_ble_scan_t * const p_scan_ctx
}
}

// Inverting the address.
for (uint8_t i = 0; i < BLE_GAP_ADDR_LEN; i++)
{
temp_addr[i] = p_addr[(BLE_GAP_ADDR_LEN - 1) - i];
}

// Decode address type.
addr_type = nrf_ble_scan_address_type_decode(temp_addr);

if (addr_type == BLE_ERROR_GAP_INVALID_BLE_ADDR)
{
return BLE_ERROR_GAP_INVALID_BLE_ADDR;
}

// Add target address to filter.
p_addr_filter[*p_counter].addr_type = (uint8_t)addr_type;

for (uint8_t i = 0; i < BLE_GAP_ADDR_LEN; i++)
{
p_addr_filter[*p_counter].addr[i] = p_addr[i];
}

NRF_LOG_DEBUG("Filter set on address type %i, address 0x",
p_addr_filter[*p_counter].addr_type);

for (index = 0; index < BLE_GAP_ADDR_LEN; index++)
{
NRF_LOG_DEBUG("%x", p_addr_filter[*p_counter].addr[index]);
}
// Address type is not used so set it to 0.
p_addr_filter[*p_counter].addr_type = 0;

NRF_LOG_DEBUG("\n\r");
NRF_LOG_DEBUG("Filter set on address 0x");
NRF_LOG_HEXDUMP_DEBUG(p_addr_filter[*p_counter].addr, BLE_GAP_ADDR_LEN);

// Increase the address filter counter.
*p_counter += 1;
Expand Down Expand Up @@ -1254,16 +1183,7 @@ static void nrf_ble_scan_on_connected_evt(nrf_ble_scan_t const * const p_scan_ct
ret_code_t nrf_ble_scan_copy_addr_to_sd_gap_addr(ble_gap_addr_t * p_gap_addr,
const uint8_t addr[BLE_GAP_ADDR_LEN])
{
uint16_t addr_type;

addr_type = nrf_ble_scan_address_type_decode(addr);

if (addr_type == BLE_ERROR_GAP_INVALID_BLE_ADDR)
{
return BLE_ERROR_GAP_INVALID_BLE_ADDR;
}

p_gap_addr->addr_type = addr_type;
VERIFY_PARAM_NOT_NULL(p_gap_addr);

for (uint8_t i = 0; i < BLE_GAP_ADDR_LEN; ++i)
{
Expand Down
4 changes: 3 additions & 1 deletion SDK/components/ble/peer_manager/gatt_cache_manager.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
* Copyright (c) 2015 - 2021, Nordic Semiconductor ASA
*
* All rights reserved.
*
Expand Down Expand Up @@ -250,6 +250,8 @@ static bool local_db_update_in_evt(uint16_t conn_handle)
success = true;
break;

case NRF_ERROR_INVALID_DATA:
/* Fallthrough */
case BLE_ERROR_INVALID_CONN_HANDLE:
/* Do nothing */
break;
Expand Down
41 changes: 39 additions & 2 deletions SDK/components/ble/peer_manager/gatts_cache_manager.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2015 - 2020, Nordic Semiconductor ASA
* Copyright (c) 2015 - 2021, Nordic Semiconductor ASA
*
* All rights reserved.
*
Expand Down Expand Up @@ -228,7 +228,44 @@ ret_code_t gscm_local_db_cache_update(uint16_t conn_handle)

if (err_code == NRF_SUCCESS)
{
err_code = pdb_write_buf_store(peer_id, PM_PEER_DATA_ID_GATT_LOCAL, peer_id);
pm_peer_data_flash_t curr_peer_data;

err_code = pdb_peer_data_ptr_get(peer_id,
PM_PEER_DATA_ID_GATT_LOCAL,
&curr_peer_data);

if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_NOT_FOUND))
{
NRF_LOG_ERROR("pdb_peer_data_ptr_get() returned %s for conn_handle: %d",
nrf_strerror_get(err_code),
conn_handle);
return NRF_ERROR_INTERNAL;
}

if((err_code == NRF_ERROR_NOT_FOUND)
|| (p_local_gatt_db->len != curr_peer_data.p_local_gatt_db->len)
|| (memcmp(p_local_gatt_db->data, curr_peer_data.p_local_gatt_db->data,
p_local_gatt_db->len) != 0))
{
err_code = pdb_write_buf_store(peer_id, PM_PEER_DATA_ID_GATT_LOCAL, peer_id);
}
else
{
NRF_LOG_DEBUG("Local db is already up to date, skipping write.");
ret_code_t err_code_release = pdb_write_buf_release(peer_id, PM_PEER_DATA_ID_GATT_LOCAL);
if (err_code_release == NRF_SUCCESS)
{
err_code = NRF_ERROR_INVALID_DATA;
}
else
{
NRF_LOG_ERROR("Did another thread manipulate PM_PEER_DATA_ID_GATT_LOCAL for "\
"peer_id %d at the same time? pdb_write_buf_release() returned %s.",
peer_id,
nrf_strerror_get(err_code_release));
err_code = NRF_ERROR_INTERNAL;
}
}
}
else
{
Expand Down
Loading

0 comments on commit a9a9369

Please sign in to comment.