I thought git would be smart enough to understand all the whitespace changes but even with all the flags I know to make it ignore theses it still blows up if there are identical changes on both sides.
I have a solution but it require creating a new commit at the merge base for each conflicting PR and merging it into develop.
I don't think blowing up all PRs is worth for now, maybe if we can coordinate this for V3 let's say.
This reverts commit 0d11331d18.
This commit is contained in:
@@ -41,99 +41,103 @@
|
||||
|
||||
const uint16_t UUID16_SVC_DFU_OTA = 0xFE59;
|
||||
|
||||
const uint8_t UUID128_CHR_DFU_CONTROL[16] = {0x50, 0xEA, 0xDA, 0x30, 0x88, 0x83, 0xB8, 0x9F, 0x60, 0x4F, 0x15, 0xF3, 0x03, 0x00, 0xC9, 0x8E};
|
||||
const uint8_t UUID128_CHR_DFU_CONTROL[16] = {0x50, 0xEA, 0xDA, 0x30, 0x88, 0x83, 0xB8, 0x9F,
|
||||
0x60, 0x4F, 0x15, 0xF3, 0x03, 0x00, 0xC9, 0x8E};
|
||||
|
||||
extern "C" void bootloader_util_app_start(uint32_t start_addr);
|
||||
|
||||
static uint16_t crc16(const uint8_t *data_p, uint8_t length) {
|
||||
uint16_t crc = 0xFFFF;
|
||||
static uint16_t crc16(const uint8_t *data_p, uint8_t length)
|
||||
{
|
||||
uint16_t crc = 0xFFFF;
|
||||
|
||||
while (length--) {
|
||||
uint8_t x = crc >> 8 ^ *data_p++;
|
||||
x ^= x >> 4;
|
||||
crc = (crc << 8) ^ ((uint16_t)(x << 12)) ^ ((uint16_t)(x << 5)) ^ ((uint16_t)x);
|
||||
}
|
||||
return crc;
|
||||
while (length--) {
|
||||
uint8_t x = crc >> 8 ^ *data_p++;
|
||||
x ^= x >> 4;
|
||||
crc = (crc << 8) ^ ((uint16_t)(x << 12)) ^ ((uint16_t)(x << 5)) ^ ((uint16_t)x);
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
static void bledfu_control_wr_authorize_cb(uint16_t conn_hdl, BLECharacteristic *chr, ble_gatts_evt_write_t *request) {
|
||||
if ((request->handle == chr->handles().value_handle) && (request->op != BLE_GATTS_OP_PREP_WRITE_REQ) &&
|
||||
(request->op != BLE_GATTS_OP_EXEC_WRITE_REQ_NOW) && (request->op != BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL)) {
|
||||
BLEConnection *conn = Bluefruit.Connection(conn_hdl);
|
||||
static void bledfu_control_wr_authorize_cb(uint16_t conn_hdl, BLECharacteristic *chr, ble_gatts_evt_write_t *request)
|
||||
{
|
||||
if ((request->handle == chr->handles().value_handle) && (request->op != BLE_GATTS_OP_PREP_WRITE_REQ) &&
|
||||
(request->op != BLE_GATTS_OP_EXEC_WRITE_REQ_NOW) && (request->op != BLE_GATTS_OP_EXEC_WRITE_REQ_CANCEL)) {
|
||||
BLEConnection *conn = Bluefruit.Connection(conn_hdl);
|
||||
|
||||
ble_gatts_rw_authorize_reply_params_t reply = {.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE};
|
||||
ble_gatts_rw_authorize_reply_params_t reply = {.type = BLE_GATTS_AUTHORIZE_TYPE_WRITE};
|
||||
|
||||
if (!chr->indicateEnabled(conn_hdl)) {
|
||||
reply.params.write.gatt_status = BLE_GATT_STATUS_ATTERR_CPS_CCCD_CONFIG_ERROR;
|
||||
sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply);
|
||||
return;
|
||||
}
|
||||
|
||||
reply.params.write.gatt_status = BLE_GATT_STATUS_SUCCESS;
|
||||
sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply);
|
||||
|
||||
enum { START_DFU = 1 };
|
||||
if (request->data[0] == START_DFU) {
|
||||
// Peer data information so that bootloader could re-connect after reboot
|
||||
typedef struct {
|
||||
ble_gap_addr_t addr;
|
||||
ble_gap_irk_t irk;
|
||||
ble_gap_enc_key_t enc_key;
|
||||
uint8_t sys_attr[8];
|
||||
uint16_t crc16;
|
||||
} peer_data_t;
|
||||
|
||||
VERIFY_STATIC(offsetof(peer_data_t, crc16) == 60);
|
||||
|
||||
/* Save Peer data
|
||||
* Peer data address is defined in bootloader linker @0x20007F80
|
||||
* - If bonded : save Security information
|
||||
* - Otherwise : save Address for direct advertising
|
||||
*
|
||||
* TODO may force bonded only for security reason
|
||||
*/
|
||||
peer_data_t *peer_data = (peer_data_t *)(0x20007F80UL);
|
||||
varclr(peer_data);
|
||||
|
||||
// Get CCCD
|
||||
uint16_t sysattr_len = sizeof(peer_data->sys_attr);
|
||||
sd_ble_gatts_sys_attr_get(conn_hdl, peer_data->sys_attr, &sysattr_len, BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS);
|
||||
|
||||
// Get Bond Data or using Address if not bonded
|
||||
peer_data->addr = conn->getPeerAddr();
|
||||
|
||||
if (conn->secured()) {
|
||||
bond_keys_t bkeys;
|
||||
if (conn->loadBondKey(&bkeys)) {
|
||||
peer_data->addr = bkeys.peer_id.id_addr_info;
|
||||
peer_data->irk = bkeys.peer_id.id_info;
|
||||
peer_data->enc_key = bkeys.own_enc;
|
||||
if (!chr->indicateEnabled(conn_hdl)) {
|
||||
reply.params.write.gatt_status = BLE_GATT_STATUS_ATTERR_CPS_CCCD_CONFIG_ERROR;
|
||||
sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate crc
|
||||
peer_data->crc16 = crc16((uint8_t *)peer_data, offsetof(peer_data_t, crc16));
|
||||
reply.params.write.gatt_status = BLE_GATT_STATUS_SUCCESS;
|
||||
sd_ble_gatts_rw_authorize_reply(conn_hdl, &reply);
|
||||
|
||||
// Initiate DFU Sequence and reboot into DFU OTA mode
|
||||
Bluefruit.Advertising.restartOnDisconnect(false);
|
||||
conn->disconnect();
|
||||
enum { START_DFU = 1 };
|
||||
if (request->data[0] == START_DFU) {
|
||||
// Peer data information so that bootloader could re-connect after reboot
|
||||
typedef struct {
|
||||
ble_gap_addr_t addr;
|
||||
ble_gap_irk_t irk;
|
||||
ble_gap_enc_key_t enc_key;
|
||||
uint8_t sys_attr[8];
|
||||
uint16_t crc16;
|
||||
} peer_data_t;
|
||||
|
||||
NRF_POWER->GPREGRET = 0xB1;
|
||||
NVIC_SystemReset();
|
||||
VERIFY_STATIC(offsetof(peer_data_t, crc16) == 60);
|
||||
|
||||
/* Save Peer data
|
||||
* Peer data address is defined in bootloader linker @0x20007F80
|
||||
* - If bonded : save Security information
|
||||
* - Otherwise : save Address for direct advertising
|
||||
*
|
||||
* TODO may force bonded only for security reason
|
||||
*/
|
||||
peer_data_t *peer_data = (peer_data_t *)(0x20007F80UL);
|
||||
varclr(peer_data);
|
||||
|
||||
// Get CCCD
|
||||
uint16_t sysattr_len = sizeof(peer_data->sys_attr);
|
||||
sd_ble_gatts_sys_attr_get(conn_hdl, peer_data->sys_attr, &sysattr_len, BLE_GATTS_SYS_ATTR_FLAG_SYS_SRVCS);
|
||||
|
||||
// Get Bond Data or using Address if not bonded
|
||||
peer_data->addr = conn->getPeerAddr();
|
||||
|
||||
if (conn->secured()) {
|
||||
bond_keys_t bkeys;
|
||||
if (conn->loadBondKey(&bkeys)) {
|
||||
peer_data->addr = bkeys.peer_id.id_addr_info;
|
||||
peer_data->irk = bkeys.peer_id.id_info;
|
||||
peer_data->enc_key = bkeys.own_enc;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate crc
|
||||
peer_data->crc16 = crc16((uint8_t *)peer_data, offsetof(peer_data_t, crc16));
|
||||
|
||||
// Initiate DFU Sequence and reboot into DFU OTA mode
|
||||
Bluefruit.Advertising.restartOnDisconnect(false);
|
||||
conn->disconnect();
|
||||
|
||||
NRF_POWER->GPREGRET = 0xB1;
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BLEDfuSecure::BLEDfuSecure(void) : BLEService(UUID16_SVC_DFU_OTA), _chr_control(UUID128_CHR_DFU_CONTROL) {}
|
||||
|
||||
err_t BLEDfuSecure::begin(void) {
|
||||
// Invoke base class begin()
|
||||
VERIFY_STATUS(BLEService::begin());
|
||||
err_t BLEDfuSecure::begin(void)
|
||||
{
|
||||
// Invoke base class begin()
|
||||
VERIFY_STATUS(BLEService::begin());
|
||||
|
||||
_chr_control.setProperties(CHR_PROPS_WRITE | CHR_PROPS_INDICATE);
|
||||
_chr_control.setMaxLen(23);
|
||||
_chr_control.setWriteAuthorizeCallback(bledfu_control_wr_authorize_cb);
|
||||
VERIFY_STATUS(_chr_control.begin());
|
||||
_chr_control.setProperties(CHR_PROPS_WRITE | CHR_PROPS_INDICATE);
|
||||
_chr_control.setMaxLen(23);
|
||||
_chr_control.setWriteAuthorizeCallback(bledfu_control_wr_authorize_cb);
|
||||
VERIFY_STATUS(_chr_control.begin());
|
||||
|
||||
return ERROR_NONE;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user