diff --git a/src/ble/ancs_client.c b/src/ble/ancs_client.c index 27d9703f3..6593415f1 100644 --- a/src/ble/ancs_client.c +++ b/src/ble/ancs_client.c @@ -102,14 +102,14 @@ static void notify_client_text(int event_type){ if (!client_handler) return; uint8_t event[7 + sizeof(ancs_notification_buffer) + 1]; event[0] = HCI_EVENT_ANCS_META; - event[1] = 5 + ancs_attribute_len; + event[1] = 5u + ancs_attribute_len; event[2] = event_type; little_endian_store_16(event, 3, gc_handle); little_endian_store_16(event, 5, ancs_attribute_id); (void)memcpy(&event[7], ancs_notification_buffer, ancs_attribute_len); // we're nice - event[7+ancs_attribute_len] = 0; - (*client_handler)(HCI_EVENT_PACKET, 0, event, event[1] + 2); + event[7u+ancs_attribute_len] = 0u; + (*client_handler)(HCI_EVENT_PACKET, 0u, event, event[1u] + 2u); } static void notify_client_simple(int event_type){ @@ -149,16 +149,16 @@ static void ancs_chunk_parser_handle_byte(uint8_t data){ if (ancs_bytes_received < ancs_bytes_needed) return; switch (chunk_parser_state){ case W4_ATTRIBUTE_ID: - ancs_attribute_id = ancs_notification_buffer[ancs_bytes_received-1]; + ancs_attribute_id = ancs_notification_buffer[ancs_bytes_received-1u]; ancs_bytes_received = 0; ancs_bytes_needed = 2; chunk_parser_state = W4_ATTRIBUTE_LEN; break; case W4_ATTRIBUTE_LEN: - ancs_attribute_len = little_endian_read_16(ancs_notification_buffer, ancs_bytes_received-2); + ancs_attribute_len = little_endian_read_16(ancs_notification_buffer, ancs_bytes_received-2u); ancs_bytes_received = 0; ancs_bytes_needed = ancs_attribute_len; - if (ancs_attribute_len == 0) { + if (ancs_attribute_len == 0u) { ancs_bytes_needed = 1; chunk_parser_state = W4_ATTRIBUTE_ID; break; diff --git a/src/ble/att_db.c b/src/ble/att_db.c index 59d3c95aa..c07392a02 100644 --- a/src/ble/att_db.c +++ b/src/ble/att_db.c @@ -67,7 +67,7 @@ static int is_Bluetooth_Base_UUID(uint8_t const *uuid){ } static uint16_t uuid16_from_uuid(uint16_t uuid_len, uint8_t * uuid){ - if (uuid_len == 2) return little_endian_read_16(uuid, 0); + if (uuid_len == 2u) return little_endian_read_16(uuid, 0u); if (!is_Bluetooth_Base_UUID(uuid)) return 0; return little_endian_read_16(uuid, 12); } @@ -109,7 +109,7 @@ static bool att_iterator_has_next(att_iterator_t *it){ static void att_iterator_fetch_next(att_iterator_t *it){ it->size = little_endian_read_16(it->att_ptr, 0); - if (it->size == 0){ + if (it->size == 0u){ it->flags = 0; it->handle = 0; it->uuid = NULL; @@ -122,11 +122,11 @@ static void att_iterator_fetch_next(att_iterator_t *it){ it->handle = little_endian_read_16(it->att_ptr, 4); it->uuid = &it->att_ptr[6]; // handle 128 bit UUIDs - if ((it->flags & ATT_PROPERTY_UUID128) != 0){ - it->value_len = it->size - 22; + if ((it->flags & ATT_PROPERTY_UUID128) != 0u){ + it->value_len = it->size - 22u; it->value = &it->att_ptr[22]; } else { - it->value_len = it->size - 8; + it->value_len = it->size - 8u; it->value = &it->att_ptr[8]; } // advance AFTER setting values @@ -134,7 +134,7 @@ static void att_iterator_fetch_next(att_iterator_t *it){ } static int att_iterator_match_uuid16(att_iterator_t *it, uint16_t uuid){ - if (it->handle == 0) return 0; + if (it->handle == 0u) return 0u; if (it->flags & ATT_PROPERTY_UUID128){ if (!is_Bluetooth_Base_UUID(it->uuid)) return 0; return little_endian_read_16(it->uuid, 12) == uuid; @@ -143,13 +143,13 @@ static int att_iterator_match_uuid16(att_iterator_t *it, uint16_t uuid){ } static int att_iterator_match_uuid(att_iterator_t *it, uint8_t *uuid, uint16_t uuid_len){ - if (it->handle == 0) return 0; + if (it->handle == 0u) return 0u; // input: UUID16 - if (uuid_len == 2) { + if (uuid_len == 2u) { return att_iterator_match_uuid16(it, little_endian_read_16(uuid, 0)); } // input and db: UUID128 - if ((it->flags & ATT_PROPERTY_UUID128) != 0){ + if ((it->flags & ATT_PROPERTY_UUID128) != 0u){ return memcmp(it->uuid, uuid, 16) == 0; } // input: UUID128, db: UUID16 @@ -159,7 +159,7 @@ static int att_iterator_match_uuid(att_iterator_t *it, uint8_t *uuid, uint16_t u static int att_find_handle(att_iterator_t *it, uint16_t handle){ - if (handle == 0) return 0; + if (handle == 0u) return 0u; att_iterator_init(it); while (att_iterator_has_next(it)){ att_iterator_fetch_next(it); @@ -174,13 +174,13 @@ uint16_t att_uuid_for_handle(uint16_t attribute_handle){ att_iterator_t it; int ok = att_find_handle(&it, attribute_handle); if (!ok) return 0; - if ((it.flags & ATT_PROPERTY_UUID128) != 0) return 0; + if ((it.flags & ATT_PROPERTY_UUID128) != 0u) return 0u; return little_endian_read_16(it.uuid, 0); } // end of client API static void att_update_value_len(att_iterator_t *it, hci_con_handle_t con_handle){ - if ((it->flags & ATT_PROPERTY_DYNAMIC) == 0) return; + if ((it->flags & ATT_PROPERTY_DYNAMIC) == 0u) return; it->value_len = (*att_read_callback)(con_handle, it->handle, 0, NULL, 0); return; } @@ -189,7 +189,7 @@ static void att_update_value_len(att_iterator_t *it, hci_con_handle_t con_handle static int att_copy_value(att_iterator_t *it, uint16_t offset, uint8_t * buffer, uint16_t buffer_size, hci_con_handle_t con_handle){ // DYNAMIC - if ((it->flags & ATT_PROPERTY_DYNAMIC) != 0){ + if ((it->flags & ATT_PROPERTY_DYNAMIC) != 0u){ return (*att_read_callback)(con_handle, it->handle, offset, buffer, buffer_size); } @@ -226,12 +226,12 @@ void att_dump_attributes(void){ uint8_t uuid128[16]; while (att_iterator_has_next(&it)){ att_iterator_fetch_next(&it); - if (it.handle == 0) { + if (it.handle == 0u) { log_info("Handle: END"); return; } log_info("Handle: 0x%04x, flags: 0x%04x, uuid: ", it.handle, it.flags); - if ((it.flags & ATT_PROPERTY_UUID128) != 0){ + if ((it.flags & ATT_PROPERTY_UUID128) != 0u){ reverse_128(it.uuid, uuid128); log_info("%s", uuid128_to_str(uuid128)); } else { @@ -296,52 +296,52 @@ static inline uint16_t setup_error_invalid_pdu(uint8_t *response_buffer, uint16_ static uint8_t att_validate_security(att_connection_t * att_connection, att_operation_t operation, att_iterator_t * it){ int required_security_level = 0; - int requires_secure_connection = 0; + bool requires_secure_connection = false; switch (operation){ case ATT_READ: - if ((it->flags & ATT_PROPERTY_READ_PERMISSION_BIT_0) != 0){ + if ((it->flags & ATT_PROPERTY_READ_PERMISSION_BIT_0) != 0u){ required_security_level |= 1; } - if ((it->flags & ATT_PROPERTY_READ_PERMISSION_BIT_1) != 0){ + if ((it->flags & ATT_PROPERTY_READ_PERMISSION_BIT_1) != 0u){ required_security_level |= 2; } - if ((it->flags & ATT_PROPERTY_READ_PERMISSION_SC) != 0){ - requires_secure_connection = 1; + if ((it->flags & ATT_PROPERTY_READ_PERMISSION_SC) != 0u){ + requires_secure_connection = true; } break; case ATT_WRITE: - if ((it->flags & ATT_PROPERTY_WRITE_PERMISSION_BIT_0) != 0){ + if ((it->flags & ATT_PROPERTY_WRITE_PERMISSION_BIT_0) != 0u){ required_security_level |= 1; } - if ((it->flags & ATT_PROPERTY_WRITE_PERMISSION_BIT_1) != 0){ + if ((it->flags & ATT_PROPERTY_WRITE_PERMISSION_BIT_1) != 0u){ required_security_level |= 2; } - if ((it->flags & ATT_PROPERTY_WRITE_PERMISSION_SC) != 0){ - requires_secure_connection = 1; + if ((it->flags & ATT_PROPERTY_WRITE_PERMISSION_SC) != 0u){ + requires_secure_connection = true; } break; } - int required_encryption_size = it->flags >> 12; + uint8_t required_encryption_size = it->flags >> 12; if (required_encryption_size != 0) required_encryption_size++; // store -1 to fit into 4 bit log_debug("att_validate_security. flags 0x%04x (=> security level %u, key size %u) authorized %u, authenticated %u, encryption_key_size %u, secure connection %u", it->flags, required_security_level, required_encryption_size, att_connection->authorized, att_connection->authenticated, att_connection->encryption_key_size, att_connection->secure_connection); - int sc_missing = requires_secure_connection && (att_connection->secure_connection == 0); + bool sc_missing = requires_secure_connection && (att_connection->secure_connection == 0u); switch (required_security_level){ case ATT_SECURITY_AUTHORIZED: - if ((att_connection->authorized == 0) || sc_missing){ + if ((att_connection->authorized == 0u) || sc_missing){ return ATT_ERROR_INSUFFICIENT_AUTHORIZATION; } /* fall through */ case ATT_SECURITY_AUTHENTICATED: - if ((att_connection->authenticated == 0) || sc_missing){ + if ((att_connection->authenticated == 0u) || sc_missing){ return ATT_ERROR_INSUFFICIENT_AUTHENTICATION; } /* fall through */ case ATT_SECURITY_ENCRYPTED: - if ((required_encryption_size > 0) && ((att_connection->encryption_key_size == 0) || sc_missing)){ + if ((required_encryption_size > 0u) && ((att_connection->encryption_key_size == 0u) || sc_missing)){ return ATT_ERROR_INSUFFICIENT_ENCRYPTION; } if (required_encryption_size > att_connection->encryption_key_size){ @@ -360,7 +360,7 @@ static uint8_t att_validate_security(att_connection_t * att_connection, att_oper static uint16_t handle_exchange_mtu_request(att_connection_t * att_connection, uint8_t * request_buffer, uint16_t request_len, uint8_t * response_buffer){ - if (request_len != 3) return setup_error_invalid_pdu(response_buffer, ATT_EXCHANGE_MTU_REQUEST); + if (request_len != 3u) return setup_error_invalid_pdu(response_buffer, ATT_EXCHANGE_MTU_REQUEST); uint16_t client_rx_mtu = little_endian_read_16(request_buffer, 1); @@ -388,7 +388,7 @@ static uint16_t handle_find_information_request2(att_connection_t * att_connecti log_info("ATT_FIND_INFORMATION_REQUEST: from %04X to %04X", start_handle, end_handle); uint8_t request_type = ATT_FIND_INFORMATION_REQUEST; - if ((start_handle > end_handle) || (start_handle == 0)){ + if ((start_handle > end_handle) || (start_handle == 0u)){ return setup_error_invalid_handle(response_buffer, request_type, start_handle); } @@ -408,14 +408,14 @@ static uint16_t handle_find_information_request2(att_connection_t * att_connecti uint16_t this_uuid_len = (it.flags & ATT_PROPERTY_UUID128) ? 16 : 2; // check if value has same len as last one if not first result - if (offset > 1){ + if (offset > 1u){ if (this_uuid_len != uuid_len) { break; } } // first - if (offset == 1) { + if (offset == 1u) { uuid_len = this_uuid_len; // set format field response_buffer[offset] = (it.flags & ATT_PROPERTY_UUID128) ? 0x02 : 0x01; @@ -423,17 +423,17 @@ static uint16_t handle_find_information_request2(att_connection_t * att_connecti } // space? - if ((offset + 2 + uuid_len) > response_buffer_size) break; + if ((offset + 2u + uuid_len) > response_buffer_size) break; // store little_endian_store_16(response_buffer, offset, it.handle); - offset += 2; + offset += 2u; (void)memcpy(response_buffer + offset, it.uuid, uuid_len); offset += uuid_len; } - if (offset == 1){ + if (offset == 1u){ return setup_error_atribute_not_found(response_buffer, request_type, start_handle); } @@ -444,7 +444,7 @@ static uint16_t handle_find_information_request2(att_connection_t * att_connecti static uint16_t handle_find_information_request(att_connection_t * att_connection, uint8_t * request_buffer, uint16_t request_len, uint8_t * response_buffer, uint16_t response_buffer_size){ - if (request_len != 5) return setup_error_invalid_pdu(response_buffer, ATT_FIND_INFORMATION_REQUEST); + if (request_len != 5u) return setup_error_invalid_pdu(response_buffer, ATT_FIND_INFORMATION_REQUEST); uint16_t start_handle = little_endian_read_16(request_buffer, 1); uint16_t end_handle = little_endian_read_16(request_buffer, 3); @@ -467,20 +467,20 @@ static uint16_t handle_find_by_type_value_request(att_connection_t * att_connect uint8_t * response_buffer, uint16_t response_buffer_size){ UNUSED(att_connection); - if (request_len < 7) return setup_error_invalid_pdu(response_buffer, ATT_FIND_BY_TYPE_VALUE_REQUEST); + if (request_len < 7u) return setup_error_invalid_pdu(response_buffer, ATT_FIND_BY_TYPE_VALUE_REQUEST); // parse request uint16_t start_handle = little_endian_read_16(request_buffer, 1); uint16_t end_handle = little_endian_read_16(request_buffer, 3); uint16_t attribute_type = little_endian_read_16(request_buffer, 5); const uint8_t *attribute_value = &request_buffer[7]; - uint16_t attribute_len = request_len - 7; + uint16_t attribute_len = request_len - 7u; log_info("ATT_FIND_BY_TYPE_VALUE_REQUEST: from %04X to %04X, type %04X, value: ", start_handle, end_handle, attribute_type); log_info_hexdump(attribute_value, attribute_len); uint8_t request_type = ATT_FIND_BY_TYPE_VALUE_REQUEST; - if ((start_handle > end_handle) || (start_handle == 0)){ + if ((start_handle > end_handle) || (start_handle == 0u)){ return setup_error_invalid_handle(response_buffer, request_type, start_handle); } @@ -498,15 +498,15 @@ static uint16_t handle_find_by_type_value_request(att_connection_t * att_connect // close current tag, if within a group and a new service definition starts or we reach end of att db if (in_group && - ((it.handle == 0) || att_iterator_match_uuid16(&it, GATT_PRIMARY_SERVICE_UUID) || att_iterator_match_uuid16(&it, GATT_SECONDARY_SERVICE_UUID))){ + ((it.handle == 0u) || att_iterator_match_uuid16(&it, GATT_PRIMARY_SERVICE_UUID) || att_iterator_match_uuid16(&it, GATT_SECONDARY_SERVICE_UUID))){ log_info("End of group, handle 0x%04x", prev_handle); little_endian_store_16(response_buffer, offset, prev_handle); - offset += 2; + offset += 2u; in_group = 0; // check if space for another handle pair available - if ((offset + 4) > response_buffer_size){ + if ((offset + 4u) > response_buffer_size){ break; } } @@ -518,12 +518,12 @@ static uint16_t handle_find_by_type_value_request(att_connection_t * att_connect if (it.handle && att_iterator_match_uuid16(&it, attribute_type) && (attribute_len == it.value_len) && (memcmp(attribute_value, it.value, it.value_len) == 0)){ log_info("Begin of group, handle 0x%04x", it.handle); little_endian_store_16(response_buffer, offset, it.handle); - offset += 2; + offset += 2u; in_group = 1; } } - if (offset == 1){ + if (offset == 1u){ return setup_error_atribute_not_found(response_buffer, request_type, start_handle); } @@ -542,7 +542,7 @@ static uint16_t handle_read_by_type_request2(att_connection_t * att_connection, log_info_hexdump(attribute_type, attribute_type_len); uint8_t request_type = ATT_READ_BY_TYPE_REQUEST; - if ((start_handle > end_handle) || (start_handle == 0)){ + if ((start_handle > end_handle) || (start_handle == 0u)){ return setup_error_invalid_handle(response_buffer, request_type, start_handle); } @@ -557,7 +557,7 @@ static uint16_t handle_read_by_type_request2(att_connection_t * att_connection, while (att_iterator_has_next(&it)){ att_iterator_fetch_next(&it); - if ((it.handle == 0 ) || (it.handle > end_handle)) break; + if ((it.handle == 0u ) || (it.handle > end_handle)) break; if (it.handle < start_handle) continue; @@ -565,8 +565,8 @@ static uint16_t handle_read_by_type_request2(att_connection_t * att_connection, if (!att_iterator_match_uuid(&it, attribute_type, attribute_type_len)) continue; // skip handles that cannot be read but remember that there has been at least one - if ((it.flags & ATT_PROPERTY_READ) == 0) { - if (first_matching_but_unreadable_handle == 0) { + if ((it.flags & ATT_PROPERTY_READ) == 0u) { + if (first_matching_but_unreadable_handle == 0u) { first_matching_but_unreadable_handle = it.handle; } continue; @@ -574,7 +574,7 @@ static uint16_t handle_read_by_type_request2(att_connection_t * att_connection, // check security requirements error_code = att_validate_security(att_connection, ATT_READ, &it); - if (error_code != 0) break; + if (error_code != 0u) break; att_update_value_len(&it, att_connection->con_handle); @@ -585,13 +585,13 @@ static uint16_t handle_read_by_type_request2(att_connection_t * att_connection, #endif // check if value has same len as last one - uint16_t this_pair_len = 2 + it.value_len; - if ((offset > 1) && (pair_len != this_pair_len)) { + uint16_t this_pair_len = 2u + it.value_len; + if ((offset > 1u) && (pair_len != this_pair_len)) { break; } // first - if (offset == 1) { + if (offset == 1u) { pair_len = this_pair_len; response_buffer[offset] = pair_len; offset++; @@ -599,31 +599,31 @@ static uint16_t handle_read_by_type_request2(att_connection_t * att_connection, // space? if ((offset + pair_len) > response_buffer_size) { - if (offset > 2) break; - it.value_len = response_buffer_size - 4; - response_buffer[1] = 2 + it.value_len; + if (offset > 2u) break; + it.value_len = response_buffer_size - 4u; + response_buffer[1u] = 2u + it.value_len; } // store little_endian_store_16(response_buffer, offset, it.handle); - offset += 2; + offset += 2u; uint16_t bytes_copied = att_copy_value(&it, 0, response_buffer + offset, it.value_len, att_connection->con_handle); offset += bytes_copied; } // at least one attribute could be read - if (offset > 1){ + if (offset > 1u){ response_buffer[0] = ATT_READ_BY_TYPE_RESPONSE; return offset; } // first attribute had an error - if (error_code != 0){ + if (error_code != 0u){ return setup_error(response_buffer, request_type, start_handle, error_code); } // no other errors, but all found attributes had been non-readable - if (first_matching_but_unreadable_handle != 0){ + if (first_matching_but_unreadable_handle != 0u){ return setup_error_read_not_permitted(response_buffer, request_type, first_matching_but_unreadable_handle); } @@ -666,7 +666,7 @@ static uint16_t handle_read_request2(att_connection_t * att_connection, uint8_t } // check if handle can be read - if ((it.flags & ATT_PROPERTY_READ) == 0) { + if ((it.flags & ATT_PROPERTY_READ) == 0u) { return setup_error_read_not_permitted(response_buffer, request_type, handle); } @@ -694,7 +694,7 @@ static uint16_t handle_read_request2(att_connection_t * att_connection, uint8_t static uint16_t handle_read_request(att_connection_t * att_connection, uint8_t * request_buffer, uint16_t request_len, uint8_t * response_buffer, uint16_t response_buffer_size){ - if (request_len != 3) return setup_error_invalid_pdu(response_buffer, ATT_READ_REQUEST); + if (request_len != 3u) return setup_error_invalid_pdu(response_buffer, ATT_READ_REQUEST); uint16_t handle = little_endian_read_16(request_buffer, 1); return handle_read_request2(att_connection, response_buffer, response_buffer_size, handle); @@ -714,7 +714,7 @@ static uint16_t handle_read_blob_request2(att_connection_t * att_connection, uin } // check if handle can be read - if ((it.flags & ATT_PROPERTY_READ) == 0) { + if ((it.flags & ATT_PROPERTY_READ) == 0u) { return setup_error_read_not_permitted(response_buffer, request_type, handle); } @@ -749,7 +749,7 @@ static uint16_t handle_read_blob_request2(att_connection_t * att_connection, uin static uint16_t handle_read_blob_request(att_connection_t * att_connection, uint8_t * request_buffer, uint16_t request_len, uint8_t * response_buffer, uint16_t response_buffer_size){ - if (request_len != 5) return setup_error_invalid_pdu(response_buffer, ATT_READ_BLOB_REQUEST); + if (request_len != 5u) return setup_error_invalid_pdu(response_buffer, ATT_READ_BLOB_REQUEST); uint16_t handle = little_endian_read_16(request_buffer, 1); uint16_t value_offset = little_endian_read_16(request_buffer, 3); @@ -781,7 +781,7 @@ static uint16_t handle_read_multiple_request2(att_connection_t * att_connection, for (i=0;i> 1; + int num_handles = (request_len - 1u) >> 1u; return handle_read_multiple_request2(att_connection, response_buffer, response_buffer_size, num_handles, &request_buffer[1]); } @@ -860,7 +860,7 @@ static uint16_t handle_read_by_group_type_request2(att_connection_t * att_connec log_info_hexdump(attribute_type, attribute_type_len); uint8_t request_type = ATT_READ_BY_GROUP_TYPE_REQUEST; - if ((start_handle > end_handle) || (start_handle == 0)){ + if ((start_handle > end_handle) || (start_handle == 0u)){ return setup_error_invalid_handle(response_buffer, request_type, start_handle); } @@ -889,16 +889,16 @@ static uint16_t handle_read_by_group_type_request2(att_connection_t * att_connec // close current tag, if within a group and a new service definition starts or we reach end of att db if (in_group && - ((it.handle == 0) || att_iterator_match_uuid16(&it, GATT_PRIMARY_SERVICE_UUID) || att_iterator_match_uuid16(&it, GATT_SECONDARY_SERVICE_UUID))){ + ((it.handle == 0u) || att_iterator_match_uuid16(&it, GATT_PRIMARY_SERVICE_UUID) || att_iterator_match_uuid16(&it, GATT_SECONDARY_SERVICE_UUID))){ // log_info("End of group, handle 0x%04x, val_len: %u", prev_handle, pair_len - 4); little_endian_store_16(response_buffer, offset, group_start_handle); - offset += 2; + offset += 2u; little_endian_store_16(response_buffer, offset, prev_handle); - offset += 2; + offset += 2u; (void)memcpy(response_buffer + offset, group_start_value, - pair_len - 4); - offset += pair_len - 4; + pair_len - 4u); + offset += pair_len - 4u; in_group = 0; // check if space for another handle pair available @@ -915,8 +915,8 @@ static uint16_t handle_read_by_group_type_request2(att_connection_t * att_connec if (it.handle && att_iterator_match_uuid(&it, attribute_type, attribute_type_len)) { // check if value has same len as last one - uint16_t this_pair_len = 4 + it.value_len; - if (offset > 1){ + uint16_t this_pair_len = 4u + it.value_len; + if (offset > 1u){ if (this_pair_len != pair_len) { break; } @@ -925,7 +925,7 @@ static uint16_t handle_read_by_group_type_request2(att_connection_t * att_connec // log_info("Begin of group, handle 0x%04x", it.handle); // first - if (offset == 1) { + if (offset == 1u) { pair_len = this_pair_len; response_buffer[offset] = this_pair_len; offset++; @@ -937,7 +937,7 @@ static uint16_t handle_read_by_group_type_request2(att_connection_t * att_connec } } - if (offset == 1){ + if (offset == 1u){ return setup_error_atribute_not_found(response_buffer, request_type, start_handle); } @@ -970,7 +970,7 @@ static uint16_t handle_write_request(att_connection_t * att_connection, uint8_t UNUSED(response_buffer_size); - if (request_len < 3) return setup_error_invalid_pdu(response_buffer, ATT_WRITE_REQUEST); + if (request_len < 3u) return setup_error_invalid_pdu(response_buffer, ATT_WRITE_REQUEST); uint8_t request_type = ATT_WRITE_REQUEST; @@ -983,10 +983,10 @@ static uint16_t handle_write_request(att_connection_t * att_connection, uint8_t if (att_write_callback == NULL) { return setup_error_write_not_permitted(response_buffer, request_type, handle); } - if ((it.flags & ATT_PROPERTY_WRITE) == 0) { + if ((it.flags & ATT_PROPERTY_WRITE) == 0u) { return setup_error_write_not_permitted(response_buffer, request_type, handle); } - if ((it.flags & ATT_PROPERTY_DYNAMIC) == 0) { + if ((it.flags & ATT_PROPERTY_DYNAMIC) == 0u) { return setup_error_write_not_permitted(response_buffer, request_type, handle); } // check security requirements @@ -995,7 +995,7 @@ static uint16_t handle_write_request(att_connection_t * att_connection, uint8_t return setup_error(response_buffer, request_type, handle, error_code); } att_persistent_ccc_cache(&it); - error_code = (*att_write_callback)(att_connection->con_handle, handle, ATT_TRANSACTION_MODE_NONE, 0, request_buffer + 3, request_len - 3); + error_code = (*att_write_callback)(att_connection->con_handle, handle, ATT_TRANSACTION_MODE_NONE, 0u, request_buffer + 3u, request_len - 3u); #ifdef ENABLE_ATT_DELAYED_RESPONSE if (error_code == ATT_ERROR_WRITE_RESPONSE_PENDING) return ATT_INTERNAL_WRITE_RESPONSE_PENDING; @@ -1015,7 +1015,7 @@ static uint16_t handle_prepare_write_request(att_connection_t * att_connection, uint8_t request_type = ATT_PREPARE_WRITE_REQUEST; - if (request_len < 5) return setup_error_invalid_pdu(response_buffer, request_type); + if (request_len < 5u) return setup_error_invalid_pdu(response_buffer, request_type); uint16_t handle = little_endian_read_16(request_buffer, 1); uint16_t offset = little_endian_read_16(request_buffer, 3); @@ -1026,10 +1026,10 @@ static uint16_t handle_prepare_write_request(att_connection_t * att_connection, if (att_find_handle(&it, handle) == 0) { return setup_error_invalid_handle(response_buffer, request_type, handle); } - if ((it.flags & ATT_PROPERTY_WRITE) == 0) { + if ((it.flags & ATT_PROPERTY_WRITE) == 0u) { return setup_error_write_not_permitted(response_buffer, request_type, handle); } - if ((it.flags & ATT_PROPERTY_DYNAMIC) == 0) { + if ((it.flags & ATT_PROPERTY_DYNAMIC) == 0u) { return setup_error_write_not_permitted(response_buffer, request_type, handle); } // check security requirements @@ -1038,7 +1038,7 @@ static uint16_t handle_prepare_write_request(att_connection_t * att_connection, return setup_error(response_buffer, request_type, handle, error_code); } - error_code = (*att_write_callback)(att_connection->con_handle, handle, ATT_TRANSACTION_MODE_ACTIVE, offset, request_buffer + 5, request_len - 5); + error_code = (*att_write_callback)(att_connection->con_handle, handle, ATT_TRANSACTION_MODE_ACTIVE, offset, request_buffer + 5u, request_len - 5u); switch (error_code){ case 0: break; @@ -1078,7 +1078,7 @@ static uint16_t handle_execute_write_request(att_connection_t * att_connection, uint8_t request_type = ATT_EXECUTE_WRITE_REQUEST; - if (request_len < 2) return setup_error_invalid_pdu(response_buffer, request_type); + if (request_len < 2u) return setup_error_invalid_pdu(response_buffer, request_type); if (att_write_callback == NULL) { return setup_error_write_not_permitted(response_buffer, request_type, 0); @@ -1113,7 +1113,7 @@ static uint16_t handle_execute_write_request(att_connection_t * att_connection, // "No Error Response or Write Response shall be sent in response to this command" static void handle_write_command(att_connection_t * att_connection, uint8_t * request_buffer, uint16_t request_len, uint16_t required_flags){ - if (request_len < 3) return; + if (request_len < 3u) return; uint16_t handle = little_endian_read_16(request_buffer, 1); if (att_write_callback == NULL) return; @@ -1121,11 +1121,11 @@ static void handle_write_command(att_connection_t * att_connection, uint8_t * re att_iterator_t it; int ok = att_find_handle(&it, handle); if (!ok) return; - if ((it.flags & ATT_PROPERTY_DYNAMIC) == 0) return; - if ((it.flags & required_flags) == 0) return; + if ((it.flags & ATT_PROPERTY_DYNAMIC) == 0u) return; + if ((it.flags & required_flags) == 0u) return; if (att_validate_security(att_connection, ATT_WRITE, &it)) return; att_persistent_ccc_cache(&it); - (*att_write_callback)(att_connection->con_handle, handle, ATT_TRANSACTION_MODE_NONE, 0, request_buffer + 3, request_len - 3); + (*att_write_callback)(att_connection->con_handle, handle, ATT_TRANSACTION_MODE_NONE, 0u, request_buffer + 3u, request_len - 3u); } // MARK: helper for ATT_HANDLE_VALUE_NOTIFICATION and ATT_HANDLE_VALUE_INDICATION @@ -1135,11 +1135,11 @@ static uint16_t prepare_handle_value(att_connection_t * att_connection, uint16_t value_len, uint8_t * response_buffer){ little_endian_store_16(response_buffer, 1, handle); - if (value_len > (att_connection->mtu - 3)){ - value_len = att_connection->mtu - 3; + if (value_len > (att_connection->mtu - 3u)){ + value_len = att_connection->mtu - 3u; } (void)memcpy(&response_buffer[3], value, value_len); - return value_len + 3; + return value_len + 3u; } // MARK: ATT_HANDLE_VALUE_NOTIFICATION 0x1b @@ -1216,7 +1216,7 @@ uint16_t att_handle_request(att_connection_t * att_connection, #endif default: log_info("Unhandled ATT Command: %02X, DATA: ", request_buffer[0]); - log_info_hexdump(&request_buffer[9], request_len-9); + log_info_hexdump(&request_buffer[9u], request_len-9u); break; } return response_len; @@ -1239,7 +1239,7 @@ bool gatt_server_get_get_handle_range_for_service_with_uuid16(uint16_t uuid16, u // close current tag, if within a group and a new service definition starts or we reach end of att db if (in_group && - ((it.handle == 0) || new_service_started)){ + ((it.handle == 0u) || new_service_started)){ *end_handle = prev_handle; return true; } @@ -1264,7 +1264,7 @@ uint16_t gatt_server_get_value_handle_for_characteristic_with_uuid16(uint16_t st att_iterator_fetch_next(&it); if (it.handle && (it.handle < start_handle)) continue; if (it.handle > end_handle) break; // (1) - if (it.handle == 0) break; + if (it.handle == 0u) break; if (att_iterator_match_uuid16(&it, uuid16)) return it.handle; } return 0; @@ -1278,7 +1278,7 @@ uint16_t gatt_server_get_descriptor_handle_for_characteristic_with_uuid16(uint16 att_iterator_fetch_next(&it); if (it.handle && (it.handle < start_handle)) continue; if (it.handle > end_handle) break; // (1) - if (it.handle == 0) break; + if (it.handle == 0u) break; if (att_iterator_match_uuid16(&it, characteristic_uuid16)){ characteristic_found = 1; continue; @@ -1323,7 +1323,7 @@ int gatt_server_get_get_handle_range_for_service_with_uuid128(const uint8_t * uu // close current tag, if within a group and a new service definition starts or we reach end of att db if (in_group && - ((it.handle == 0) || new_service_started)){ + ((it.handle == 0u) || new_service_started)){ *end_handle = prev_handle; return 1; } @@ -1350,7 +1350,7 @@ uint16_t gatt_server_get_value_handle_for_characteristic_with_uuid128(uint16_t s att_iterator_fetch_next(&it); if (it.handle && (it.handle < start_handle)) continue; if (it.handle > end_handle) break; // (1) - if (it.handle == 0) break; + if (it.handle == 0u) break; if (att_iterator_match_uuid(&it, attribute_value, 16)) return it.handle; } return 0; @@ -1367,7 +1367,7 @@ uint16_t gatt_server_get_client_configuration_handle_for_characteristic_with_uui att_iterator_fetch_next(&it); if (it.handle && (it.handle < start_handle)) continue; if (it.handle > end_handle) break; // (1) - if (it.handle == 0) break; + if (it.handle == 0u) break; if (att_iterator_match_uuid(&it, attribute_value, 16)){ characteristic_found = 1; continue; diff --git a/src/ble/att_db_util.c b/src/ble/att_db_util.c index 8847ac9a6..2bcddb4e5 100644 --- a/src/ble/att_db_util.c +++ b/src/ble/att_db_util.c @@ -68,7 +68,7 @@ static uint16_t att_db_hash_len; static void att_db_util_set_end_tag(void){ // end tag att_db[att_db_size] = 0; - att_db[att_db_size+1] = 0; + att_db[att_db_size+1u] = 0u; } void att_db_util_init(void){ @@ -121,7 +121,7 @@ static bool att_db_util_hash_include_without_value(uint16_t uuid16){ * @returns TRUE if space is available */ static int att_db_util_assert_space(uint16_t size){ - size += 2; // for end tag + size += 2u; // for end tag uint16_t required_size = att_db_size + size; if (required_size <= att_db_max_size) return 1; #ifdef HAVE_MALLOC @@ -149,41 +149,41 @@ static int att_db_util_assert_space(uint16_t size){ // db endds with 0x00 0x00 static void att_db_util_add_attribute_uuid16(uint16_t uuid16, uint16_t flags, uint8_t * data, uint16_t data_len){ - int size = 2 + 2 + 2 + 2 + data_len; + int size = 2u + 2u + 2u + 2u + data_len; if (!att_db_util_assert_space(size)) return; little_endian_store_16(att_db, att_db_size, size); - att_db_size += 2; + att_db_size += 2u; little_endian_store_16(att_db, att_db_size, flags); - att_db_size += 2; + att_db_size += 2u; little_endian_store_16(att_db, att_db_size, att_db_next_handle); - att_db_size += 2; + att_db_size += 2u; att_db_next_handle++; little_endian_store_16(att_db, att_db_size, uuid16); - att_db_size += 2; + att_db_size += 2u; (void)memcpy(&att_db[att_db_size], data, data_len); att_db_size += data_len; att_db_util_set_end_tag(); if (att_db_util_hash_include_with_value(uuid16)){ - att_db_hash_len += 4 + data_len; + att_db_hash_len += 4u + data_len; } else if (att_db_util_hash_include_without_value(uuid16)){ - att_db_hash_len += 4; + att_db_hash_len += 4u; } } static void att_db_util_add_attribute_uuid128(const uint8_t * uuid128, uint16_t flags, uint8_t * data, uint16_t data_len){ - int size = 2 + 2 + 2 + 16 + data_len; + int size = 2u + 2u + 2u + 16u + data_len; if (!att_db_util_assert_space(size)) return; flags |= ATT_PROPERTY_UUID128; little_endian_store_16(att_db, att_db_size, size); - att_db_size += 2; + att_db_size += 2u; little_endian_store_16(att_db, att_db_size, flags); - att_db_size += 2; + att_db_size += 2u; little_endian_store_16(att_db, att_db_size, att_db_next_handle); - att_db_size += 2; + att_db_size += 2u; att_db_next_handle++; reverse_128(uuid128, &att_db[att_db_size]); - att_db_size += 16; + att_db_size += 16u; (void)memcpy(&att_db[att_db_size], data, data_len); att_db_size += data_len; att_db_util_set_end_tag(); @@ -234,17 +234,17 @@ uint16_t att_db_util_add_included_service_uuid16(uint16_t start_group_handle, ui static void att_db_util_add_client_characteristic_configuration(uint16_t flags){ uint8_t buffer[2]; // drop permission for read (0xc00), keep write permissions (0x0091) - flags = (flags & 0x1f391) | ATT_PROPERTY_READ | ATT_PROPERTY_WRITE | ATT_PROPERTY_DYNAMIC; + flags = (flags & 0x1f391u) | ATT_PROPERTY_READ | ATT_PROPERTY_WRITE | ATT_PROPERTY_DYNAMIC; little_endian_store_16(buffer, 0, 0); att_db_util_add_attribute_uuid16(GATT_CLIENT_CHARACTERISTICS_CONFIGURATION, flags, buffer, 2); } static uint16_t att_db_util_encode_permissions(uint16_t properties, uint8_t read_permission, uint8_t write_permission){ // drop Broadcast (0x01), Notify (0x10), Indicate (0x20), Extended Attributes (0x80) - not used for flags - uint16_t flags = properties & 0xfff4e; + uint16_t flags = properties & 0xfff4eu; // if encryption requested, set encryption key size to 16 if ((read_permission > ATT_SECURITY_NONE) || (write_permission > ATT_SECURITY_NONE)){ - flags |= 0xf000; + flags |= 0xf000u; } // map SC requirement if (read_permission == ATT_SECURITY_AUTHENTICATED_SC){ @@ -256,16 +256,16 @@ static uint16_t att_db_util_encode_permissions(uint16_t properties, uint8_t read flags |= ATT_PROPERTY_WRITE_PERMISSION_SC; } // encode read/write security levels - if (read_permission & 1){ + if (read_permission & 1u){ flags |= ATT_PROPERTY_READ_PERMISSION_BIT_0; } - if (read_permission & 2){ + if (read_permission & 2u){ flags |= ATT_PROPERTY_READ_PERMISSION_BIT_1; } - if (write_permission & 1){ + if (write_permission & 1u){ flags |= ATT_PROPERTY_WRITE_PERMISSION_BIT_0; } - if (write_permission & 2){ + if (write_permission & 2u){ flags |= ATT_PROPERTY_WRITE_PERMISSION_BIT_1; } return flags; @@ -274,7 +274,7 @@ static uint16_t att_db_util_encode_permissions(uint16_t properties, uint8_t read uint16_t att_db_util_add_characteristic_uuid16(uint16_t uuid16, uint16_t properties, uint8_t read_permission, uint8_t write_permission, uint8_t * data, uint16_t data_len){ uint8_t buffer[5]; buffer[0] = properties; - little_endian_store_16(buffer, 1, att_db_next_handle + 1); + little_endian_store_16(buffer, 1u, att_db_next_handle + 1u); little_endian_store_16(buffer, 3, uuid16); att_db_util_add_attribute_uuid16(GATT_CHARACTERISTICS_UUID, ATT_PROPERTY_READ, buffer, sizeof(buffer)); uint16_t flags = att_db_util_encode_permissions(properties, read_permission, write_permission); @@ -289,7 +289,7 @@ uint16_t att_db_util_add_characteristic_uuid16(uint16_t uuid16, uint16_t propert uint16_t att_db_util_add_characteristic_uuid128(const uint8_t * uuid128, uint16_t properties, uint8_t read_permission, uint8_t write_permission, uint8_t * data, uint16_t data_len){ uint8_t buffer[19]; buffer[0] = properties; - little_endian_store_16(buffer, 1, att_db_next_handle + 1); + little_endian_store_16(buffer, 1u, att_db_next_handle + 1u); reverse_128(uuid128, &buffer[3]); att_db_util_add_attribute_uuid16(GATT_CHARACTERISTICS_UUID, ATT_PROPERTY_READ, buffer, sizeof(buffer)); uint16_t flags = att_db_util_encode_permissions(properties, read_permission, write_permission); @@ -320,7 +320,7 @@ uint8_t * att_db_util_get_address(void){ } uint16_t att_db_util_get_size(void){ - return att_db_size + 2; // end tag + return att_db_size + 2u; // end tag } static uint8_t * att_db_util_hash_att_ptr; @@ -333,11 +333,11 @@ static void att_db_util_hash_fetch_next_attribute(void){ btstack_assert(size != 0); UNUSED(size); uint16_t flags = little_endian_read_16(att_db_util_hash_att_ptr, 2); - if ((flags & ATT_PROPERTY_UUID128) == 0) { + if ((flags & ATT_PROPERTY_UUID128) == 0u) { uint16_t uuid16 = little_endian_read_16(att_db_util_hash_att_ptr, 6); if (att_db_util_hash_include_with_value(uuid16)){ att_db_util_hash_offset = 4; - att_db_util_hash_bytes_available = size - 4; + att_db_util_hash_bytes_available = size - 4u; return; } else if (att_db_util_hash_include_without_value(uuid16)){ att_db_util_hash_offset = 4; @@ -361,7 +361,7 @@ void att_db_util_hash_init(void){ uint8_t att_db_util_hash_get_next(void){ // find next hashable data blob - if (att_db_util_hash_bytes_available == 0){ + if (att_db_util_hash_bytes_available == 0u){ att_db_util_hash_fetch_next_attribute(); } @@ -370,7 +370,7 @@ uint8_t att_db_util_hash_get_next(void){ att_db_util_hash_bytes_available--; // go to next attribute if blob used up - if (att_db_util_hash_bytes_available == 0){ + if (att_db_util_hash_bytes_available == 0u){ uint16_t size = little_endian_read_16(att_db_util_hash_att_ptr, 0); att_db_util_hash_att_ptr += size; } diff --git a/src/ble/att_dispatch.c b/src/ble/att_dispatch.c index 520757523..160698695 100644 --- a/src/ble/att_dispatch.c +++ b/src/ble/att_dispatch.c @@ -68,7 +68,7 @@ static void att_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *pa switch (packet_type){ case ATT_DATA_PACKET: // odd PDUs are sent from server to client - even PDUs are sent from client to server - index = packet[0] & 1; + index = packet[0u] & 1u; // log_info("att_data_packet with opcode 0x%x", packet[0]); if (!subscriptions[index].packet_handler) return; subscriptions[index].packet_handler(packet_type, handle, packet, size); @@ -77,12 +77,12 @@ static void att_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *pa if (packet[0] != L2CAP_EVENT_CAN_SEND_NOW) break; can_send_now_pending = 0; for (i = 0; i < ATT_MAX; i++){ - index = (att_round_robin + i) & 1; + index = (att_round_robin + i) & 1u; if (subscriptions[index].packet_handler && subscriptions[index].waiting_for_can_send){ subscriptions[index].waiting_for_can_send = 0; subscriptions[index].packet_handler(packet_type, handle, packet, size); // fairness: prioritize next service - att_round_robin = (index + 1) % ATT_MAX; + att_round_robin = (index + 1u) % ATT_MAX; // stop if client cannot send anymore if (!hci_can_send_acl_le_packet_now()) break; } @@ -170,7 +170,7 @@ static void emit_mtu_exchange_complete(btstack_packet_handler_t packet_handler, if (!packet_handler) return; uint8_t packet[6]; packet[0] = ATT_EVENT_MTU_EXCHANGE_COMPLETE; - packet[1] = sizeof(packet) - 2; + packet[1] = sizeof(packet) - 2u; little_endian_store_16(packet, 2, con_handle); little_endian_store_16(packet, 4, new_mtu); packet_handler(HCI_EVENT_PACKET, con_handle, packet, 1); diff --git a/src/ble/att_server.c b/src/ble/att_server.c index 2a20f924f..1be4befcc 100644 --- a/src/ble/att_server.c +++ b/src/ble/att_server.c @@ -164,7 +164,7 @@ static void att_handle_value_indication_notify_client(uint8_t status, uint16_t c uint8_t event[7]; int pos = 0; event[pos++] = ATT_EVENT_HANDLE_VALUE_INDICATION_COMPLETE; - event[pos++] = sizeof(event) - 2; + event[pos++] = sizeof(event) - 2u; event[pos++] = status; little_endian_store_16(event, pos, client_handle); pos += 2; @@ -192,7 +192,7 @@ static void att_emit_mtu_event(hci_con_handle_t con_handle, uint16_t mtu){ uint8_t event[6]; int pos = 0; event[pos++] = ATT_EVENT_MTU_EXCHANGE_COMPLETE; - event[pos++] = sizeof(event) - 2; + event[pos++] = sizeof(event) - 2u; little_endian_store_16(event, pos, con_handle); pos += 2; little_endian_store_16(event, pos, mtu); @@ -216,7 +216,7 @@ static void att_emit_connected_event(att_server_t * att_server){ uint8_t event[11]; int pos = 0; event[pos++] = ATT_EVENT_CONNECTED; - event[pos++] = sizeof(event) - 2; + event[pos++] = sizeof(event) - 2u; event[pos++] = att_server->peer_addr_type; reverse_bd_addr(att_server->peer_address, &event[pos]); pos += 6; @@ -232,7 +232,7 @@ static void att_emit_disconnected_event(uint16_t con_handle){ uint8_t event[4]; int pos = 0; event[pos++] = ATT_EVENT_DISCONNECTED; - event[pos++] = sizeof(event) - 2; + event[pos++] = sizeof(event) - 2u; little_endian_store_16(event, pos, con_handle); pos += 2; @@ -532,7 +532,7 @@ static int att_server_process_validated_request(att_server_t * att_server){ #endif // intercept "insufficient authorization" for authenticated connections to allow for user authorization - if ((att_response_size >= 4) + if ((att_response_size >= 4u) && (att_response_buffer[0] == ATT_ERROR_RESPONSE) && (att_response_buffer[4] == ATT_ERROR_INSUFFICIENT_AUTHORIZATION) && (att_server->connection.authenticated)){ @@ -551,7 +551,7 @@ static int att_server_process_validated_request(att_server_t * att_server){ } att_server->state = ATT_SERVER_IDLE; - if (att_response_size == 0) { + if (att_response_size == 0u) { l2cap_release_packet_buffer(); return 0; } @@ -840,7 +840,7 @@ static void att_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *pa // --------------------- // persistent CCC writes static uint32_t att_server_persistent_ccc_tag_for_index(uint8_t index){ - return ('B' << 24) | ('T' << 16) | ('C' << 8) | index; + return ('B' << 24u) | ('T' << 16u) | ('C' << 8u) | index; } static void att_server_persistent_ccc_write(hci_con_handle_t con_handle, uint16_t att_handle, uint16_t value){ @@ -880,7 +880,7 @@ static void att_server_persistent_ccc_write(hci_con_handle_t con_handle, uint16_ highest_seq_nr = entry.seq_nr; } // find entry with lowest seq nr - if ((tag_for_lowest_seq_nr == 0) || (entry.seq_nr < lowest_seq_nr)){ + if ((tag_for_lowest_seq_nr == 0u) || (entry.seq_nr < lowest_seq_nr)){ tag_for_lowest_seq_nr = tag; lowest_seq_nr = entry.seq_nr; } @@ -896,7 +896,7 @@ static void att_server_persistent_ccc_write(hci_con_handle_t con_handle, uint16_ return; } entry.value = value; - entry.seq_nr = highest_seq_nr + 1; + entry.seq_nr = highest_seq_nr + 1u; log_info("CCC Index %u: Store", index); int result = tlv_impl->store_tag(tlv_context, tag, (const uint8_t *) &entry, sizeof(persistent_ccc_entry_t)); if (result != 0){ @@ -912,7 +912,7 @@ static void att_server_persistent_ccc_write(hci_con_handle_t con_handle, uint16_ log_info("tag_for_empty %"PRIx32", tag_for_lowest_seq_nr %"PRIx32, tag_for_empty, tag_for_lowest_seq_nr); - if (value == 0){ + if (value == 0u){ // done return; } @@ -927,7 +927,7 @@ static void att_server_persistent_ccc_write(hci_con_handle_t con_handle, uint16_ return; } // store ccc tag - entry.seq_nr = highest_seq_nr + 1; + entry.seq_nr = highest_seq_nr + 1u; entry.device_index = le_device_index; entry.att_handle = att_handle; entry.value = value; @@ -1071,7 +1071,7 @@ static int att_server_write_callback(hci_con_handle_t con_handle, uint16_t attri } // track CCC writes - if (att_is_persistent_ccc(attribute_handle) && (offset == 0) && (buffer_size == 2)){ + if (att_is_persistent_ccc(attribute_handle) && (offset == 0u) && (buffer_size == 2u)){ att_server_persistent_ccc_write(con_handle, attribute_handle, little_endian_read_16(buffer, 0)); } diff --git a/src/ble/gatt-service/cycling_power_service_server.c b/src/ble/gatt-service/cycling_power_service_server.c index 1a6a3bac3..9ea15add9 100644 --- a/src/ble/gatt-service/cycling_power_service_server.c +++ b/src/ble/gatt-service/cycling_power_service_server.c @@ -226,42 +226,42 @@ static uint16_t cycling_power_service_read_callback(hci_con_handle_t con_handle, cycling_power_t * instance = &cycling_power; if (attribute_handle == instance->measurement_client_configuration_descriptor_handle){ - if (buffer && (buffer_size >= 2)){ + if (buffer && (buffer_size >= 2u)){ little_endian_store_16(buffer, 0, instance->measurement_client_configuration_descriptor_notify); } return 2; } if (attribute_handle == instance->measurement_server_configuration_descriptor_handle){ - if (buffer && (buffer_size >= 2)){ + if (buffer && (buffer_size >= 2u)){ little_endian_store_16(buffer, 0, instance->measurement_server_configuration_descriptor_broadcast); } return 2; } if (attribute_handle == instance->vector_client_configuration_descriptor_handle){ - if (buffer && (buffer_size >= 2)){ + if (buffer && (buffer_size >= 2u)){ little_endian_store_16(buffer, 0, instance->vector_client_configuration_descriptor_notify); } return 2; } if (attribute_handle == instance->control_point_client_configuration_descriptor_handle){ - if (buffer && (buffer_size >= 2)){ + if (buffer && (buffer_size >= 2u)){ little_endian_store_16(buffer, 0, instance->control_point_client_configuration_descriptor_indicate); } return 2; } if (attribute_handle == instance->feature_value_handle){ - if (buffer && (buffer_size >= 4)){ + if (buffer && (buffer_size >= 4u)){ little_endian_store_32(buffer, 0, instance->feature_flags); } return 4; } if (attribute_handle == instance->sensor_location_value_handle){ - if (buffer && (buffer_size >= 1)){ + if (buffer && (buffer_size >= 1u)){ buffer[0] = instance->sensor_location; } return 1; @@ -271,7 +271,7 @@ static uint16_t cycling_power_service_read_callback(hci_con_handle_t con_handle, static int has_feature(cycling_power_feature_flag_t feature){ cycling_power_t * instance = &cycling_power; - return (instance->feature_flags & (1 << feature)) != 0; + return (instance->feature_flags & (1u << feature)) != 0u; } static int cycling_power_vector_instantaneous_measurement_direction(void){ @@ -353,7 +353,7 @@ static void cycling_power_service_vector_can_send_now(void * context){ value[pos++] = vector_flags; int i; for (i = CP_VECTOR_FLAG_CRANK_REVOLUTION_DATA_PRESENT; i <= CP_VECTOR_FLAG_INSTANTANEOUS_MEASUREMENT_DIRECTION; i++){ - if ((vector_flags & (1 << i)) == 0) continue; + if ((vector_flags & (1u << i)) == 0u) continue; switch ((cycling_power_vector_flag_t) i){ case CP_VECTOR_FLAG_CRANK_REVOLUTION_DATA_PRESENT: little_endian_store_16(value, pos, instance->cumulative_crank_revolutions); @@ -364,13 +364,13 @@ static void cycling_power_service_vector_can_send_now(void * context){ case CP_VECTOR_FLAG_INSTANTANEOUS_FORCE_MAGNITUDE_ARRAY_PRESENT:{ uint16_t att_mtu = att_server_get_mtu(instance->con_handle); uint16_t bytes_left = 0; - if (att_mtu > (pos + 3)){ - bytes_left = btstack_min(sizeof(value), att_mtu - 3 - pos); + if (att_mtu > (pos + 3u)){ + bytes_left = btstack_min(sizeof(value), att_mtu - 3u - pos); } - while ((bytes_left > 2) && instance->force_magnitude_count){ + while ((bytes_left > 2u) && instance->force_magnitude_count){ little_endian_store_16(value, pos, instance->vector_instantaneous_force_magnitude_newton_array[0]); pos += 2; - bytes_left -= 2; + bytes_left -= 2u; instance->vector_instantaneous_force_magnitude_newton_array++; instance->force_magnitude_count--; } @@ -379,14 +379,14 @@ static void cycling_power_service_vector_can_send_now(void * context){ case CP_VECTOR_FLAG_INSTANTANEOUS_TORQUE_MAGNITUDE_ARRAY_PRESENT:{ uint16_t att_mtu = att_server_get_mtu(instance->con_handle); uint16_t bytes_left = 0; - if (att_mtu > (pos + 3)){ - bytes_left = btstack_min(sizeof(value), att_mtu - 3 - pos); + if (att_mtu > (pos + 3u)){ + bytes_left = btstack_min(sizeof(value), att_mtu - 3u - pos); } - while ((bytes_left > 2) && instance->torque_magnitude_count){ + while ((bytes_left > 2u) && instance->torque_magnitude_count){ little_endian_store_16(value, pos, instance->vector_instantaneous_torque_magnitude_newton_per_m_array[0]); pos += 2; - bytes_left -= 2; + bytes_left -= 2u; instance->vector_instantaneous_torque_magnitude_newton_per_m_array++; instance->torque_magnitude_count--; } @@ -489,7 +489,7 @@ static int cycling_power_store_measurement_flag_value(cycling_power_t * instance static int cycling_power_store_measurement(cycling_power_t * instance, uint8_t * value, uint16_t max_value_size){ - if (max_value_size < 4) return 0; + if (max_value_size < 4u) return 0u; if (!instance) return 0; uint16_t measurement_flags = cycling_power_service_get_measurement_flags(instance); @@ -501,7 +501,7 @@ static int cycling_power_store_measurement(cycling_power_t * instance, uint8_t * int flag_index; uint16_t bytes_left = max_value_size - pos; for (flag_index = 0; flag_index < CP_MEASUREMENT_FLAG_RESERVED; flag_index++){ - if ((measurement_flags & (1 << flag_index)) == 0) continue; + if ((measurement_flags & (1u << flag_index)) == 0u) continue; cycling_power_measurement_flag_t flag = (cycling_power_measurement_flag_t) flag_index; uint16_t value_size = cycling_power_measurement_flag_value_size(flag); if (value_size > bytes_left ) return pos; @@ -513,7 +513,7 @@ static int cycling_power_store_measurement(cycling_power_t * instance, uint8_t * } int cycling_power_get_measurement_adv(uint16_t adv_interval, uint8_t * broadcast_adv, uint16_t max_value_size){ - if (max_value_size < 12) return 0; + if (max_value_size < 12u) return 0u; cycling_power_t * instance = &cycling_power; int pos = 0; // adv flags @@ -688,7 +688,7 @@ static int cycling_power_service_write_callback(hci_con_handle_t con_handle, uin // printf("cycling_power_service_write_callback: attr handle 0x%02x\n", attribute_handle); if (attribute_handle == instance->measurement_client_configuration_descriptor_handle){ - if (buffer_size < 2){ + if (buffer_size < 2u){ return ATT_ERROR_INVALID_OFFSET; } instance->measurement_client_configuration_descriptor_notify = little_endian_read_16(buffer, 0); @@ -698,7 +698,7 @@ static int cycling_power_service_write_callback(hci_con_handle_t con_handle, uin } if (attribute_handle == instance->measurement_server_configuration_descriptor_handle){ - if (buffer_size < 2){ + if (buffer_size < 2u){ return ATT_ERROR_INVALID_OFFSET; } instance->measurement_server_configuration_descriptor_broadcast = little_endian_read_16(buffer, 0); @@ -706,7 +706,7 @@ static int cycling_power_service_write_callback(hci_con_handle_t con_handle, uin uint8_t event[5]; int index = 0; event[index++] = HCI_EVENT_GATTSERVICE_META; - event[index++] = sizeof(event) - 2; + event[index++] = sizeof(event) - 2u; if (instance->measurement_server_configuration_descriptor_broadcast){ event[index++] = GATTSERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_START; @@ -722,7 +722,7 @@ static int cycling_power_service_write_callback(hci_con_handle_t con_handle, uin } if (attribute_handle == instance->vector_client_configuration_descriptor_handle){ - if (buffer_size < 2){ + if (buffer_size < 2u){ return ATT_ERROR_INVALID_OFFSET; } instance->con_handle = con_handle; @@ -749,7 +749,7 @@ static int cycling_power_service_write_callback(hci_con_handle_t con_handle, uin } if (attribute_handle == instance->control_point_client_configuration_descriptor_handle){ - if (buffer_size < 2){ + if (buffer_size < 2u){ return ATT_ERROR_INVALID_OFFSET; } instance->control_point_client_configuration_descriptor_indicate = little_endian_read_16(buffer, 0); @@ -759,7 +759,7 @@ static int cycling_power_service_write_callback(hci_con_handle_t con_handle, uin } if (attribute_handle == instance->feature_value_handle){ - if (buffer_size < 4){ + if (buffer_size < 4u){ return ATT_ERROR_INVALID_OFFSET; } instance->feature_flags = little_endian_read_32(buffer, 0); @@ -767,8 +767,8 @@ static int cycling_power_service_write_callback(hci_con_handle_t con_handle, uin } if (attribute_handle == instance->control_point_value_handle){ - if (instance->control_point_client_configuration_descriptor_indicate == 0) return CYCLING_POWER_ERROR_CODE_CCC_DESCRIPTOR_IMPROPERLY_CONFIGURED; - if (instance->w4_indication_complete != 0){ + if (instance->control_point_client_configuration_descriptor_indicate == 0u) return CYCLING_POWER_ERROR_CODE_CCC_DESCRIPTOR_IMPROPERLY_CONFIGURED; + if (instance->w4_indication_complete != 0u){ return CYCLING_POWER_ERROR_CODE_PROCEDURE_ALREADY_IN_PROGRESS; } int pos = 0; @@ -864,7 +864,7 @@ static int cycling_power_service_write_callback(hci_con_handle_t con_handle, uin uint8_t event[7]; int index = 0; event[index++] = HCI_EVENT_GATTSERVICE_META; - event[index++] = sizeof(event) - 2; + event[index++] = sizeof(event) - 2u; event[index++] = GATTSERVICE_SUBEVENT_CYCLING_POWER_START_CALIBRATION; little_endian_store_16(event, index, con_handle); index += 2; @@ -885,7 +885,7 @@ static int cycling_power_service_write_callback(hci_con_handle_t con_handle, uin uint16_t index = 0; for (i = 0; i < CP_MASK_BIT_RESERVED; i++){ - uint8_t clear_bit = (mask_bitmap & (1 << i)) ? 1 : 0; + uint8_t clear_bit = (mask_bitmap & (1u << i)) ? 1u : 0u; masked_measurement_flags &= ~(clear_bit << index); index++; @@ -981,7 +981,7 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe uint8_t event[5]; int index = 0; event[index++] = HCI_EVENT_GATTSERVICE_META; - event[index++] = sizeof(event) - 2; + event[index++] = sizeof(event) - 2u; event[index++] = GATTSERVICE_SUBEVENT_CYCLING_POWER_BROADCAST_STOP; little_endian_store_16(event, index, con_handle); @@ -1108,7 +1108,7 @@ void cycling_power_service_server_add_crank_revolution(uint16_t crank_revolution void cycling_power_service_add_energy(uint16_t energy_kJ){ cycling_power_t * instance = &cycling_power; - if (instance->accumulated_energy_kJ <= (0xffff - energy_kJ)){ + if (instance->accumulated_energy_kJ <= (0xffffu - energy_kJ)){ instance->accumulated_energy_kJ += energy_kJ; } else { instance->accumulated_energy_kJ = 0xffff; @@ -1177,13 +1177,13 @@ void cycling_power_service_server_set_bottom_dead_spot_angle(uint16_t bottom_dea } static int gatt_date_is_valid(gatt_date_time_t date){ - if ((date.year != 0) && ((date.year < 1582) || (date.year > 9999))) return 0; - if ((date.month != 0) && (date.month > 12)) return 0; - if ((date.day != 0) && (date.day > 31)) return 0; + if ((date.year != 0u) && ((date.year < 1582u) || (date.year > 9999u))) return 0u; + if ((date.month != 0u) && (date.month > 12u)) return 0u; + if ((date.day != 0u) && (date.day > 31u)) return 0u; - if (date.hours > 23) return 0; - if (date.minutes > 59) return 0; - if (date.seconds > 59) return 0; + if (date.hours > 23u) return 0u; + if (date.minutes > 59u) return 0u; + if (date.seconds > 59u) return 0u; return 1; } diff --git a/src/ble/gatt-service/cycling_speed_and_cadence_service_server.c b/src/ble/gatt-service/cycling_speed_and_cadence_service_server.c index 3ec228948..259295dad 100644 --- a/src/ble/gatt-service/cycling_speed_and_cadence_service_server.c +++ b/src/ble/gatt-service/cycling_speed_and_cadence_service_server.c @@ -103,21 +103,21 @@ static uint16_t cycling_speed_and_cadence_service_read_callback(hci_con_handle_t cycling_speed_and_cadence_t * instance = &cycling_speed_and_cadence; if (attribute_handle == instance->measurement_client_configuration_descriptor_handle){ - if (buffer && (buffer_size >= 2)){ + if (buffer && (buffer_size >= 2u)){ little_endian_store_16(buffer, 0, instance->measurement_client_configuration_descriptor_notify); } return 2; } if (attribute_handle == instance->control_point_client_configuration_descriptor_handle){ - if (buffer && (buffer_size >= 2)){ + if (buffer && (buffer_size >= 2u)){ little_endian_store_16(buffer, 0, instance->control_point_client_configuration_descriptor_indicate); } return 2; } if (attribute_handle == instance->feature_handle){ - if (buffer && (buffer_size >= 2)){ + if (buffer && (buffer_size >= 2u)){ uint16_t feature = (instance->wheel_revolution_data_supported << CSC_FLAG_WHEEL_REVOLUTION_DATA_SUPPORTED); feature |= (instance->crank_revolution_data_supported << CSC_FLAG_CRANK_REVOLUTION_DATA_SUPPORTED); feature |= (instance->multiple_sensor_locations_supported << CSC_FLAG_MULTIPLE_SENSOR_LOCATIONS_SUPPORTED); @@ -127,7 +127,7 @@ static uint16_t cycling_speed_and_cadence_service_read_callback(hci_con_handle_t } if (attribute_handle == instance->sensor_location_value_handle){ - if (buffer && (buffer_size >= 1)){ + if (buffer && (buffer_size >= 1u)){ buffer[0] = instance->sensor_location; } return 1; @@ -182,7 +182,7 @@ static void cycling_speed_and_cadence_service_response_can_send_now(void * conte case CSC_OPCODE_REQUEST_SUPPORTED_SENSOR_LOCATIONS:{ int loc; for (loc = CSC_SERVICE_SENSOR_LOCATION_OTHER; loc < (CSC_SERVICE_SENSOR_LOCATION_RESERVED-1); loc++){ - if (instance->supported_sensor_locations & (1 << loc)){ + if (instance->supported_sensor_locations & (1u << loc)){ value[pos++] = loc; } } @@ -218,7 +218,7 @@ static int cycling_speed_and_cadence_service_write_callback(hci_con_handle_t con // printf("cycling_speed_and_cadence_service_write_callback: attr handle 0x%02x\n", attribute_handle); if (attribute_handle == instance->measurement_client_configuration_descriptor_handle){ - if (buffer_size < 2){ + if (buffer_size < 2u){ return ATT_ERROR_INVALID_OFFSET; } instance->measurement_client_configuration_descriptor_notify = little_endian_read_16(buffer, 0); @@ -230,7 +230,7 @@ static int cycling_speed_and_cadence_service_write_callback(hci_con_handle_t con } if (attribute_handle == instance->control_point_client_configuration_descriptor_handle){ - if (buffer_size < 2){ + if (buffer_size < 2u){ return ATT_ERROR_INVALID_OFFSET; } instance->control_point_client_configuration_descriptor_indicate = little_endian_read_16(buffer, 0); @@ -242,7 +242,7 @@ static int cycling_speed_and_cadence_service_write_callback(hci_con_handle_t con } if (attribute_handle == instance->control_point_value_handle){ - if (instance->control_point_client_configuration_descriptor_indicate == 0) return CYCLING_SPEED_AND_CADENCE_ERROR_CODE_CCC_DESCRIPTOR_IMPROPERLY_CONFIGURED; + if (instance->control_point_client_configuration_descriptor_indicate == 0u) return CYCLING_SPEED_AND_CADENCE_ERROR_CODE_CCC_DESCRIPTOR_IMPROPERLY_CONFIGURED; if (instance->request_opcode != CSC_OPCODE_IDLE) return CYCLING_SPEED_AND_CADENCE_ERROR_CODE_PROCEDURE_ALREADY_IN_PROGRESS; instance->request_opcode = (csc_opcode_t) buffer[0]; @@ -358,7 +358,7 @@ static void cycling_speed_and_cadence_service_calculate_cumulative_wheel_revolut static void cycling_speed_and_cadence_service_calculate_cumulative_crank_revolutions(uint16_t revolutions_change){ cycling_speed_and_cadence_t * instance = &cycling_speed_and_cadence; - if (instance->cumulative_crank_revolutions <= (0xffff - revolutions_change)){ + if (instance->cumulative_crank_revolutions <= (0xffffu - revolutions_change)){ instance->cumulative_crank_revolutions += revolutions_change; } else { instance->cumulative_crank_revolutions = 0xffff; diff --git a/src/ble/gatt-service/heart_rate_service_server.c b/src/ble/gatt-service/heart_rate_service_server.c index 74610e79f..7c34b1a8c 100644 --- a/src/ble/gatt-service/heart_rate_service_server.c +++ b/src/ble/gatt-service/heart_rate_service_server.c @@ -95,14 +95,14 @@ static uint16_t heart_rate_service_read_callback(hci_con_handle_t con_handle, ui UNUSED(buffer_size); if (attribute_handle == heart_rate.measurement_client_configuration_descriptor_handle){ - if (buffer && (buffer_size >= 2)){ + if (buffer && (buffer_size >= 2u)){ little_endian_store_16(buffer, 0, heart_rate.measurement_client_configuration_descriptor_notify); } return 2; } if (attribute_handle == heart_rate.sensor_location_value_handle){ - if (buffer && (buffer_size >= 1)){ + if (buffer && (buffer_size >= 1u)){ buffer[0] = heart_rate.sensor_location; } return 1; @@ -116,7 +116,7 @@ static int heart_rate_service_write_callback(hci_con_handle_t con_handle, uint16 UNUSED(buffer_size); if (attribute_handle == heart_rate.measurement_client_configuration_descriptor_handle){ - if (buffer_size < 2){ + if (buffer_size < 2u){ return ATT_ERROR_INVALID_OFFSET; } heart_rate.measurement_client_configuration_descriptor_notify = little_endian_read_16(buffer, 0); @@ -179,10 +179,10 @@ static void heart_rate_service_can_send_now(void * context){ uint8_t flags = (1 << HEART_RATE_SERVICE_VALUE_FORMAT); flags |= (instance->sensor_contact << HEART_RATE_SERVICE_SENSOR_CONTACT_STATUS); if (instance->energy_expended_supported){ - flags |= (1 << HEART_RATE_SERVICE_ENERGY_EXPENDED_STATUS); + flags |= (1u << HEART_RATE_SERVICE_ENERGY_EXPENDED_STATUS); } if (instance->rr_interval_count){ - flags |= (1 << HEART_RATE_SERVICE_RR_INTERVAL); + flags |= (1u << HEART_RATE_SERVICE_RR_INTERVAL); } uint8_t value[100]; @@ -197,12 +197,12 @@ static void heart_rate_service_can_send_now(void * context){ } // TODO: get actual MTU from ATT server - uint16_t bytes_left = btstack_min(sizeof(value), l2cap_max_mtu() - 3 - pos); + uint16_t bytes_left = btstack_min(sizeof(value), l2cap_max_mtu() - 3u - pos); - while ((bytes_left > 2) && instance->rr_interval_count){ + while ((bytes_left > 2u) && instance->rr_interval_count){ little_endian_store_16(value, pos, instance->rr_intervals[0]); pos +=2; - bytes_left -= 2; + bytes_left -= 2u; instance->rr_intervals++; instance->rr_interval_count--; } @@ -219,7 +219,7 @@ static void heart_rate_service_can_send_now(void * context){ void heart_rate_service_add_energy_expended(uint16_t energy_expended_kJ){ heart_rate_t * instance = &heart_rate; // limit energy expended to 0xffff - if (instance->energy_expended_kJ <= (0xffff - energy_expended_kJ)){ + if (instance->energy_expended_kJ <= (0xffffu - energy_expended_kJ)){ instance->energy_expended_kJ += energy_expended_kJ; } else { instance->energy_expended_kJ = 0xffff; diff --git a/src/ble/gatt-service/hids_device.c b/src/ble/gatt-service/hids_device.c index 016a5440d..0abb921dd 100644 --- a/src/ble/gatt-service/hids_device.c +++ b/src/ble/gatt-service/hids_device.c @@ -197,7 +197,7 @@ static uint16_t att_read_callback(hci_con_handle_t con_handle, uint16_t att_hand } if (att_handle == instance->hid_control_point_value_handle){ - if (buffer && (buffer_size >= 1)){ + if (buffer && (buffer_size >= 1u)){ buffer[0] = instance->hid_control_point_suspend; } return 1; @@ -252,15 +252,15 @@ static int att_write_callback(hci_con_handle_t con_handle, uint16_t att_handle, } if (att_handle == instance->hid_control_point_value_handle){ - if (buffer_size < 1){ + if (buffer_size < 1u){ return ATT_ERROR_INVALID_OFFSET; } instance->hid_control_point_suspend = buffer[0]; instance->con_handle = con_handle; log_info("Set suspend tp: %u", instance->hid_control_point_suspend ); - if (instance->hid_control_point_suspend == 0){ + if (instance->hid_control_point_suspend == 0u){ hids_device_emit_event(HIDS_SUBEVENT_SUSPEND, con_handle); - } else if (instance->hid_control_point_suspend == 1){ + } else if (instance->hid_control_point_suspend == 1u){ hids_device_emit_event(HIDS_SUBEVENT_EXIT_SUSPEND, con_handle); } } @@ -306,10 +306,10 @@ void hids_device_init(uint8_t country_code, const uint8_t * descriptor, uint16_t instance->hid_report_input_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_REPORT); instance->hid_report_input_client_configuration_handle = gatt_server_get_client_configuration_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_REPORT); - instance->hid_report_output_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(instance->hid_report_input_client_configuration_handle+1, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_REPORT); + instance->hid_report_output_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(instance->hid_report_input_client_configuration_handle+1u, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_REPORT); instance->hid_report_output_client_configuration_handle = gatt_server_get_client_configuration_handle_for_characteristic_with_uuid16(instance->hid_report_input_client_configuration_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_REPORT); - instance->hid_report_feature_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(instance->hid_report_output_client_configuration_handle+1, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_REPORT); + instance->hid_report_feature_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(instance->hid_report_output_client_configuration_handle+1u, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_REPORT); instance->hid_report_feature_client_configuration_handle = gatt_server_get_client_configuration_handle_for_characteristic_with_uuid16(instance->hid_report_output_client_configuration_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_REPORT); instance->hid_control_point_value_handle = gatt_server_get_value_handle_for_characteristic_with_uuid16(start_handle, end_handle, ORG_BLUETOOTH_CHARACTERISTIC_HID_CONTROL_POINT); diff --git a/src/ble/gatt-service/ublox_spp_service_server.c b/src/ble/gatt-service/ublox_spp_service_server.c index 30a9024f4..63580629e 100644 --- a/src/ble/gatt-service/ublox_spp_service_server.c +++ b/src/ble/gatt-service/ublox_spp_service_server.c @@ -150,7 +150,7 @@ static int ublox_spp_service_write_callback(hci_con_handle_t con_handle, uint16_ } if (attribute_handle == instance->fifo_client_configuration_descriptor_handle){ - if (buffer_size < 2){ + if (buffer_size < 2u){ return ATT_ERROR_INVALID_OFFSET; } instance->fifo_client_configuration_descriptor_value = little_endian_read_16(buffer, 0); @@ -176,7 +176,7 @@ static int ublox_spp_service_write_callback(hci_con_handle_t con_handle, uint16_ } if (attribute_handle == instance->credits_client_configuration_descriptor_handle){ - if (buffer_size < 2){ + if (buffer_size < 2u){ return ATT_ERROR_INVALID_OFFSET; } instance->credits_client_configuration_descriptor_value = little_endian_read_16(buffer, 0); @@ -267,7 +267,7 @@ void ublox_spp_service_server_request_can_send_now(btstack_context_callback_regi int ublox_spp_service_server_send(hci_con_handle_t con_handle, const uint8_t * data, uint16_t size){ ublox_spp_service_t * instance = &ublox_spp; if (ublox_spp_service_flow_control_enabled(instance)){ - if (instance->outgoing_credits > 0){ + if (instance->outgoing_credits > 0u){ instance->outgoing_credits--; } } diff --git a/src/ble/gatt_client.c b/src/ble/gatt_client.c index 110bf8f43..f10448f21 100644 --- a/src/ble/gatt_client.c +++ b/src/ble/gatt_client.c @@ -238,7 +238,7 @@ static uint8_t att_find_by_type_value_request(uint16_t request_type, uint16_t at little_endian_store_16(request, 5, attribute_group_type); (void)memcpy(&request[7], value, value_size); - return l2cap_send_prepared_connectionless(peripheral_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL, 7+value_size); + return l2cap_send_prepared_connectionless(peripheral_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL, 7u+value_size); } // precondition: can_send_packet_now == TRUE @@ -323,7 +323,7 @@ static uint8_t att_write_request(uint16_t request_type, uint16_t peripheral_hand little_endian_store_16(request, 1, attribute_handle); (void)memcpy(&request[3], value, value_length); - return l2cap_send_prepared_connectionless(peripheral_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL, 3 + value_length); + return l2cap_send_prepared_connectionless(peripheral_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL, 3u + value_length); } // precondition: can_send_packet_now == TRUE @@ -345,7 +345,7 @@ static uint8_t att_prepare_write_request(uint16_t request_type, uint16_t periphe little_endian_store_16(request, 3, value_offset); (void)memcpy(&request[5], &value[value_offset], blob_length); - return l2cap_send_prepared_connectionless(peripheral_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL, 5+blob_length); + return l2cap_send_prepared_connectionless(peripheral_handle, L2CAP_CID_ATTRIBUTE_PROTOCOL, 5u+blob_length); } static uint8_t att_exchange_mtu_request(uint16_t peripheral_handle){ @@ -359,7 +359,7 @@ static uint8_t att_exchange_mtu_request(uint16_t peripheral_handle){ } static uint16_t write_blob_length(gatt_client_t * peripheral){ - uint16_t max_blob_length = peripheral_mtu(peripheral) - 5; + uint16_t max_blob_length = peripheral_mtu(peripheral) - 5u; if (peripheral->attribute_offset >= peripheral->attribute_length) { return 0; } @@ -464,12 +464,12 @@ static void send_gatt_signed_write_request(gatt_client_t * peripheral, uint32_t static uint16_t get_last_result_handle_from_service_list(uint8_t * packet, uint16_t size){ uint8_t attr_length = packet[1]; - return little_endian_read_16(packet, size - attr_length + 2); + return little_endian_read_16(packet, size - attr_length + 2u); } static uint16_t get_last_result_handle_from_characteristics_list(uint8_t * packet, uint16_t size){ uint8_t attr_length = packet[1]; - return little_endian_read_16(packet, size - attr_length + 3); + return little_endian_read_16(packet, size - attr_length + 3u); } static uint16_t get_last_result_handle_from_included_services_list(uint8_t * packet, uint16_t size){ @@ -528,7 +528,7 @@ static void emit_gatt_service_query_result_event(gatt_client_t * peripheral, uin // @format HX uint8_t packet[24]; packet[0] = GATT_EVENT_SERVICE_QUERY_RESULT; - packet[1] = sizeof(packet) - 2; + packet[1] = sizeof(packet) - 2u; little_endian_store_16(packet, 2, peripheral->con_handle); /// little_endian_store_16(packet, 4, start_group_handle); @@ -541,7 +541,7 @@ static void emit_gatt_included_service_query_result_event(gatt_client_t * periph // @format HX uint8_t packet[26]; packet[0] = GATT_EVENT_INCLUDED_SERVICE_QUERY_RESULT; - packet[1] = sizeof(packet) - 2; + packet[1] = sizeof(packet) - 2u; little_endian_store_16(packet, 2, peripheral->con_handle); /// little_endian_store_16(packet, 4, include_handle); @@ -557,7 +557,7 @@ static void emit_gatt_characteristic_query_result_event(gatt_client_t * peripher // @format HY uint8_t packet[28]; packet[0] = GATT_EVENT_CHARACTERISTIC_QUERY_RESULT; - packet[1] = sizeof(packet) - 2; + packet[1] = sizeof(packet) - 2u; little_endian_store_16(packet, 2, peripheral->con_handle); /// little_endian_store_16(packet, 4, start_handle); @@ -573,7 +573,7 @@ static void emit_gatt_all_characteristic_descriptors_result_event( // @format HZ uint8_t packet[22]; packet[0] = GATT_EVENT_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY_RESULT; - packet[1] = sizeof(packet) - 2; + packet[1] = sizeof(packet) - 2u; little_endian_store_16(packet, 2, peripheral->con_handle); /// little_endian_store_16(packet, 4, descriptor_handle); @@ -585,7 +585,7 @@ static void emit_gatt_mtu_exchanged_result_event(gatt_client_t * peripheral, uin // @format H2 uint8_t packet[6]; packet[0] = GATT_EVENT_MTU; - packet[1] = sizeof(packet) - 2; + packet[1] = sizeof(packet) - 2u; little_endian_store_16(packet, 2, peripheral->con_handle); little_endian_store_16(packet, 4, new_mtu); att_dispatch_client_mtu_exchanged(peripheral->con_handle, new_mtu); @@ -594,7 +594,7 @@ static void emit_gatt_mtu_exchanged_result_event(gatt_client_t * peripheral, uin /// static void report_gatt_services(gatt_client_t * peripheral, uint8_t * packet, uint16_t size){ uint8_t attr_length = packet[1]; - uint8_t uuid_length = attr_length - 4; + uint8_t uuid_length = attr_length - 4u; int i; for (i = 2; i < size; i += attr_length){ @@ -603,7 +603,7 @@ static void report_gatt_services(gatt_client_t * peripheral, uint8_t * packet, uint8_t uuid128[16]; uint16_t uuid16 = 0; - if (uuid_length == 2){ + if (uuid_length == 2u){ uuid16 = little_endian_read_16(packet, i+4); uuid_add_bluetooth_prefix((uint8_t*) &uuid128, uuid16); } else { @@ -618,10 +618,10 @@ static void report_gatt_services(gatt_client_t * peripheral, uint8_t * packet, static void characteristic_start_found(gatt_client_t * peripheral, uint16_t start_handle, uint8_t properties, uint16_t value_handle, uint8_t * uuid, uint16_t uuid_length){ uint8_t uuid128[16]; uint16_t uuid16 = 0; - if (uuid_length == 2){ + if (uuid_length == 2u){ uuid16 = little_endian_read_16(uuid, 0); uuid_add_bluetooth_prefix((uint8_t*) uuid128, uuid16); - } else if (uuid_length == 16){ + } else if (uuid_length == 16u){ reverse_128(uuid, uuid128); } else { return; @@ -651,16 +651,16 @@ static void characteristic_end_found(gatt_client_t * peripheral, uint16_t end_ha } static void report_gatt_characteristics(gatt_client_t * peripheral, uint8_t * packet, uint16_t size){ - if (size < 2) return; + if (size < 2u) return; uint8_t attr_length = packet[1]; - if ((attr_length != 7) && (attr_length != 21)) return; - uint8_t uuid_length = attr_length - 5; + if ((attr_length != 7u) && (attr_length != 21u)) return; + uint8_t uuid_length = attr_length - 5u; int i; - for (i = 2; (i + attr_length) <= size; i += attr_length){ + for (i = 2u; (i + attr_length) <= size; i += attr_length){ uint16_t start_handle = little_endian_read_16(packet, i); uint8_t properties = packet[i+2]; uint16_t value_handle = little_endian_read_16(packet, i+3); - characteristic_end_found(peripheral, start_handle-1); + characteristic_end_found(peripheral, start_handle-1u); characteristic_start_found(peripheral, start_handle, properties, value_handle, &packet[i+5], uuid_length); } } @@ -748,7 +748,7 @@ static void report_gatt_long_characteristic_value_blob(gatt_client_t * periphera static void report_gatt_characteristic_descriptor(gatt_client_t * peripheral, uint16_t descriptor_handle, uint8_t *value, uint16_t value_length, uint16_t value_offset){ UNUSED(value_offset); uint8_t * packet = setup_characteristic_value_packet(GATT_EVENT_CHARACTERISTIC_DESCRIPTOR_QUERY_RESULT, peripheral->con_handle, descriptor_handle, value, value_length); - emit_event_new(peripheral->callback, packet, value_length + 8); + emit_event_new(peripheral->callback, packet, value_length + 8u); } static void report_gatt_long_characteristic_descriptor(gatt_client_t * peripheral, uint16_t descriptor_handle, uint8_t *blob, uint16_t blob_length, uint16_t value_offset){ @@ -759,11 +759,11 @@ static void report_gatt_long_characteristic_descriptor(gatt_client_t * periphera static void report_gatt_all_characteristic_descriptors(gatt_client_t * peripheral, uint8_t * packet, uint16_t size, uint16_t pair_size){ int i; - for (i = 0; (i + pair_size) <= size; i += pair_size){ + for (i = 0u; (i + pair_size) <= size; i += pair_size){ uint16_t descriptor_handle = little_endian_read_16(packet,i); uint8_t uuid128[16]; uint16_t uuid16 = 0; - if (pair_size == 4){ + if (pair_size == 4u){ uuid16 = little_endian_read_16(packet,i+2); uuid_add_bluetooth_prefix(uuid128, uuid16); } else { @@ -785,7 +785,7 @@ static void trigger_next_query(gatt_client_t * peripheral, uint16_t last_result_ return; } // next - peripheral->start_group_handle = last_result_handle + 1; + peripheral->start_group_handle = last_result_handle + 1u; peripheral->gatt_client_state = next_query_state; } @@ -821,7 +821,7 @@ static void trigger_next_prepare_write_query(gatt_client_t * peripheral, gatt_cl peripheral->attribute_offset += write_blob_length(peripheral); uint16_t next_blob_length = write_blob_length(peripheral); - if (next_blob_length == 0){ + if (next_blob_length == 0u){ peripheral->gatt_client_state = done_state; return; } @@ -830,7 +830,7 @@ static void trigger_next_prepare_write_query(gatt_client_t * peripheral, gatt_cl static void trigger_next_blob_query(gatt_client_t * peripheral, gatt_client_state_t next_query_state, uint16_t received_blob_length){ - uint16_t max_blob_length = peripheral_mtu(peripheral) - 1; + uint16_t max_blob_length = peripheral_mtu(peripheral) - 1u; if (received_blob_length < max_blob_length){ gatt_client_handle_transaction_complete(peripheral); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS); @@ -848,7 +848,7 @@ static int is_value_valid(gatt_client_t *peripheral, uint8_t *packet, uint16_t s if (peripheral->attribute_handle != attribute_handle) return 0; if (peripheral->attribute_offset != value_offset) return 0; - return memcmp(&peripheral->attribute_value[peripheral->attribute_offset], &packet[5], size-5) == 0; + return memcmp(&peripheral->attribute_value[peripheral->attribute_offset], &packet[5], size-5u) == 0u; } // returns 1 if packet was sent @@ -884,7 +884,7 @@ static int gatt_client_run_for_peripheral( gatt_client_t * peripheral){ switch (peripheral->gatt_client_state){ case P_W2_SEND_WRITE_CHARACTERISTIC_VALUE: case P_W2_SEND_WRITE_CHARACTERISTIC_DESCRIPTOR: - if (peripheral->attribute_length <= (peripheral_mtu(peripheral) - 3)) break; + if (peripheral->attribute_length <= (peripheral_mtu(peripheral) - 3u)) break; log_error("gatt_client_run: value len %u > MTU %u - 3\n", peripheral->attribute_length, peripheral_mtu(peripheral)); gatt_client_handle_transaction_complete(peripheral); emit_gatt_complete_event(peripheral, ATT_ERROR_INVALID_ATTRIBUTE_VALUE_LENGTH); @@ -1079,7 +1079,7 @@ static int gatt_client_run_for_peripheral( gatt_client_t * peripheral){ peripheral->write_without_response_callback = NULL; uint8_t event[4]; event[0] = GATT_EVENT_CAN_WRITE_WITHOUT_RESPONSE; - event[1] = sizeof(event) - 2; + event[1] = sizeof(event) - 2u; little_endian_store_16(event, 2, peripheral->con_handle); packet_handler(HCI_EVENT_PACKET, peripheral->con_handle, event, sizeof(event)); return 1; // to trigger requeueing (even if higher layer didn't sent) @@ -1171,7 +1171,7 @@ static void gatt_client_event_packet_handler(uint8_t packet_type, uint16_t chann static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, uint8_t *packet, uint16_t size){ gatt_client_t * peripheral; - if (size < 1) return; + if (size < 1u) return; if (packet_type == HCI_EVENT_PACKET) { switch (packet[0]){ @@ -1180,7 +1180,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, break; // att_server has negotiated the mtu for this connection, cache if context exists case ATT_EVENT_MTU_EXCHANGE_COMPLETE: - if (size < 6) break; + if (size < 6u) break; peripheral = get_gatt_client_context_for_handle(handle); if (peripheral == NULL) break; peripheral->mtu = little_endian_read_16(packet, 4); @@ -1196,8 +1196,8 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, // special cases: notifications don't need a context while indications motivate creating one switch (packet[0]){ case ATT_HANDLE_VALUE_NOTIFICATION: - if (size < 3) return; - report_gatt_notification(handle, little_endian_read_16(packet,1), &packet[3], size-3); + if (size < 3u) return; + report_gatt_notification(handle, little_endian_read_16(packet,1u), &packet[3], size-3u); return; case ATT_HANDLE_VALUE_INDICATION: peripheral = provide_context_for_conn_handle(handle); @@ -1212,7 +1212,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, switch (packet[0]){ case ATT_EXCHANGE_MTU_RESPONSE: { - if (size < 3) break; + if (size < 3u) break; uint16_t remote_rx_mtu = little_endian_read_16(packet, 1); uint16_t local_rx_mtu = l2cap_max_le_mtu(); peripheral->mtu = (remote_rx_mtu < local_rx_mtu) ? remote_rx_mtu : local_rx_mtu; @@ -1232,8 +1232,8 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, } break; case ATT_HANDLE_VALUE_INDICATION: - if (size < 3) break; - report_gatt_indication(handle, little_endian_read_16(packet,1), &packet[3], size-3); + if (size < 3u) break; + report_gatt_indication(handle, little_endian_read_16(packet,1u), &packet[3], size-3u); peripheral->send_confirmation = 1; break; @@ -1251,12 +1251,12 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, break; case P_W4_INCLUDED_SERVICE_QUERY_RESULT: { - if (size < 2) break; + if (size < 2u) break; uint16_t uuid16 = 0; uint16_t pair_size = packet[1]; - if (pair_size == 6){ - if (size < 8) break; + if (pair_size == 6u){ + if (size < 8u) break; // UUIDs not available, query first included service peripheral->start_group_handle = little_endian_read_16(packet, 2); // ready for next query peripheral->query_start_handle = little_endian_read_16(packet, 4); @@ -1265,15 +1265,15 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, break; } - if (pair_size != 8) break; + if (pair_size != 8u) break; // UUIDs included, report all of them uint16_t offset; - for (offset = 2; (offset + 8) <= size; offset += pair_size){ + for (offset = 2u; (offset + 8u) <= size; offset += pair_size){ uint16_t include_handle = little_endian_read_16(packet, offset); - peripheral->query_start_handle = little_endian_read_16(packet,offset+2); - peripheral->query_end_handle = little_endian_read_16(packet,offset+4); - uuid16 = little_endian_read_16(packet, offset+6); + peripheral->query_start_handle = little_endian_read_16(packet,offset+2u); + peripheral->query_end_handle = little_endian_read_16(packet,offset+4u); + uuid16 = little_endian_read_16(packet, offset+6u); report_gatt_included_service_uuid16(peripheral, include_handle, uuid16); } @@ -1293,7 +1293,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, uint16_t last_result_handle = 0; for (offset = 2; offset < size ; offset += pair_size){ uint16_t value_handle = little_endian_read_16(packet, offset); - report_gatt_characteristic_value(peripheral, value_handle, &packet[offset+2], pair_size-2); + report_gatt_characteristic_value(peripheral, value_handle, &packet[offset+2u], pair_size-2u); last_result_handle = value_handle; } trigger_next_read_by_type_query(peripheral, last_result_handle); @@ -1315,13 +1315,13 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, } case P_W4_READ_CHARACTERISTIC_VALUE_RESULT: gatt_client_handle_transaction_complete(peripheral); - report_gatt_characteristic_value(peripheral, peripheral->attribute_handle, &packet[1], size-1); + report_gatt_characteristic_value(peripheral, peripheral->attribute_handle, &packet[1], size-1u); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS); break; case P_W4_READ_CHARACTERISTIC_DESCRIPTOR_RESULT:{ gatt_client_handle_transaction_complete(peripheral); - report_gatt_characteristic_descriptor(peripheral, peripheral->attribute_handle, &packet[1], size-1, 0); + report_gatt_characteristic_descriptor(peripheral, peripheral->attribute_handle, &packet[1], size-1u, 0u); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS); break; } @@ -1336,7 +1336,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, int i; uint16_t start_group_handle; uint16_t end_group_handle= 0xffff; // asserts GATT_EVENT_QUERY_COMPLETE is emitted if no results - for (i = 1; (i + pair_size) <= size; i += pair_size){ + for (i = 1u; (i + pair_size) <= size; i += pair_size){ start_group_handle = little_endian_read_16(packet,i); end_group_handle = little_endian_read_16(packet,i+2); emit_gatt_service_query_result_event(peripheral, start_group_handle, end_group_handle, peripheral->uuid128); @@ -1347,10 +1347,10 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, } case ATT_FIND_INFORMATION_REPLY: { - if (size < 2) break; + if (size < 2u) break; uint8_t pair_size = 4; - if (packet[1] == 2){ + if (packet[1u] == 2u){ pair_size = 18; } uint16_t offset = 2; @@ -1384,7 +1384,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, break; } #endif - report_gatt_all_characteristic_descriptors(peripheral, &packet[2], size-2, pair_size); + report_gatt_all_characteristic_descriptors(peripheral, &packet[2], size-2u, pair_size); trigger_next_characteristic_descriptor_query(peripheral, last_descriptor_handle); // GATT_EVENT_QUERY_COMPLETE is emitted by trigger_next_xxx when done break; @@ -1410,7 +1410,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, break; case ATT_READ_BLOB_RESPONSE:{ - uint16_t received_blob_length = size-1; + uint16_t received_blob_length = size-1u; switch(peripheral->gatt_client_state){ case P_W4_READ_BLOB_RESULT: report_gatt_long_characteristic_value_blob(peripheral, peripheral->attribute_handle, &packet[1], received_blob_length, peripheral->attribute_offset); @@ -1494,7 +1494,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, case ATT_READ_MULTIPLE_RESPONSE: switch(peripheral->gatt_client_state){ case P_W4_READ_MULTIPLE_RESPONSE: - report_gatt_characteristic_value(peripheral, 0, &packet[1], size-1); + report_gatt_characteristic_value(peripheral, 0u, &packet[1], size-1u); gatt_client_handle_transaction_complete(peripheral); emit_gatt_complete_event(peripheral, ATT_ERROR_SUCCESS); break; @@ -1504,7 +1504,7 @@ static void gatt_client_att_packet_handler(uint8_t packet_type, uint16_t handle, break; case ATT_ERROR_RESPONSE: - if (size < 5) return; + if (size < 5u) return; switch (packet[4]){ case ATT_ERROR_ATTRIBUTE_NOT_FOUND: { switch(peripheral->gatt_client_state){ @@ -1803,7 +1803,7 @@ uint8_t gatt_client_discover_characteristic_descriptors(btstack_packet_handler_t return ERROR_CODE_SUCCESS; } peripheral->callback = callback; - peripheral->start_group_handle = characteristic->value_handle + 1; + peripheral->start_group_handle = characteristic->value_handle + 1u; peripheral->end_group_handle = characteristic->end_handle; peripheral->gatt_client_state = P_W2_SEND_ALL_CHARACTERISTIC_DESCRIPTORS_QUERY; gatt_client_run(); @@ -1900,7 +1900,7 @@ uint8_t gatt_client_write_value_of_characteristic_without_response(hci_con_handl gatt_client_t * peripheral = provide_context_for_conn_handle(con_handle); if (peripheral == NULL) return BTSTACK_MEMORY_ALLOC_FAILED; - if (value_length > (peripheral_mtu(peripheral) - 3)) return GATT_CLIENT_VALUE_TOO_LONG; + if (value_length > (peripheral_mtu(peripheral) - 3u)) return GATT_CLIENT_VALUE_TOO_LONG; if (!att_dispatch_client_can_send_now(peripheral->con_handle)) return GATT_CLIENT_BUSY; return att_write_request(ATT_WRITE_COMMAND, peripheral->con_handle, value_handle, value_length, value); @@ -1960,11 +1960,11 @@ uint8_t gatt_client_write_client_characteristic_configuration(btstack_packet_han if (is_ready(peripheral) == 0) return GATT_CLIENT_IN_WRONG_STATE; if ( (configuration & GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION) && - ((characteristic->properties & ATT_PROPERTY_NOTIFY) == 0)) { + ((characteristic->properties & ATT_PROPERTY_NOTIFY) == 0u)) { log_info("gatt_client_write_client_characteristic_configuration: GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED"); return GATT_CLIENT_CHARACTERISTIC_NOTIFICATION_NOT_SUPPORTED; } else if ( (configuration & GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_INDICATION) && - ((characteristic->properties & ATT_PROPERTY_INDICATE) == 0)){ + ((characteristic->properties & ATT_PROPERTY_INDICATE) == 0u)){ log_info("gatt_client_write_client_characteristic_configuration: GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED"); return GATT_CLIENT_CHARACTERISTIC_INDICATION_NOT_SUPPORTED; } diff --git a/src/ble/le_device_db_tlv.c b/src/ble/le_device_db_tlv.c index cea66ad9c..04d5fffae 100644 --- a/src/ble/le_device_db_tlv.c +++ b/src/ble/le_device_db_tlv.c @@ -106,7 +106,7 @@ static uint32_t le_device_db_tlv_tag_for_index(uint8_t index){ static const char tag_1 = 'T'; static const char tag_2 = 'D'; - return (tag_0 << 24) | (tag_1 << 16) | (tag_2 << 8) | index; + return (tag_0 << 24u) | (tag_1 << 16u) | (tag_2 << 8u) | index; } // @returns success @@ -181,7 +181,7 @@ int le_device_db_max_count(void){ void le_device_db_remove(int index){ // check if entry exists - if (entry_map[index] == 0) return; + if (entry_map[index] == 0u) return; // delete entry in TLV le_device_db_tlv_delete(index); @@ -251,7 +251,7 @@ int le_device_db_add(int addr_type, bd_addr_t addr, sm_key_t irk){ entry.addr_type = addr_type; (void)memcpy(entry.addr, addr, 6); (void)memcpy(entry.irk, irk, 16); - entry.seq_nr = highest_seq_nr + 1; + entry.seq_nr = highest_seq_nr + 1u; #ifdef ENABLE_LE_SIGNED_WRITE entry.remote_counter = 0; #endif diff --git a/src/ble/sm.c b/src/ble/sm.c index 544978a37..422238b1e 100644 --- a/src/ble/sm.c +++ b/src/ble/sm.c @@ -757,7 +757,7 @@ static void sm_setup_tk(void){ #ifdef ENABLE_LE_SECURE_CONNECTIONS setup->sm_use_secure_connections = ( sm_pairing_packet_get_auth_req(setup->sm_m_preq) & sm_pairing_packet_get_auth_req(setup->sm_s_pres) - & SM_AUTHREQ_SECURE_CONNECTION ) != 0; + & SM_AUTHREQ_SECURE_CONNECTION ) != 0u; #else setup->sm_use_secure_connections = 0; #endif @@ -785,8 +785,8 @@ static void sm_setup_tk(void){ // If both devices have not set the MITM option in the Authentication Requirements // Flags, then the IO capabilities shall be ignored and the Just Works association // model shall be used. - if (((sm_pairing_packet_get_auth_req(setup->sm_m_preq) & SM_AUTHREQ_MITM_PROTECTION) == 0) - && ((sm_pairing_packet_get_auth_req(setup->sm_s_pres) & SM_AUTHREQ_MITM_PROTECTION) == 0)){ + if (((sm_pairing_packet_get_auth_req(setup->sm_m_preq) & SM_AUTHREQ_MITM_PROTECTION) == 0u) + && ((sm_pairing_packet_get_auth_req(setup->sm_s_pres) & SM_AUTHREQ_MITM_PROTECTION) == 0u)){ log_info("SM: MITM not required by both -> JUST WORKS"); return; } @@ -889,7 +889,7 @@ static void sm_cmac_done_trampoline(void * arg){ } int sm_cmac_ready(void){ - return sm_cmac_active == 0; + return sm_cmac_active == 0u; } #endif @@ -1121,7 +1121,7 @@ static int sm_stk_generation_init(sm_connection_t * sm_conn){ // check key size sm_conn->sm_actual_encryption_key_size = sm_calc_actual_encryption_key_size(sm_pairing_packet_get_max_encryption_key_size(*remote_packet)); - if (sm_conn->sm_actual_encryption_key_size == 0) return SM_REASON_ENCRYPTION_KEY_SIZE; + if (sm_conn->sm_actual_encryption_key_size == 0u) return SM_REASON_ENCRYPTION_KEY_SIZE; // decide on STK generation method / SC sm_setup_tk(); @@ -1257,7 +1257,7 @@ static void sm_key_distribution_handle_all_received(sm_connection_t * sm_conn){ // only store pairing information if both sides are bondable, i.e., the bonadble flag is set int bonding_enabed = ( sm_pairing_packet_get_auth_req(setup->sm_m_preq) & sm_pairing_packet_get_auth_req(setup->sm_s_pres) - & SM_AUTHREQ_BONDING ) != 0; + & SM_AUTHREQ_BONDING ) != 0u; if (bonding_enabed){ @@ -1400,7 +1400,7 @@ static void sm_sc_state_after_receiving_random(sm_connection_t * sm_conn){ case PK_INIT_INPUT: case PK_RESP_INPUT: case PK_BOTH_INPUT: - if (setup->sm_passkey_bit < 20) { + if (setup->sm_passkey_bit < 20u) { sm_sc_start_calculating_local_confirm(sm_conn); } else { sm_sc_prepare_dhkey_check(sm_conn); @@ -1656,7 +1656,7 @@ static void sm_sc_calculate_local_confirm(sm_connection_t * sm_conn){ if (sm_passkey_entry(setup->sm_stk_generation_method)){ // some form of passkey uint32_t pk = big_endian_read_32(setup->sm_tk, 12); - z = 0x80 | ((pk >> setup->sm_passkey_bit) & 1); + z = 0x80u | ((pk >> setup->sm_passkey_bit) & 1u); setup->sm_passkey_bit++; } f4_engine(sm_conn, ec_q, setup->sm_peer_q, setup->sm_local_nonce, z); @@ -1678,7 +1678,7 @@ static void sm_sc_calculate_remote_confirm(sm_connection_t * sm_conn){ // some form of passkey uint32_t pk = big_endian_read_32(setup->sm_tk, 12); // sm_passkey_bit was increased before sending confirm value - z = 0x80 | ((pk >> (setup->sm_passkey_bit-1)) & 1); + z = 0x80u | ((pk >> (setup->sm_passkey_bit-1u)) & 1u); } f4_engine(sm_conn, setup->sm_peer_q, ec_q, setup->sm_peer_nonce, z); } @@ -1827,9 +1827,9 @@ static void sm_start_calculating_ltk_from_ediv_and_rand(sm_connection_t * sm_con setup->sm_local_ediv = sm_connection->sm_local_ediv; // re-establish used key encryption size // no db for encryption size hack: encryption size is stored in lowest nibble of setup->sm_local_rand - sm_connection->sm_actual_encryption_key_size = (setup->sm_local_rand[7] & 0x0f) + 1; + sm_connection->sm_actual_encryption_key_size = (setup->sm_local_rand[7u] & 0x0fu) + 1u; // no db for authenticated flag hack: flag is stored in bit 4 of LSB - sm_connection->sm_connection_authenticated = (setup->sm_local_rand[7] & 0x10) >> 4; + sm_connection->sm_connection_authenticated = (setup->sm_local_rand[7u] & 0x10u) >> 4u; // Legacy paring -> not SC sm_connection->sm_connection_sc = 0; log_info("sm: received ltk request with key size %u, authenticated %u", @@ -2105,7 +2105,7 @@ static void sm_run_activate_connection(void){ // start using context by loading security info sm_reset_setup(); sm_load_security_info(sm_connection); - if ((setup->sm_peer_ediv == 0) && sm_is_null_random(setup->sm_peer_rand) && !sm_is_null_key(setup->sm_peer_ltk)){ + if ((setup->sm_peer_ediv == 0u) && sm_is_null_random(setup->sm_peer_rand) && !sm_is_null_key(setup->sm_peer_ltk)){ (void)memcpy(setup->sm_ltk, setup->sm_peer_ltk, 16); sm_connection->sm_engine_state = SM_RESPONDER_PH4_SEND_LTK_REPLY; @@ -2217,11 +2217,11 @@ static void sm_run(void){ // send keypress notifications if (setup->sm_keypress_notification){ int i; - uint8_t flags = setup->sm_keypress_notification & 0x1f; + uint8_t flags = setup->sm_keypress_notification & 0x1fu; uint8_t num_actions = setup->sm_keypress_notification >> 5; uint8_t action = 0; for (i=SM_KEYPRESS_PASSKEY_ENTRY_STARTED;i<=SM_KEYPRESS_PASSKEY_ENTRY_COMPLETED;i++){ - if (flags & (1<sm_local_nonce, &buffer[1]); log_info("stk method %u, num bits %u", setup->sm_stk_generation_method, setup->sm_passkey_bit); - if (sm_passkey_entry(setup->sm_stk_generation_method) && (setup->sm_passkey_bit < 20)){ + if (sm_passkey_entry(setup->sm_stk_generation_method) && (setup->sm_passkey_bit < 20u)){ log_info("SM_SC_SEND_PAIRING_RANDOM A"); if (IS_RESPONDER(connection->sm_role)){ // responder @@ -2983,14 +2983,14 @@ static void sm_handle_random_result_rau(void * arg){ case GAP_RANDOM_ADDRESS_RESOLVABLE: // resolvable: use random as prand and calc address hash // "The two most significant bits of prand shall be equal to ‘0’ and ‘1" - sm_random_address[0] &= 0x3f; - sm_random_address[0] |= 0x40; + sm_random_address[0u] &= 0x3fu; + sm_random_address[0u] |= 0x40u; rau_state = RAU_GET_ENC; break; case GAP_RANDOM_ADDRESS_NON_RESOLVABLE: default: // "The two most significant bits of the address shall be equal to ‘0’"" - sm_random_address[0] &= 0x3f; + sm_random_address[0u] &= 0x3fu; rau_state = RAU_SET_ADDRESS; break; } @@ -3037,8 +3037,8 @@ static void sm_handle_random_result_ph2_tk(void * arg){ // map random to 0-999999 without speding much cycles on a modulus operation tk = little_endian_read_32(sm_random_data,0); tk = tk & 0xfffff; // 1048575 - if (tk >= 999999){ - tk = tk - 999999; + if (tk >= 999999u){ + tk = tk - 999999u; } } else { // override with pre-defined passkey @@ -3081,9 +3081,9 @@ static void sm_handle_random_result_ph3_random(void * arg){ reverse_64(sm_random_data, setup->sm_local_rand); // no db for encryption size hack: encryption size is stored in lowest nibble of setup->sm_local_rand - setup->sm_local_rand[7] = (setup->sm_local_rand[7] & 0xf0) + (connection->sm_actual_encryption_key_size - 1); + setup->sm_local_rand[7u] = (setup->sm_local_rand[7u] & 0xf0u) + (connection->sm_actual_encryption_key_size - 1u); // no db for authenticated flag hack: store flag in bit 4 of LSB - setup->sm_local_rand[7] = (setup->sm_local_rand[7] & 0xef) + (connection->sm_connection_authenticated << 4); + setup->sm_local_rand[7u] = (setup->sm_local_rand[7u] & 0xefu) + (connection->sm_connection_authenticated << 4u); btstack_crypto_random_generate(&sm_crypto_random_request, sm_random_data, 2, &sm_handle_random_result_ph3_div, (void *)(uintptr_t) connection->sm_handle); } static void sm_validate_er_ir(void){ @@ -3106,7 +3106,7 @@ static void sm_handle_random_result_ir(void *arg){ sm_persistent_keys_random_active = 0; if (arg){ // key generated, store in tlv - int status = sm_tlv_impl->store_tag(sm_tlv_context, BTSTACK_TAG32('S','M','I','R'), sm_persistent_ir, 16); + int status = sm_tlv_impl->store_tag(sm_tlv_context, BTSTACK_TAG32('S','M','I','R'), sm_persistent_ir, 16u); log_info("Generated IR key. Store in TLV status: %d", status); } log_info_key("IR", sm_persistent_ir); @@ -3124,13 +3124,13 @@ static void sm_handle_random_result_er(void *arg){ sm_persistent_keys_random_active = 0; if (arg){ // key generated, store in tlv - int status = sm_tlv_impl->store_tag(sm_tlv_context, BTSTACK_TAG32('S','M','E','R'), sm_persistent_er, 16); + int status = sm_tlv_impl->store_tag(sm_tlv_context, BTSTACK_TAG32('S','M','E','R'), sm_persistent_er, 16u); log_info("Generated ER key. Store in TLV status: %d", status); } log_info_key("ER", sm_persistent_er); // try load ir - int key_size = sm_tlv_impl->get_tag(sm_tlv_context, BTSTACK_TAG32('S','M','I','R'), sm_persistent_ir, 16); + int key_size = sm_tlv_impl->get_tag(sm_tlv_context, BTSTACK_TAG32('S','M','I','R'), sm_persistent_ir, 16u); if (key_size == 16){ // ok, let's continue log_info("IR from TLV"); @@ -3163,7 +3163,7 @@ static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint // setup IR/ER with TLV btstack_tlv_get_instance(&sm_tlv_impl, &sm_tlv_context); if (sm_tlv_impl){ - int key_size = sm_tlv_impl->get_tag(sm_tlv_context, BTSTACK_TAG32('S','M','E','R'), sm_persistent_er, 16); + int key_size = sm_tlv_impl->get_tag(sm_tlv_context, BTSTACK_TAG32('S','M','E','R'), sm_persistent_er, 16u); if (key_size == 16){ // ok, let's continue log_info("ER from TLV"); @@ -3257,7 +3257,7 @@ static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint // For Legacy Pairing (<=> EDIV != 0 || RAND != NULL), we need to recalculated our LTK as a // potentially stored LTK is from the master - if ((sm_conn->sm_local_ediv != 0) || !sm_is_null_random(sm_conn->sm_local_rand)){ + if ((sm_conn->sm_local_ediv != 0u) || !sm_is_null_random(sm_conn->sm_local_rand)){ if (sm_reconstruct_ltk_without_le_device_db_entry){ sm_conn->sm_engine_state = SM_RESPONDER_PH0_RECEIVED_LTK_REQUEST; break; @@ -3386,7 +3386,7 @@ static void sm_event_packet_handler (uint8_t packet_type, uint16_t channel, uint if (!sm_conn) break; // delete stored bonding on disconnect with authentication failure in ph0 - if ((sm_conn->sm_role == 0) + if ((sm_conn->sm_role == 0u) && (sm_conn->sm_engine_state == SM_INITIATOR_PH0_W4_CONNECTION_ENCRYPTED) && (packet[2] == ERROR_CODE_AUTHENTICATION_FAILURE)){ le_device_db_remove(sm_conn->sm_le_db_index); @@ -3474,15 +3474,15 @@ static int sm_validate_stk_generation_method(void){ // check if STK generation method is acceptable by client switch (setup->sm_stk_generation_method){ case JUST_WORKS: - return (sm_accepted_stk_generation_methods & SM_STK_GENERATION_METHOD_JUST_WORKS) != 0; + return (sm_accepted_stk_generation_methods & SM_STK_GENERATION_METHOD_JUST_WORKS) != 0u; case PK_RESP_INPUT: case PK_INIT_INPUT: case PK_BOTH_INPUT: - return (sm_accepted_stk_generation_methods & SM_STK_GENERATION_METHOD_PASSKEY) != 0; + return (sm_accepted_stk_generation_methods & SM_STK_GENERATION_METHOD_PASSKEY) != 0u; case OOB: - return (sm_accepted_stk_generation_methods & SM_STK_GENERATION_METHOD_OOB) != 0; + return (sm_accepted_stk_generation_methods & SM_STK_GENERATION_METHOD_OOB) != 0u; case NUMERIC_COMPARISON: - return (sm_accepted_stk_generation_methods & SM_STK_GENERATION_METHOD_NUMERIC_COMPARISON) != 0; + return (sm_accepted_stk_generation_methods & SM_STK_GENERATION_METHOD_NUMERIC_COMPARISON) != 0u; default: return 0; } @@ -3514,7 +3514,7 @@ static void sm_pdu_handler(uint8_t packet_type, hci_con_handle_t con_handle, uin } if (packet_type != SM_DATA_PACKET) return; - if (size == 0) return; + if (size == 0u) return; uint8_t sm_pdu_code = packet[0]; @@ -3812,7 +3812,7 @@ static void sm_pdu_handler(uint8_t packet_type, hci_con_handle_t con_handle, uin // setup local random, set to zero if remote did not receive our data log_info("Received nonce, setup local random ra/rb for dhkey check"); if (IS_RESPONDER(sm_conn->sm_role)){ - if (sm_pairing_packet_get_oob_data_flag(setup->sm_m_preq) == 0){ + if (sm_pairing_packet_get_oob_data_flag(setup->sm_m_preq) == 0u){ log_info("Reset rb as A does not have OOB data"); memset(setup->sm_rb, 0, 16); } else { @@ -3821,7 +3821,7 @@ static void sm_pdu_handler(uint8_t packet_type, hci_con_handle_t con_handle, uin log_info_hexdump(setup->sm_rb, 16); } } else { - if (sm_pairing_packet_get_oob_data_flag(setup->sm_s_pres) == 0){ + if (sm_pairing_packet_get_oob_data_flag(setup->sm_s_pres) == 0u){ log_info("Reset ra as B does not have OOB data"); memset(setup->sm_ra, 0, 16); } else { @@ -4293,41 +4293,41 @@ void sm_keypress_notification(hci_con_handle_t con_handle, uint8_t action){ if (!sm_conn) return; // wrong connection if (action > SM_KEYPRESS_PASSKEY_ENTRY_COMPLETED) return; uint8_t num_actions = setup->sm_keypress_notification >> 5; - uint8_t flags = setup->sm_keypress_notification & 0x1f; + uint8_t flags = setup->sm_keypress_notification & 0x1fu; switch (action){ case SM_KEYPRESS_PASSKEY_ENTRY_STARTED: case SM_KEYPRESS_PASSKEY_ENTRY_COMPLETED: - flags |= (1 << action); + flags |= (1u << action); break; case SM_KEYPRESS_PASSKEY_CLEARED: // clear counter, keypress & erased flags + set passkey cleared - flags = (flags & 0x19) | (1 << SM_KEYPRESS_PASSKEY_CLEARED); + flags = (flags & 0x19u) | (1u << SM_KEYPRESS_PASSKEY_CLEARED); break; case SM_KEYPRESS_PASSKEY_DIGIT_ENTERED: - if (flags & (1 << SM_KEYPRESS_PASSKEY_DIGIT_ERASED)){ + if (flags & (1u << SM_KEYPRESS_PASSKEY_DIGIT_ERASED)){ // erase actions queued num_actions--; - if (num_actions == 0){ + if (num_actions == 0u){ // clear counter, keypress & erased flags - flags &= 0x19; + flags &= 0x19u; } break; } num_actions++; - flags |= (1 << SM_KEYPRESS_PASSKEY_DIGIT_ENTERED); + flags |= (1u << SM_KEYPRESS_PASSKEY_DIGIT_ENTERED); break; case SM_KEYPRESS_PASSKEY_DIGIT_ERASED: - if (flags & (1 << SM_KEYPRESS_PASSKEY_DIGIT_ENTERED)){ + if (flags & (1u << SM_KEYPRESS_PASSKEY_DIGIT_ENTERED)){ // enter actions queued num_actions--; - if (num_actions == 0){ + if (num_actions == 0u){ // clear counter, keypress & erased flags - flags &= 0x19; + flags &= 0x19u; } break; } num_actions++; - flags |= (1 << SM_KEYPRESS_PASSKEY_DIGIT_ERASED); + flags |= (1u << SM_KEYPRESS_PASSKEY_DIGIT_ERASED); break; default: break; diff --git a/src/btstack_base64_decoder.c b/src/btstack_base64_decoder.c index e227d7b53..120253846 100644 --- a/src/btstack_base64_decoder.c +++ b/src/btstack_base64_decoder.c @@ -81,7 +81,7 @@ int btstack_base64_decoder_process_byte(btstack_base64_decoder_t * context, uin // handle '=' if (c == '='){ - if ((context->pos == 2) || (context->pos == 3)){ + if ((context->pos == 2u) || (context->pos == 3u)){ context->pos++; return BTSTACK_BASE64_DECODER_MORE; } @@ -91,7 +91,7 @@ int btstack_base64_decoder_process_byte(btstack_base64_decoder_t * context, uin uint8_t value = table[c]; // invalid character - if (value == 99) { + if (value == 99u) { context->pos = 99; } diff --git a/src/btstack_crypto.c b/src/btstack_crypto.c index d8de2fcf0..15e931f05 100644 --- a/src/btstack_crypto.c +++ b/src/btstack_crypto.c @@ -285,8 +285,8 @@ static inline void btstack_crypto_cmac_next_state(void){ static int btstack_crypto_cmac_last_block_complete(btstack_crypto_aes128_cmac_t * btstack_crypto_cmac){ uint16_t len = btstack_crypto_cmac->size; - if (len == 0) return 0; - return (len & 0x0f) == 0; + if (len == 0u) return 0u; + return (len & 0x0fu) == 0u; } static void btstack_crypto_cmac_handle_aes_engine_ready(btstack_crypto_aes128_cmac_t * btstack_crypto_cmac){ @@ -300,7 +300,7 @@ static void btstack_crypto_cmac_handle_aes_engine_ready(btstack_crypto_aes128_cm int j; sm_key_t y; for (j=0;j<16;j++){ - y[j] = btstack_crypto_cmac_x[j] ^ btstack_crypto_cmac_get_byte(btstack_crypto_cmac, (btstack_crypto_cmac_block_current*16) + j); + y[j] = btstack_crypto_cmac_x[j] ^ btstack_crypto_cmac_get_byte(btstack_crypto_cmac, (btstack_crypto_cmac_block_current*16u) + j); } btstack_crypto_cmac_block_current++; btstack_crypto_cmac_next_state(); @@ -311,14 +311,14 @@ static void btstack_crypto_cmac_handle_aes_engine_ready(btstack_crypto_aes128_cm sm_key_t k1; (void)memcpy(k1, btstack_crypto_cmac_subkey, 16); btstack_crypto_cmac_shift_left_by_one_bit_inplace(16, k1); - if (btstack_crypto_cmac_subkey[0] & 0x80){ - k1[15] ^= 0x87; + if (btstack_crypto_cmac_subkey[0u] & 0x80u){ + k1[15u] ^= 0x87u; } sm_key_t k2; (void)memcpy(k2, k1, 16); btstack_crypto_cmac_shift_left_by_one_bit_inplace(16, k2); - if (k1[0] & 0x80){ - k2[15] ^= 0x87; + if (k1[0u] & 0x80u){ + k2[15u] ^= 0x87u; } log_info_key("k", btstack_crypto_cmac_k); @@ -330,17 +330,17 @@ static void btstack_crypto_cmac_handle_aes_engine_ready(btstack_crypto_aes128_cm sm_key_t btstack_crypto_cmac_m_last; if (btstack_crypto_cmac_last_block_complete(btstack_crypto_cmac)){ for (i=0;i<16;i++){ - btstack_crypto_cmac_m_last[i] = btstack_crypto_cmac_get_byte(btstack_crypto_cmac, btstack_crypto_cmac->size - 16 + i) ^ k1[i]; + btstack_crypto_cmac_m_last[i] = btstack_crypto_cmac_get_byte(btstack_crypto_cmac, btstack_crypto_cmac->size - 16u + i) ^ k1[i]; } } else { - int valid_octets_in_last_block = btstack_crypto_cmac->size & 0x0f; + int valid_octets_in_last_block = btstack_crypto_cmac->size & 0x0fu; for (i=0;i<16;i++){ if (i < valid_octets_in_last_block){ - btstack_crypto_cmac_m_last[i] = btstack_crypto_cmac_get_byte(btstack_crypto_cmac, (btstack_crypto_cmac->size & 0xfff0) + i) ^ k2[i]; + btstack_crypto_cmac_m_last[i] = btstack_crypto_cmac_get_byte(btstack_crypto_cmac, (btstack_crypto_cmac->size & 0xfff0u) + i) ^ k2[i]; continue; } if (i == valid_octets_in_last_block){ - btstack_crypto_cmac_m_last[i] = 0x80 ^ k2[i]; + btstack_crypto_cmac_m_last[i] = 0x80u ^ k2[i]; continue; } btstack_crypto_cmac_m_last[i] = k2[i]; @@ -366,11 +366,11 @@ static void btstack_crypto_cmac_handle_encryption_result(btstack_crypto_aes128_c case CMAC_W4_SUBKEYS: (void)memcpy(btstack_crypto_cmac_subkey, data, 16); // next - btstack_crypto_cmac_state = (btstack_crypto_cmac_block_current < (btstack_crypto_cmac_block_count - 1)) ? CMAC_CALC_MI : CMAC_CALC_MLAST; + btstack_crypto_cmac_state = (btstack_crypto_cmac_block_current < (btstack_crypto_cmac_block_count - 1u)) ? CMAC_CALC_MI : CMAC_CALC_MLAST; break; case CMAC_W4_MI: (void)memcpy(btstack_crypto_cmac_x, data, 16); - btstack_crypto_cmac_state = (btstack_crypto_cmac_block_current < (btstack_crypto_cmac_block_count - 1)) ? CMAC_CALC_MI : CMAC_CALC_MLAST; + btstack_crypto_cmac_state = (btstack_crypto_cmac_block_current < (btstack_crypto_cmac_block_count - 1u)) ? CMAC_CALC_MI : CMAC_CALC_MLAST; break; case CMAC_W4_MLAST: // done @@ -394,10 +394,10 @@ static void btstack_crypto_cmac_start(btstack_crypto_aes128_cmac_t * btstack_cry btstack_crypto_cmac_block_current = 0; // step 2: n := ceil(len/const_Bsize); - btstack_crypto_cmac_block_count = (btstack_crypto_cmac->size + 15) / 16; + btstack_crypto_cmac_block_count = (btstack_crypto_cmac->size + 15u) / 16u; // step 3: .. - if (btstack_crypto_cmac_block_count==0){ + if (btstack_crypto_cmac_block_count==0u){ btstack_crypto_cmac_block_count = 1; } log_info("btstack_crypto_cmac_start: len %u, block count %u", btstack_crypto_cmac->size, btstack_crypto_cmac_block_count); @@ -469,9 +469,9 @@ static void btstack_crypto_ccm_setup_a_i(btstack_crypto_ccm_t * btstack_crypto_c */ static void btstack_crypto_ccm_setup_b_0(btstack_crypto_ccm_t * btstack_crypto_ccm, uint8_t * b0){ - uint8_t m_prime = (btstack_crypto_ccm->auth_len - 2) / 2; + uint8_t m_prime = (btstack_crypto_ccm->auth_len - 2u) / 2u; uint8_t Adata = btstack_crypto_ccm->aad_len ? 1 : 0; - b0[0] = (Adata << 6) | (m_prime << 3) | 1 ; // Adata, M', L' = L - 1 + b0[0u] = (Adata << 6u) | (m_prime << 3u) | 1u ; // Adata, M', L' = L - 1 (void)memcpy(&b0[1], btstack_crypto_ccm->nonce, 13); big_endian_store_16(b0, 14, btstack_crypto_ccm->message_len); #ifdef DEBUG_CCM @@ -601,11 +601,11 @@ static void btstack_crypto_ccm_next_block(btstack_crypto_ccm_t * btstack_crypto_ #ifdef DEBUG_CCM printf("btstack_crypto_ccm_next_block (message len %u, block_len %u)\n", btstack_crypto_ccm->message_len, btstack_crypto_ccm->block_len); #endif - if (btstack_crypto_ccm->message_len == 0){ + if (btstack_crypto_ccm->message_len == 0u){ btstack_crypto_ccm->state = CCM_CALCULATE_S0; } else { btstack_crypto_ccm->state = state_when_done; - if (btstack_crypto_ccm->block_len == 0){ + if (btstack_crypto_ccm->block_len == 0u){ btstack_crypto_done(&btstack_crypto_ccm->btstack_crypto); } } @@ -654,7 +654,7 @@ static void btstack_crypto_ccm_handle_aad_xn(btstack_crypto_ccm_t * btstack_cryp printf_hexdump(btstack_crypto_ccm->x_i, 16); #endif // more aad? - if (btstack_crypto_ccm->aad_offset < (btstack_crypto_ccm->aad_len + 2)){ + if (btstack_crypto_ccm->aad_offset < (btstack_crypto_ccm->aad_len + 2u)){ btstack_crypto_ccm->state = CCM_CALCULATE_AAD_XN; } else { // done @@ -755,14 +755,14 @@ static void btstack_crypto_ccm_calc_xn(btstack_crypto_ccm_t * btstack_crypto_ccm uint8_t i; uint8_t bytes_to_decrypt = btstack_crypto_ccm->block_len; // use explicit min implementation as c-stat worried about out-of-bounds-reads - if (bytes_to_decrypt > 16) { + if (bytes_to_decrypt > 16u) { bytes_to_decrypt = 16; } for (i = 0; i < bytes_to_decrypt ; i++){ btstack_crypto_ccm_buffer[i] = btstack_crypto_ccm->x_i[i] ^ plaintext[i]; } (void)memcpy(&btstack_crypto_ccm_buffer[i], &btstack_crypto_ccm->x_i[i], - 16 - bytes_to_decrypt); + 16u - bytes_to_decrypt); #ifdef DEBUG_CCM printf("%16s: ", "Xn XOR bn"); printf_hexdump(btstack_crypto_ccm_buffer, 16); @@ -778,17 +778,17 @@ static void btstack_crypto_ccm_calc_xn(btstack_crypto_ccm_t * btstack_crypto_ccm static void btstack_crypto_ccm_calc_aad_xn(btstack_crypto_ccm_t * btstack_crypto_ccm){ // store length - if (btstack_crypto_ccm->aad_offset == 0){ + if (btstack_crypto_ccm->aad_offset == 0u){ uint8_t len_buffer[2]; big_endian_store_16(len_buffer, 0, btstack_crypto_ccm->aad_len); btstack_crypto_ccm->x_i[0] ^= len_buffer[0]; btstack_crypto_ccm->x_i[1] ^= len_buffer[1]; - btstack_crypto_ccm->aad_remainder_len += 2; - btstack_crypto_ccm->aad_offset += 2; + btstack_crypto_ccm->aad_remainder_len += 2u; + btstack_crypto_ccm->aad_offset += 2u; } // fill from input - uint16_t bytes_free = 16 - btstack_crypto_ccm->aad_remainder_len; + uint16_t bytes_free = 16u - btstack_crypto_ccm->aad_remainder_len; uint16_t bytes_to_copy = btstack_min(bytes_free, btstack_crypto_ccm->block_len); while (bytes_to_copy){ btstack_crypto_ccm->x_i[btstack_crypto_ccm->aad_remainder_len++] ^= *btstack_crypto_ccm->input++; @@ -799,11 +799,11 @@ static void btstack_crypto_ccm_calc_aad_xn(btstack_crypto_ccm_t * btstack_crypto } // if last block, fill with zeros - if (btstack_crypto_ccm->aad_offset == (btstack_crypto_ccm->aad_len + 2)){ + if (btstack_crypto_ccm->aad_offset == (btstack_crypto_ccm->aad_len + 2u)){ btstack_crypto_ccm->aad_remainder_len = 16; } // if not full, notify done - if (btstack_crypto_ccm->aad_remainder_len < 16){ + if (btstack_crypto_ccm->aad_remainder_len < 16u){ btstack_crypto_done(&btstack_crypto_ccm->btstack_crypto); return; } @@ -1001,8 +1001,8 @@ static void btstack_crypto_handle_random_data(const uint8_t * data, uint16_t len case BTSTACK_CRYPTO_ECC_P256_GENERATE_KEY: (void)memcpy(&btstack_crypto_ecc_p256_random[btstack_crypto_ecc_p256_random_len], data, 8); - btstack_crypto_ecc_p256_random_len += 8; - if (btstack_crypto_ecc_p256_random_len >= 64) { + btstack_crypto_ecc_p256_random_len += 8u; + if (btstack_crypto_ecc_p256_random_len >= 64u) { btstack_crypto_ecc_p256_key_generation_state = ECC_P256_KEY_GENERATION_ACTIVE; btstack_crypto_ecc_p256_generate_key_software(); btstack_crypto_ecc_p256_key_generation_state = ECC_P256_KEY_GENERATION_DONE; @@ -1105,7 +1105,7 @@ static void btstack_crypto_event_handler(uint8_t packet_type, uint16_t cid, uint btstack_crypto_handle_random_data(&packet[6], 8); } if (HCI_EVENT_IS_COMMAND_COMPLETE(packet, hci_read_local_supported_commands)){ - int ecdh_operations_supported = (packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+34] & 0x06) == 0x06; + int ecdh_operations_supported = (packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1u+34u] & 0x06u) == 0x06u; UNUSED(ecdh_operations_supported); log_info("controller supports ECDH operation: %u", ecdh_operations_supported); #ifdef ENABLE_ECC_P256 diff --git a/src/btstack_hid_parser.c b/src/btstack_hid_parser.c index 341b9aa8f..ccd468aa7 100644 --- a/src/btstack_hid_parser.c +++ b/src/btstack_hid_parser.c @@ -152,15 +152,15 @@ void btstack_hid_parse_descriptor_item(hid_descriptor_item_t * item, const uint8 const int hid_item_sizes[] = { 0, 1, 2, 4 }; // parse item header - if (hid_descriptor_len < 1) return; + if (hid_descriptor_len < 1u) return; uint16_t pos = 0; uint8_t item_header = hid_descriptor[pos++]; - item->data_size = hid_item_sizes[item_header & 0x03]; - item->item_type = (item_header & 0x0c) >> 2; - item->item_tag = (item_header & 0xf0) >> 4; + item->data_size = hid_item_sizes[item_header & 0x03u]; + item->item_type = (item_header & 0x0cu) >> 2u; + item->item_tag = (item_header & 0xf0u) >> 4u; // long item - if ((item->data_size == 2) && (item->item_tag == 0x0f) && (item->item_type == 3)){ - if (hid_descriptor_len < 3) return; + if ((item->data_size == 2u) && (item->item_tag == 0x0fu) && (item->item_type == 3u)){ + if (hid_descriptor_len < 3u) return; item->data_size = hid_descriptor[pos++]; item->item_tag = hid_descriptor[pos++]; } @@ -169,18 +169,18 @@ void btstack_hid_parse_descriptor_item(hid_descriptor_item_t * item, const uint8 // read item value if (hid_descriptor_len < item->item_size) return; - if (item->data_size > 4) return; + if (item->data_size > 4u) return; int i; - int sgnd = (item->item_type == Global) && (item->item_tag > 0) && (item->item_tag < 5); + int sgnd = (item->item_type == Global) && (item->item_tag > 0u) && (item->item_tag < 5u); int32_t value = 0; uint8_t latest_byte = 0; for (i=0;idata_size;i++){ latest_byte = hid_descriptor[pos++]; value = (latest_byte << (8*i)) | value; } - if (sgnd && (item->data_size > 0)){ - if (latest_byte & 0x80) { - value -= 1 << (item->data_size*8); + if (sgnd && (item->data_size > 0u)){ + if (latest_byte & 0x80u) { + value -= 1u << (item->data_size*8u); } } item->item_value = value; @@ -217,7 +217,7 @@ static void btstack_hid_handle_global_item(btstack_hid_parser_t * parser, hid_de } static void hid_find_next_usage(btstack_hid_parser_t * parser){ - while ((parser->available_usages == 0) && (parser->usage_pos < parser->descriptor_pos)){ + while ((parser->available_usages == 0u) && (parser->usage_pos < parser->descriptor_pos)){ hid_descriptor_item_t usage_item; // parser->usage_pos < parser->descriptor_pos < parser->descriptor_len btstack_hid_parse_descriptor_item(&usage_item, &parser->descriptor[parser->usage_pos], parser->descriptor_len - parser->usage_pos); @@ -225,7 +225,7 @@ static void hid_find_next_usage(btstack_hid_parser_t * parser){ parser->usage_page = usage_item.item_value; } if (usage_item.item_type == Local){ - uint32_t usage_value = (usage_item.data_size > 2) ? usage_item.item_value : ((parser->usage_page << 16) | usage_item.item_value); + uint32_t usage_value = (usage_item.data_size > 2u) ? usage_item.item_value : ((parser->usage_page << 16u) | usage_item.item_value); switch (usage_item.item_tag){ case Usage: parser->available_usages = 1; @@ -243,7 +243,7 @@ static void hid_find_next_usage(btstack_hid_parser_t * parser){ break; } if (parser->have_usage_min && parser->have_usage_max){ - parser->available_usages = parser->usage_maximum - parser->usage_minimum + 1; + parser->available_usages = parser->usage_maximum - parser->usage_minimum + 1u; parser->have_usage_min = 0; parser->have_usage_max = 0; } @@ -284,7 +284,7 @@ static void hid_process_item(btstack_hid_parser_t * parser, hid_descriptor_item_ if (parser->report[0] != parser->global_report_id){ return; } - parser->report_pos_in_bit += 8; + parser->report_pos_in_bit += 8u; } parser->active_record = 1; // handle constant fields used for padding @@ -297,7 +297,7 @@ static void hid_process_item(btstack_hid_parser_t * parser, hid_descriptor_item_ return; } // Empty Item - if (parser->global_report_count == 0) return; + if (parser->global_report_count == 0u) return; // let's start parser->required_usages = parser->global_report_count; } @@ -362,19 +362,19 @@ void btstack_hid_parser_get_field(btstack_hid_parser_t * parser, uint16_t * usag int is_variable = parser->descriptor_item.item_value & 2; int is_signed = parser->global_logical_minimum < 0; int pos_start = btstack_min( parser->report_pos_in_bit >> 3, parser->report_len); - int pos_end = btstack_min( (parser->report_pos_in_bit + parser->global_report_size - 1) >> 3, parser->report_len); + int pos_end = btstack_min( (parser->report_pos_in_bit + parser->global_report_size - 1u) >> 3u, parser->report_len); int bytes_to_read = pos_end - pos_start + 1; int i; uint32_t multi_byte_value = 0; for (i=0;i < bytes_to_read;i++){ multi_byte_value |= parser->report[pos_start+i] << (i*8); } - uint32_t unsigned_value = (multi_byte_value >> (parser->report_pos_in_bit & 0x07)) & ((1<global_report_size)-1); + uint32_t unsigned_value = (multi_byte_value >> (parser->report_pos_in_bit & 0x07u)) & ((1u<global_report_size)-1u); // log_debug("bit pos %2u, report size %u, start %u, end %u, len %u;; unsigned value %08x", parser->report_pos_in_bit, parser->global_report_size, pos_start, pos_end, parser->report_len, unsigned_value); if (is_variable){ - *usage = parser->usage_minimum & 0xffff; - if (is_signed && (unsigned_value & (1<<(parser->global_report_size-1)))){ - *value = unsigned_value - (1<global_report_size); + *usage = parser->usage_minimum & 0xffffu; + if (is_signed && (unsigned_value & (1u<<(parser->global_report_size-1u)))){ + *value = unsigned_value - (1u<global_report_size); } else { *value = unsigned_value; } @@ -390,20 +390,20 @@ void btstack_hid_parser_get_field(btstack_hid_parser_t * parser, uint16_t * usag parser->usage_minimum++; parser->available_usages--; } else { - if (parser->required_usages == 0){ + if (parser->required_usages == 0u){ parser->available_usages = 0; } } if (parser->available_usages) { return; } - if (parser->required_usages == 0){ + if (parser->required_usages == 0u){ hid_post_process_item(parser, &parser->descriptor_item); parser->state = BTSTACK_HID_PARSER_SCAN_FOR_REPORT_ITEM; btstack_hid_parser_find_next_usage(parser); } else { hid_find_next_usage(parser); - if (parser->available_usages == 0) { + if (parser->available_usages == 0u) { parser->state = BTSTACK_HID_PARSER_COMPLETE; } } diff --git a/src/btstack_resample.c b/src/btstack_resample.c index 57e9cc2ea..a49dfee8c 100644 --- a/src/btstack_resample.c +++ b/src/btstack_resample.c @@ -57,12 +57,12 @@ uint16_t btstack_resample_block(btstack_resample_t * context, const int16_t * in uint16_t dest_samples = 0; // samples between last sample of previous block and first sample in current block while (context->src_pos >= 0xffff0000){ - const uint16_t t = context->src_pos & 0xffff; + const uint16_t t = context->src_pos & 0xffffu; int i; for (i=0;inum_channels;i++){ int s1 = context->last_sample[i]; int s2 = input_buffer[i]; - int os = ((s1*(0x10000 - t)) + (s2*t)) >> 16; + int os = ((s1*(0x10000u - t)) + (s2*t)) >> 16u; output_buffer[dest_samples++] = os; } dest_frames++; @@ -71,10 +71,10 @@ uint16_t btstack_resample_block(btstack_resample_t * context, const int16_t * in // process current block while (true){ const uint16_t src_pos = context->src_pos >> 16; - const uint16_t t = context->src_pos & 0xffff; + const uint16_t t = context->src_pos & 0xffffu; int index = src_pos * context->num_channels; int i; - if (src_pos >= (num_frames - 1)){ + if (src_pos >= (num_frames - 1u)){ // store last sample for (i=0;inum_channels;i++){ context->last_sample[i] = input_buffer[index++]; @@ -86,7 +86,7 @@ uint16_t btstack_resample_block(btstack_resample_t * context, const int16_t * in for (i=0;inum_channels;i++){ int s1 = input_buffer[index]; int s2 = input_buffer[index+context->num_channels]; - int os = ((s1*(0x10000 - t)) + (s2*t)) >> 16; + int os = ((s1*(0x10000u - t)) + (s2*t)) >> 16u; output_buffer[dest_samples++] = os; index++; } diff --git a/src/btstack_ring_buffer.c b/src/btstack_ring_buffer.c index 76fe8ae1b..2014ca0a1 100644 --- a/src/btstack_ring_buffer.c +++ b/src/btstack_ring_buffer.c @@ -68,7 +68,7 @@ uint32_t btstack_ring_buffer_bytes_available(btstack_ring_buffer_t * ring_buffer // test if ring buffer is empty int btstack_ring_buffer_empty(btstack_ring_buffer_t * ring_buffer){ - return btstack_ring_buffer_bytes_available(ring_buffer) == 0; + return btstack_ring_buffer_bytes_available(ring_buffer) == 0u; } // @@ -83,7 +83,7 @@ int btstack_ring_buffer_write(btstack_ring_buffer_t * ring_buffer, uint8_t * dat } // simplify logic below by asserting data_length > 0 - if (data_length == 0) return 0; + if (data_length == 0u) return 0u; // copy first chunk unsigned int bytes_until_end = ring_buffer->size - ring_buffer->last_written_index; @@ -119,7 +119,7 @@ void btstack_ring_buffer_read(btstack_ring_buffer_t * ring_buffer, uint8_t * dat *number_of_bytes_read = data_length; // simplify logic below by asserting data_length > 0 - if (data_length == 0) return; + if (data_length == 0u) return; // copy first chunk unsigned int bytes_until_end = ring_buffer->size - ring_buffer->last_read_index; diff --git a/src/btstack_slip.c b/src/btstack_slip.c index ab70b8f1a..63d6e556b 100644 --- a/src/btstack_slip.c +++ b/src/btstack_slip.c @@ -92,7 +92,7 @@ void btstack_slip_encoder_start(const uint8_t * data, uint16_t len){ */ int btstack_slip_encoder_has_data(void){ if (encoder_state != SLIP_ENCODER_DEFAULT) return 1; - return encoder_len > 0; + return encoder_len > 0u; } /** diff --git a/src/btstack_util.c b/src/btstack_util.c index ab4bd10cc..4945d1969 100644 --- a/src/btstack_util.c +++ b/src/btstack_util.c @@ -393,7 +393,7 @@ uint32_t btstack_atoi(const char *str){ char chr = *str; if (!chr || (chr < '0') || (chr > '9')) return val; - val = (val * 10) + (uint8_t)(chr - '0'); + val = (val * 10u) + (uint8_t)(chr - '0'); str++; } } @@ -471,5 +471,5 @@ uint8_t btstack_crc8_check(uint8_t *data, uint16_t len, uint8_t check_sum){ /*-----------------------------------------------------------------------------------*/ uint8_t btstack_crc8_calc(uint8_t *data, uint16_t len){ /* Ones complement */ - return 0xFF - crc8(data, len); + return 0xFFu - crc8(data, len); } diff --git a/src/hci.c b/src/hci.c index c649a90e9..e8ffaf771 100644 --- a/src/hci.c +++ b/src/hci.c @@ -563,7 +563,7 @@ static int hci_can_send_comand_packet_transport(void){ // new functions replacing hci_can_send_packet_now[_using_packet_buffer] int hci_can_send_command_packet_now(void){ if (hci_can_send_comand_packet_transport() == 0) return 0; - return hci_stack->num_cmd_packets > 0; + return hci_stack->num_cmd_packets > 0u; } static int hci_transport_can_send_prepared_packet_now(uint8_t packet_type){ @@ -648,7 +648,7 @@ static int hci_send_acl_packet_fragments(hci_connection_t *connection){ // max ACL data packet length depends on connection type (LE vs. Classic) and available buffers uint16_t max_acl_data_packet_length = hci_stack->acl_data_packet_length; - if (hci_is_le_connection(connection) && (hci_stack->le_data_packets_length > 0)){ + if (hci_is_le_connection(connection) && (hci_stack->le_data_packets_length > 0u)){ max_acl_data_packet_length = hci_stack->le_data_packets_length; } @@ -667,7 +667,7 @@ static int hci_send_acl_packet_fragments(hci_connection_t *connection){ log_debug("hci_send_acl_packet_fragments loop entered"); // get current data - const uint16_t acl_header_pos = hci_stack->acl_fragmentation_pos - 4; + const uint16_t acl_header_pos = hci_stack->acl_fragmentation_pos - 4u; int current_acl_data_packet_length = hci_stack->acl_fragmentation_total_size - hci_stack->acl_fragmentation_pos; int more_fragments = 0; @@ -678,14 +678,14 @@ static int hci_send_acl_packet_fragments(hci_connection_t *connection){ } // copy handle_and_flags if not first fragment and update packet boundary flags to be 01 (continuing fragmnent) - if (acl_header_pos > 0){ + if (acl_header_pos > 0u){ uint16_t handle_and_flags = little_endian_read_16(hci_stack->hci_packet_buffer, 0); - handle_and_flags = (handle_and_flags & 0xcfff) | (1 << 12); + handle_and_flags = (handle_and_flags & 0xcfffu) | (1u << 12u); little_endian_store_16(hci_stack->hci_packet_buffer, acl_header_pos, handle_and_flags); } // update header len - little_endian_store_16(hci_stack->hci_packet_buffer, acl_header_pos + 2, current_acl_data_packet_length); + little_endian_store_16(hci_stack->hci_packet_buffer, acl_header_pos + 2u, current_acl_data_packet_length); // count packet connection->num_packets_sent++; @@ -846,7 +846,7 @@ static void acl_handler(uint8_t *packet, int size){ } // assert packet is complete - if ((acl_length + 4) != size){ + if ((acl_length + 4u) != size){ log_error("hci.c: acl_handler called with ACL packet of wrong size %d, expected %u => dropping packet", size, acl_length + 4); return; } @@ -862,16 +862,16 @@ static void acl_handler(uint8_t *packet, int size){ #endif // handle different packet types - switch (acl_flags & 0x03) { + switch (acl_flags & 0x03u) { case 0x01: // continuation fragment // sanity checks - if (conn->acl_recombination_pos == 0) { + if (conn->acl_recombination_pos == 0u) { log_error( "ACL Cont Fragment but no first fragment for handle 0x%02x", con_handle); return; } - if ((conn->acl_recombination_pos + acl_length) > (4 + HCI_ACL_BUFFER_SIZE)){ + if ((conn->acl_recombination_pos + acl_length) > (4u + HCI_ACL_BUFFER_SIZE)){ log_error( "ACL Cont Fragment to large: combined packet %u > buffer size %u for handle 0x%02x", conn->acl_recombination_pos + acl_length, 4 + HCI_ACL_BUFFER_SIZE, con_handle); conn->acl_recombination_pos = 0; @@ -887,7 +887,7 @@ static void acl_handler(uint8_t *packet, int size){ // conn->acl_recombination_pos, conn->acl_recombination_length); // forward complete L2CAP packet if complete. - if (conn->acl_recombination_pos >= (conn->acl_recombination_length + 4 + 4)){ // pos already incl. ACL header + if (conn->acl_recombination_pos >= (conn->acl_recombination_length + 4u + 4u)){ // pos already incl. ACL header hci_emit_acl_packet(&conn->acl_recombination_buffer[HCI_INCOMING_PRE_BUFFER_SIZE], conn->acl_recombination_pos); // reset recombination buffer conn->acl_recombination_length = 0; @@ -909,9 +909,9 @@ static void acl_handler(uint8_t *packet, int size){ // log_info( "ACL First Fragment: acl_len %u, l2cap_len %u", acl_length, l2cap_length); // compare fragment size to L2CAP packet size - if (acl_length >= (l2cap_length + 4)){ + if (acl_length >= (l2cap_length + 4u)){ // forward fragment as L2CAP packet - hci_emit_acl_packet(packet, acl_length + 4); + hci_emit_acl_packet(packet, acl_length + 4u); } else { if (acl_length > HCI_ACL_BUFFER_SIZE){ @@ -922,10 +922,10 @@ static void acl_handler(uint8_t *packet, int size){ // store first fragment and tweak acl length for complete package (void)memcpy(&conn->acl_recombination_buffer[HCI_INCOMING_PRE_BUFFER_SIZE], - packet, acl_length + 4); - conn->acl_recombination_pos = acl_length + 4; + packet, acl_length + 4u); + conn->acl_recombination_pos = acl_length + 4u; conn->acl_recombination_length = l2cap_length; - little_endian_store_16(conn->acl_recombination_buffer, HCI_INCOMING_PRE_BUFFER_SIZE + 2, l2cap_length +4); + little_endian_store_16(conn->acl_recombination_buffer, HCI_INCOMING_PRE_BUFFER_SIZE + 2u, l2cap_length +4u); } break; @@ -1037,12 +1037,12 @@ int hci_extended_sco_link_supported(void){ int hci_non_flushable_packet_boundary_flag_supported(void){ // No. 54, byte 6, bit 6 - return (hci_stack->local_supported_features[6] & (1 << 6)) != 0; + return (hci_stack->local_supported_features[6u] & (1u << 6u)) != 0u; } static int gap_ssp_supported(void){ // No. 51, byte 6, bit 3 - return (hci_stack->local_supported_features[6] & (1 << 3)) != 0; + return (hci_stack->local_supported_features[6u] & (1u << 3u)) != 0u; } static int hci_classic_supported(void){ @@ -1057,7 +1057,7 @@ static int hci_classic_supported(void){ static int hci_le_supported(void){ #ifdef ENABLE_BLE // No. 37, byte 4, bit 6 = LE Supported (Controller) - return (hci_stack->local_supported_features[4] & (1 << 6)) != 0; + return (hci_stack->local_supported_features[4u] & (1u << 6u)) != 0u; #else return 0; #endif @@ -1091,9 +1091,9 @@ void le_handle_advertisement_report(uint8_t *packet, uint16_t size){ // sanity checks on data_length: uint8_t data_length = packet[offset + 8]; if (data_length > LE_ADVERTISING_DATA_SIZE) return; - if ((offset + 9 + data_length + 1) > size) return; + if ((offset + 9u + data_length + 1u) > size) return; // setup event - uint8_t event_size = 10 + data_length; + uint8_t event_size = 10u + data_length; int pos = 0; event[pos++] = GAP_EVENT_ADVERTISING_REPORT; event[pos++] = event_size; @@ -1105,7 +1105,7 @@ void le_handle_advertisement_report(uint8_t *packet, uint16_t size){ offset++; (void)memcpy(&event[pos], &packet[offset], data_length); pos += data_length; - offset += data_length + 1; // rssi + offset += data_length + 1u; // rssi hci_emit_event(event, pos, 1); } } @@ -1251,7 +1251,7 @@ static void hci_initializing_run(void){ hci_stack->chipset->set_baudrate_command(baud_rate, hci_stack->hci_packet_buffer); hci_stack->last_cmd_opcode = little_endian_read_16(hci_stack->hci_packet_buffer, 0); hci_stack->substate = HCI_INIT_W4_SEND_BAUD_CHANGE; - hci_send_cmd_packet(hci_stack->hci_packet_buffer, 3 + hci_stack->hci_packet_buffer[2]); + hci_send_cmd_packet(hci_stack->hci_packet_buffer, 3u + hci_stack->hci_packet_buffer[2u]); // STLC25000D: baudrate change happens within 0.5 s after command was send, // use timer to update baud rate after 100 ms (knowing exactly, when command was sent is non-trivial) if (hci_stack->manufacturer == BLUETOOTH_COMPANY_ID_ST_MICROELECTRONICS){ @@ -1265,7 +1265,7 @@ static void hci_initializing_run(void){ hci_stack->chipset->set_baudrate_command(baud_rate, hci_stack->hci_packet_buffer); hci_stack->last_cmd_opcode = little_endian_read_16(hci_stack->hci_packet_buffer, 0); hci_stack->substate = HCI_INIT_W4_SEND_BAUD_CHANGE_BCM; - hci_send_cmd_packet(hci_stack->hci_packet_buffer, 3 + hci_stack->hci_packet_buffer[2]); + hci_send_cmd_packet(hci_stack->hci_packet_buffer, 3u + hci_stack->hci_packet_buffer[2u]); break; } case HCI_INIT_CUSTOM_INIT: @@ -1301,7 +1301,7 @@ static void hci_initializing_run(void){ } if (send_cmd){ - int size = 3 + hci_stack->hci_packet_buffer[2]; + int size = 3u + hci_stack->hci_packet_buffer[2u]; hci_stack->last_cmd_opcode = little_endian_read_16(hci_stack->hci_packet_buffer, 0); hci_dump_packet(HCI_COMMAND_DATA_PACKET, 0, hci_stack->hci_packet_buffer, size); hci_stack->hci_transport->send_packet(HCI_COMMAND_DATA_PACKET, hci_stack->hci_packet_buffer, size); @@ -1346,7 +1346,7 @@ static void hci_initializing_run(void){ hci_stack->chipset->set_bd_addr_command(hci_stack->custom_bd_addr, hci_stack->hci_packet_buffer); hci_stack->last_cmd_opcode = little_endian_read_16(hci_stack->hci_packet_buffer, 0); hci_stack->substate = HCI_INIT_W4_SET_BD_ADDR; - hci_send_cmd_packet(hci_stack->hci_packet_buffer, 3 + hci_stack->hci_packet_buffer[2]); + hci_send_cmd_packet(hci_stack->hci_packet_buffer, 3u + hci_stack->hci_packet_buffer[2u]); break; #endif @@ -1760,7 +1760,7 @@ static void hci_initializing_event_handler(const uint8_t * packet, uint16_t size #endif case HCI_INIT_W4_READ_BD_ADDR: // only read buffer size if supported - if (hci_stack->local_supported_commands[0] & 0x01) { + if (hci_stack->local_supported_commands[0u] & 0x01u) { hci_stack->substate = HCI_INIT_READ_BUFFER_SIZE; return; } @@ -1788,14 +1788,14 @@ static void hci_initializing_event_handler(const uint8_t * packet, uint16_t size #ifdef ENABLE_BLE case HCI_INIT_W4_LE_READ_BUFFER_SIZE: // skip write le host if not supported (e.g. on LE only EM9301) - if (hci_stack->local_supported_commands[0] & 0x02) break; + if (hci_stack->local_supported_commands[0u] & 0x02u) break; hci_stack->substate = HCI_INIT_LE_SET_EVENT_MASK; return; #ifdef ENABLE_LE_DATA_LENGTH_EXTENSION case HCI_INIT_W4_WRITE_LE_HOST_SUPPORTED: log_info("Supported commands %x", hci_stack->local_supported_commands[0] & 0x30); - if ((hci_stack->local_supported_commands[0] & 0x30) == 0x30){ + if ((hci_stack->local_supported_commands[0u] & 0x30u) == 0x30u){ hci_stack->substate = HCI_INIT_LE_SET_EVENT_MASK; return; } @@ -1813,7 +1813,7 @@ static void hci_initializing_event_handler(const uint8_t * packet, uint16_t size case HCI_INIT_W4_WRITE_INQUIRY_MODE: // skip write secure connections host support if not supported or disabled - if (!hci_stack->secure_connections_enable || (hci_stack->local_supported_commands[1] & 0x02) == 0) { + if (!hci_stack->secure_connections_enable || (hci_stack->local_supported_commands[1u] & 0x02u) == 0u) { hci_stack->substate = HCI_INIT_WRITE_SCAN_ENABLE; return; } @@ -2093,17 +2093,17 @@ static void handle_command_complete_event(uint8_t * packet, uint16_t size){ break; case HCI_OPCODE_HCI_READ_LOCAL_SUPPORTED_COMMANDS: hci_stack->local_supported_commands[0] = - ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+14] & 0x80) >> 7) | // bit 0 = Octet 14, bit 7 / Read Buffer Size - ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+24] & 0x40) >> 5) | // bit 1 = Octet 24, bit 6 / Write Le Host Supported - ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+10] & 0x10) >> 2) | // bit 2 = Octet 10, bit 4 / Write Synchronous Flow Control Enable - ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+18] & 0x08) ) | // bit 3 = Octet 18, bit 3 / Write Default Erroneous Data Reporting - ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+34] & 0x01) << 4) | // bit 4 = Octet 34, bit 0 / LE Write Suggested Default Data Length - ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+35] & 0x08) << 2) | // bit 5 = Octet 35, bit 3 / LE Read Maximum Data Length - ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+35] & 0x20) << 1) | // bit 6 = Octet 35, bit 5 / LE Set Default PHY - ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+20] & 0x10) << 3); // bit 7 = Octet 20, bit 4 / Read Encryption Key Size + ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1u+14u] & 0x80u) >> 7u) | // bit 0 = Octet 14, bit 7 / Read Buffer Size + ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1u+24u] & 0x40u) >> 5u) | // bit 1 = Octet 24, bit 6 / Write Le Host Supported + ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1u+10u] & 0x10u) >> 2u) | // bit 2 = Octet 10, bit 4 / Write Synchronous Flow Control Enable + ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1u+18u] & 0x08u) ) | // bit 3 = Octet 18, bit 3 / Write Default Erroneous Data Reporting + ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1u+34u] & 0x01u) << 4u) | // bit 4 = Octet 34, bit 0 / LE Write Suggested Default Data Length + ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1u+35u] & 0x08u) << 2u) | // bit 5 = Octet 35, bit 3 / LE Read Maximum Data Length + ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1u+35u] & 0x20u) << 1u) | // bit 6 = Octet 35, bit 5 / LE Set Default PHY + ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1u+20u] & 0x10u) << 3u); // bit 7 = Octet 20, bit 4 / Read Encryption Key Size hci_stack->local_supported_commands[1] = - ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+ 2] & 0x40) >> 6) | // bit 8 = Octet 2, bit 6 / Read Remote Extended Features - ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1+32] & 0x08) >> 2); // bit 9 = Octet 32, bit 3 / Write Secure Connections Host + ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1u+ 2u] & 0x40u) >> 6u) | // bit 8 = Octet 2, bit 6 / Read Remote Extended Features + ((packet[OFFSET_OF_DATA_IN_COMMAND_COMPLETE+1u+32u] & 0x08u) >> 2u); // bit 9 = Octet 32, bit 3 / Write Secure Connections Host log_info("Local supported commands summary %02x - %02x", hci_stack->local_supported_commands[0], hci_stack->local_supported_commands[1]); break; #ifdef ENABLE_CLASSIC @@ -2136,7 +2136,7 @@ static void event_handler(uint8_t *packet, int size){ uint16_t event_length = packet[1]; // assert packet is complete - if (size != (event_length + 2)){ + if (size != (event_length + 2u)){ log_error("event_handler called with packet of wrong size %d, expected %u => dropping packet", size, event_length + 2); return; } @@ -2186,7 +2186,7 @@ static void event_handler(uint8_t *packet, int size){ hci_stack->outgoing_addr_type = BD_ADDR_TYPE_UNKNOWN; // error => outgoing connection failed - if ((conn != NULL) && (status != 0)){ + if ((conn != NULL) && (status != 0u)){ hci_handle_connection_failed(conn, status); } } @@ -2195,13 +2195,13 @@ static void event_handler(uint8_t *packet, int size){ case HCI_EVENT_NUMBER_OF_COMPLETED_PACKETS:{ if (size < 3) return; uint16_t num_handles = packet[2]; - if (size != (3 + num_handles * 4)) return; + if (size != (3u + num_handles * 4u)) return; uint16_t offset = 3; for (i=0; iacl_fragmentation_total_size > 0) { + if (hci_stack->acl_fragmentation_total_size > 0u) { if (handle == READ_ACL_CONNECTION_HANDLE(hci_stack->hci_packet_buffer)){ - int release_buffer = hci_stack->acl_fragmentation_tx_active == 0; + int release_buffer = hci_stack->acl_fragmentation_tx_active == 0u; log_info("drop fragmented ACL data for closed connection, release buffer %u", release_buffer); hci_stack->acl_fragmentation_total_size = 0; hci_stack->acl_fragmentation_pos = 0; @@ -3505,7 +3505,7 @@ static void hci_halting_timeout_handler(btstack_timer_source_t * ds){ } static bool hci_run_acl_fragments(void){ - if (hci_stack->acl_fragmentation_total_size > 0) { + if (hci_stack->acl_fragmentation_total_size > 0u) { hci_con_handle_t con_handle = READ_ACL_CONNECTION_HANDLE(hci_stack->hci_packet_buffer); hci_connection_t *connection = hci_connection_for_handle(con_handle); if (connection) { @@ -3596,11 +3596,11 @@ static bool hci_run_general_gap_le(void){ // advertisements, active scanning, and creating connections requires random address to be set if using private address if (hci_stack->state != HCI_STATE_WORKING) return false; - if ( (hci_stack->le_own_addr_type != BD_ADDR_TYPE_LE_PUBLIC) && (hci_stack->le_random_address_set == 0) ) return false; + if ( (hci_stack->le_own_addr_type != BD_ADDR_TYPE_LE_PUBLIC) && (hci_stack->le_random_address_set == 0u) ) return false; #ifdef ENABLE_LE_CENTRAL // parameter change requires scanning to be stopped first - if (hci_stack->le_scan_type != 0xff) { + if (hci_stack->le_scan_type != 0xffu) { if (hci_stack->le_scanning_active){ hci_stack->le_scanning_active = 0; hci_send_cmd(&hci_le_set_scan_enable, 0, 0); @@ -3986,7 +3986,7 @@ static bool hci_run_general_pending_commmands(void){ default: break; } - if (connection->le_phy_update_all_phys != 0xff){ + if (connection->le_phy_update_all_phys != 0xffu){ uint8_t all_phys = connection->le_phy_update_all_phys; connection->le_phy_update_all_phys = 0xff; hci_send_cmd(&hci_le_set_phy, connection->con_handle, all_phys, connection->le_phy_update_tx_phys, connection->le_phy_update_rx_phys, connection->le_phy_update_phy_options); @@ -4535,7 +4535,7 @@ void hci_emit_state(void){ log_info("BTSTACK_EVENT_STATE %u", hci_stack->state); uint8_t event[3]; event[0] = BTSTACK_EVENT_STATE; - event[1] = sizeof(event) - 2; + event[1] = sizeof(event) - 2u; event[2] = hci_stack->state; hci_emit_event(event, sizeof(event), 1); } @@ -4568,7 +4568,7 @@ static void hci_emit_l2cap_check_timeout(hci_connection_t *conn){ static void hci_emit_le_connection_complete(uint8_t address_type, bd_addr_t address, hci_con_handle_t con_handle, uint8_t status){ uint8_t event[21]; event[0] = HCI_EVENT_LE_META; - event[1] = sizeof(event) - 2; + event[1] = sizeof(event) - 2u; event[2] = HCI_SUBEVENT_LE_CONNECTION_COMPLETE; event[3] = status; little_endian_store_16(event, 4, con_handle); @@ -4593,7 +4593,7 @@ static void hci_emit_transport_packet_sent(void){ static void hci_emit_disconnection_complete(hci_con_handle_t con_handle, uint8_t reason){ uint8_t event[6]; event[0] = HCI_EVENT_DISCONNECTION_COMPLETE; - event[1] = sizeof(event) - 2; + event[1] = sizeof(event) - 2u; event[2] = 0; // status = OK little_endian_store_16(event, 3, con_handle); event[5] = reason; @@ -4604,7 +4604,7 @@ static void hci_emit_nr_connections_changed(void){ log_info("BTSTACK_EVENT_NR_CONNECTIONS_CHANGED %u", nr_hci_connections()); uint8_t event[3]; event[0] = BTSTACK_EVENT_NR_CONNECTIONS_CHANGED; - event[1] = sizeof(event) - 2; + event[1] = sizeof(event) - 2u; event[2] = nr_hci_connections(); hci_emit_event(event, sizeof(event), 1); } @@ -4613,7 +4613,7 @@ static void hci_emit_hci_open_failed(void){ log_info("BTSTACK_EVENT_POWERON_FAILED"); uint8_t event[2]; event[0] = BTSTACK_EVENT_POWERON_FAILED; - event[1] = sizeof(event) - 2; + event[1] = sizeof(event) - 2u; hci_emit_event(event, sizeof(event), 1); } @@ -4622,7 +4622,7 @@ static void hci_emit_dedicated_bonding_result(bd_addr_t address, uint8_t status) uint8_t event[9]; int pos = 0; event[pos++] = GAP_EVENT_DEDICATED_BONDING_COMPLETED; - event[pos++] = sizeof(event) - 2; + event[pos++] = sizeof(event) - 2u; event[pos++] = status; reverse_bd_addr(address, &event[pos]); hci_emit_event(event, sizeof(event), 1); diff --git a/src/hci_cmd.c b/src/hci_cmd.c index ba41c6240..a8ae26ea9 100644 --- a/src/hci_cmd.c +++ b/src/hci_cmd.c @@ -72,7 +72,7 @@ */ uint16_t hci_cmd_create_from_template(uint8_t *hci_cmd_buffer, const hci_cmd_t *cmd, va_list argptr){ - hci_cmd_buffer[0] = cmd->opcode & 0xff; + hci_cmd_buffer[0] = cmd->opcode & 0xffu; hci_cmd_buffer[1] = cmd->opcode >> 8; int pos = 3; @@ -86,7 +86,7 @@ uint16_t hci_cmd_create_from_template(uint8_t *hci_cmd_buffer, const hci_cmd_t * case '2': // 16 bit value case 'H': // hci_handle word = va_arg(argptr, int); // minimal va_arg is int: 2 bytes on 8+16 bit CPUs - hci_cmd_buffer[pos++] = word & 0xff; + hci_cmd_buffer[pos++] = word & 0xffu; if (*format == '2') { hci_cmd_buffer[pos++] = word >> 8; } else if (*format == 'H') { @@ -128,13 +128,13 @@ uint16_t hci_cmd_create_from_template(uint8_t *hci_cmd_buffer, const hci_cmd_t * case 'N': { // UTF-8 string, null terminated ptr = va_arg(argptr, uint8_t *); uint16_t len = strlen((const char*) ptr); - if (len > 248) { + if (len > 248u) { len = 248; } (void)memcpy(&hci_cmd_buffer[pos], ptr, len); - if (len < 248) { + if (len < 248u) { // fill remaining space with zeroes - memset(&hci_cmd_buffer[pos+len], 0, 248-len); + memset(&hci_cmd_buffer[pos+len], 0u, 248u-len); } pos += 248; break; diff --git a/src/hci_dump.c b/src/hci_dump.c index 51022b565..06b05f80d 100644 --- a/src/hci_dump.c +++ b/src/hci_dump.c @@ -194,7 +194,7 @@ static void hci_dump_packetlogger_setup_header(uint8_t * buffer, uint32_t tv_sec } static void hci_dump_bluez_setup_header(uint8_t * buffer, uint32_t tv_sec, uint32_t tv_us, uint8_t packet_type, uint8_t in, uint16_t len){ - little_endian_store_16( buffer, 0, 1 + len); + little_endian_store_16( buffer, 0u, 1u + len); buffer[2] = in; buffer[3] = 0; little_endian_store_32( buffer, 4, tv_sec); @@ -251,13 +251,13 @@ static void printf_timestamp(void){ printf ("%s.%03u] ", time_string, milliseconds); #else uint32_t time_ms = btstack_run_loop_get_time_ms(); - int seconds = time_ms / 1000; + int seconds = time_ms / 1000u; int minutes = seconds / 60; unsigned int hours = minutes / 60; - uint16_t p_ms = time_ms - (seconds * 1000); + uint16_t p_ms = time_ms - (seconds * 1000u); uint16_t p_seconds = seconds - (minutes * 60); - uint16_t p_minutes = minutes - (hours * 60); + uint16_t p_minutes = minutes - (hours * 60u); printf("[%02u:%02u:%02u.%03u] ", hours, p_minutes, p_seconds, p_ms); #endif } @@ -302,8 +302,8 @@ void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t tv_us = curr_time.tv_usec; #else uint32_t time_ms = btstack_run_loop_get_time_ms(); - tv_us = time_ms * 1000; - tv_sec = 946728000UL + (time_ms / 1000); + tv_us = time_ms * 1000u; + tv_sec = 946728000UL + (time_ms / 1000u); #endif #ifdef ENABLE_SEGGER_RTT diff --git a/src/hci_transport_em9304_spi.c b/src/hci_transport_em9304_spi.c index 8dc339377..9b7aa60e3 100644 --- a/src/hci_transport_em9304_spi.c +++ b/src/hci_transport_em9304_spi.c @@ -269,7 +269,7 @@ static void em9304_spi_engine_run(void){ // check slave status and em9304 rx buffer space log_debug("TX: STS2 0x%02X", sStas.bytes[0]); max_bytes_to_send = sStas.bytes[0]; - if (max_bytes_to_send == 0){ + if (max_bytes_to_send == 0u){ // done em9304_engine_action_done(); // next @@ -282,7 +282,7 @@ static void em9304_spi_engine_run(void){ // send command em9304_spi_engine_state = SPI_EM9304_TX_W4_DATA_SENT; - if ( (((uintptr_t) em9304_spi_engine_tx_data) & 0x03) == 0){ + if ( (((uintptr_t) em9304_spi_engine_tx_data) & 0x03u) == 0u){ // 4-byte aligned btstack_em9304_spi->transmit( (uint8_t*) em9304_spi_engine_tx_data, em9304_spi_engine_tx_request_len); } else { @@ -305,7 +305,7 @@ static void em9304_spi_engine_run(void){ em9304_spi_engine_tx_request_len = 0; // notify higher layer when complete - if (em9304_spi_engine_tx_size == 0){ + if (em9304_spi_engine_tx_size == 0u){ (*em9304_spi_engine_tx_done_handler)(); } @@ -412,14 +412,14 @@ static void hci_transport_em9304_spi_process_data(void){ hci_transport_em9304_spi_read_pos += bytes_to_copy; hci_transport_em9304_spi_bytes_to_read -= bytes_to_copy; - if (hci_transport_em9304_spi_bytes_to_read == 0){ + if (hci_transport_em9304_spi_bytes_to_read == 0u){ hci_transport_em9304_spi_block_read(); } } } static void hci_transport_em9304_spi_packet_complete(void){ - packet_handler(hci_packet[0], &hci_packet[1], hci_transport_em9304_spi_read_pos-1); + packet_handler(hci_packet[0u], &hci_packet[1u], hci_transport_em9304_spi_read_pos-1u); hci_transport_em9304_spi_reset_statemachine(); } @@ -450,7 +450,7 @@ static void hci_transport_em9304_spi_block_read(void){ hci_transport_em9304_spi_reset_statemachine(); break; } - if (hci_transport_em9304_spi_bytes_to_read == 0){ + if (hci_transport_em9304_spi_bytes_to_read == 0u){ hci_transport_em9304_spi_packet_complete(); break; } @@ -465,7 +465,7 @@ static void hci_transport_em9304_spi_block_read(void){ hci_transport_em9304_spi_reset_statemachine(); break; } - if (hci_transport_em9304_spi_bytes_to_read == 0){ + if (hci_transport_em9304_spi_bytes_to_read == 0u){ hci_transport_em9304_spi_packet_complete(); break; } diff --git a/src/hci_transport_h4.c b/src/hci_transport_h4.c index 4d6d1def8..d4640619d 100644 --- a/src/hci_transport_h4.c +++ b/src/hci_transport_h4.c @@ -215,7 +215,7 @@ static void hci_transport_h4_packet_complete(void){ #endif } #endif - uint16_t packet_len = read_pos-1; + uint16_t packet_len = read_pos-1u; // reset state machine before delivering packet to stack as it might close the transport hci_transport_h4_reset_statemachine(); @@ -309,7 +309,7 @@ static void hci_transport_h4_block_read(void){ #endif // forward packet if payload size == 0 - if (h4_state == H4_W4_PAYLOAD && bytes_to_read == 0) { + if (h4_state == H4_W4_PAYLOAD && bytes_to_read == 0u) { hci_transport_h4_packet_complete(); } diff --git a/src/hci_transport_h5.c b/src/hci_transport_h5.c index 7a219942b..87344ffb4 100644 --- a/src/hci_transport_h5.c +++ b/src/hci_transport_h5.c @@ -166,8 +166,8 @@ static uint16_t crc16_ccitt_update (uint16_t crc, uint8_t ch){ 0xc60c, 0xd68d, 0xe70e, 0xf78f }; - crc = (crc >> 4) ^ crc16_ccitt_table[(crc ^ ch) & 0x000f]; - crc = (crc >> 4) ^ crc16_ccitt_table[(crc ^ (ch >> 4)) & 0x000f]; + crc = (crc >> 4u) ^ crc16_ccitt_table[(crc ^ ch) & 0x000fu]; + crc = (crc >> 4u) ^ crc16_ccitt_table[(crc ^ (ch >> 4u)) & 0x000fu]; return crc; } @@ -176,7 +176,7 @@ static uint16_t btstack_reverse_bits_16(uint16_t value){ int i; for (i = 0; i < 16; i++) { reverse = reverse << 1; - reverse |= value & 1; + reverse |= value & 1u; value = value >> 1; } return reverse; @@ -255,7 +255,7 @@ static void hci_transport_slip_send_frame(const uint8_t * header, const uint8_t // store data integrity check info slip_outgoing_dic = data_integrity_check; - slip_outgoing_dic_present = header[0] & 0x40; + slip_outgoing_dic_present = header[0] & 0x40u; // Start of Frame slip_outgoing_buffer[pos++] = BTSTACK_SLIP_SOF; @@ -290,9 +290,9 @@ static void hci_transport_link_calc_header(uint8_t * header, uint16_t payload_length){ header[0] = sequence_nr | (acknowledgement_nr << 3) | (data_integrity_check_present << 6) | (reliable_packet << 7); - header[1] = packet_type | ((payload_length & 0x0f) << 4); + header[1 = packet_type | ((payload_length & 0x0fu) << 4u); header[2] = payload_length >> 4; - header[3] = 0xff - (header[0] + header[1] + header[2]); + header[3] = 0xffu - (header[0u] + header[1u] + header[2u]); } static void hci_transport_link_send_control(const uint8_t * message, int message_len){ @@ -511,7 +511,7 @@ static void hci_transport_h5_emit_sleep_state(int sleep_active){ log_info("emit_sleep_state: %u", sleep_active); uint8_t event[3]; event[0] = HCI_EVENT_TRANSPORT_SLEEP_MODE; - event[1] = sizeof(event) - 2; + event[1] = sizeof(event) - 2u; event[2] = sleep_active; packet_handler(HCI_EVENT_PACKET, &event[0], sizeof(event)); } @@ -521,17 +521,17 @@ static void hci_transport_h5_process_frame(uint16_t frame_size){ static const uint8_t link_control_config_prefix_len = 2; static const uint8_t link_control_config_response_prefix_len = 2; - if (frame_size < 4) return; + if (frame_size < 4u) return; uint8_t * slip_header = &hci_packet_with_pre_buffer[HCI_INCOMING_PRE_BUFFER_SIZE]; uint8_t * slip_payload = &hci_packet_with_pre_buffer[HCI_INCOMING_PRE_BUFFER_SIZE + 4]; - int frame_size_without_header = frame_size - 4; + int frame_size_without_header = frame_size - 4u; - uint8_t seq_nr = slip_header[0] & 0x07; - uint8_t ack_nr = (slip_header[0] >> 3) & 0x07; - uint8_t data_integrity_check_present = (slip_header[0] & 0x40) != 0; - uint8_t reliable_packet = (slip_header[0] & 0x80) != 0; - uint8_t link_packet_type = slip_header[1] & 0x0f; + uint8_t seq_nr = slip_header[0u] & 0x07u; + uint8_t ack_nr = (slip_header[0u] >> 3u) & 0x07u; + uint8_t data_integrity_check_present = (slip_header[0u] & 0x40u) != 0u; + uint8_t reliable_packet = (slip_header[0u] & 0x80u) != 0u; + uint8_t link_packet_type = slip_header[1u] & 0x0fu; uint16_t link_payload_len = (slip_header[1] >> 4) | (slip_header[2] << 4); log_debug("process_frame, reliable %u, packet type %u, seq_nr %u, ack_nr %u , dic %u, payload 0x%04x bytes", reliable_packet, link_packet_type, seq_nr, ack_nr, data_integrity_check_present, frame_size_without_header); @@ -549,7 +549,7 @@ static void hci_transport_h5_process_frame(uint16_t frame_size){ // validate header checksum uint8_t header_checksum = slip_header[0] + slip_header[1] + slip_header[2] + slip_header[3]; - if (header_checksum != 0xff){ + if (header_checksum != 0xffu){ log_info("header checksum 0x%02x (instead of 0xff)", header_checksum); return; } @@ -610,7 +610,7 @@ static void hci_transport_h5_process_frame(uint16_t frame_size){ } if (memcmp(slip_payload, link_control_config_response, link_control_config_response_prefix_len) == 0){ uint8_t config = slip_payload[2]; - link_peer_supports_data_integrity_check = (config & 0x10) != 0; + link_peer_supports_data_integrity_check = (config & 0x10u) != 0u; log_info("link received config response 0x%02x, data integrity check supported %u", config, link_peer_supports_data_integrity_check); link_state = LINK_ACTIVE; btstack_run_loop_remove_timer(&link_timer); @@ -717,10 +717,10 @@ static void hci_transport_h5_process_frame(uint16_t frame_size){ // recommendet time until resend: 3 * time of largest packet static uint16_t hci_transport_link_calc_resend_timeout(uint32_t baudrate){ uint32_t max_packet_size_in_bit = (HCI_INCOMING_PACKET_BUFFER_SIZE + 6) << 3; - uint32_t t_max_x3_ms = max_packet_size_in_bit * 3000 / baudrate; + uint32_t t_max_x3_ms = max_packet_size_in_bit * 3000u / baudrate; // allow for BTstack logging and other delays - t_max_x3_ms += 50; + t_max_x3_ms += 50u; log_info("resend timeout for %"PRIu32" baud: %u ms", baudrate, (int) t_max_x3_ms); return t_max_x3_ms; @@ -745,7 +745,7 @@ static void hci_transport_h5_block_received(void){ if (hci_transport_h5_active == 0) return; // track start time when receiving first byte // a bit hackish - if ((hci_transport_h5_receive_start == 0) && (hci_transport_link_read_byte != BTSTACK_SLIP_SOF)){ + if ((hci_transport_h5_receive_start == 0u) && (hci_transport_link_read_byte != BTSTACK_SLIP_SOF)){ hci_transport_h5_receive_start = btstack_run_loop_get_time_ms(); } btstack_slip_decoder_process(hci_transport_link_read_byte); @@ -753,7 +753,7 @@ static void hci_transport_h5_block_received(void){ if (frame_size) { // track time uint32_t packet_receive_time = btstack_run_loop_get_time_ms() - hci_transport_h5_receive_start; - uint32_t nominal_time = (frame_size + 6) * 10 * 1000 / uart_config.baudrate; + uint32_t nominal_time = (frame_size + 6u) * 10u * 1000u / uart_config.baudrate; UNUSED(nominal_time); UNUSED(packet_receive_time); log_info("slip frame time %u ms for %u decoded bytes. nomimal time %u ms", (int) packet_receive_time, frame_size, (int) nominal_time); diff --git a/src/l2cap.c b/src/l2cap.c index dd46fb464..2b3574885 100644 --- a/src/l2cap.c +++ b/src/l2cap.c @@ -848,7 +848,7 @@ static void l2cap_ertm_channel_send_information_frame(l2cap_channel_t * channel) #ifdef L2CAP_USES_CHANNELS static uint16_t l2cap_next_local_cid(void){ do { - if (local_source_cid == 0xffff) { + if (local_source_cid == 0xffffu) { local_source_cid = 0x40; } else { local_source_cid++; @@ -859,7 +859,7 @@ static uint16_t l2cap_next_local_cid(void){ #endif static uint8_t l2cap_next_sig_id(void){ - if (sig_seq_nr == 0xff) { + if (sig_seq_nr == 0xffu) { sig_seq_nr = 1; } else { sig_seq_nr++; @@ -953,11 +953,11 @@ void l2cap_release_packet_buffer(void){ static void l2cap_setup_header(uint8_t * acl_buffer, hci_con_handle_t con_handle, uint8_t packet_boundary, uint16_t remote_cid, uint16_t len){ // 0 - Connection handle : PB=pb : BC=00 - little_endian_store_16(acl_buffer, 0, con_handle | (packet_boundary << 12) | (0 << 14)); + little_endian_store_16(acl_buffer, 0u, con_handle | (packet_boundary << 12u) | (0u << 14u)); // 2 - ACL length - little_endian_store_16(acl_buffer, 2, len + 4); + little_endian_store_16(acl_buffer, 2u, len + 4u); // 4 - L2CAP packet length - little_endian_store_16(acl_buffer, 4, len + 0); + little_endian_store_16(acl_buffer, 4u, len + 0u); // 6 - L2CAP channel DEST little_endian_store_16(acl_buffer, 6, remote_cid); } @@ -980,7 +980,7 @@ int l2cap_send_prepared_connectionless(hci_con_handle_t con_handle, uint16_t cid uint8_t *acl_buffer = hci_get_outgoing_packet_buffer(); l2cap_setup_header(acl_buffer, con_handle, 0, cid, len); // send - return hci_send_acl_packet_buffer(len+8); + return hci_send_acl_packet_buffer(len+8u); } // assumption - only on LE connections @@ -1003,7 +1003,7 @@ static void l2cap_emit_can_send_now(btstack_packet_handler_t packet_handler, uin log_debug("L2CAP_EVENT_CHANNEL_CAN_SEND_NOW local_cid 0x%x", channel); uint8_t event[4]; event[0] = L2CAP_EVENT_CAN_SEND_NOW; - event[1] = sizeof(event) - 2; + event[1] = sizeof(event) - 2u; little_endian_store_16(event, 2, channel); hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); packet_handler(HCI_EVENT_PACKET, channel, event, sizeof(event)); @@ -1017,7 +1017,7 @@ static void l2cap_dispatch_to_channel(l2cap_channel_t *channel, uint8_t type, ui static void l2cap_emit_simple_event_with_cid(l2cap_channel_t * channel, uint8_t event_code){ uint8_t event[4]; event[0] = event_code; - event[1] = sizeof(event) - 2; + event[1] = sizeof(event) - 2u; little_endian_store_16(event, 2, channel->local_cid); hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); l2cap_dispatch_to_channel(channel, HCI_EVENT_PACKET, event, sizeof(event)); @@ -1110,14 +1110,14 @@ static l2cap_fixed_channel_t * l2cap_channel_item_by_cid(uint16_t cid){ // used for fixed channels in LE (ATT/SM) and Classic (Connectionless Channel). CID < 0x04 static l2cap_fixed_channel_t * l2cap_fixed_channel_for_channel_id(uint16_t local_cid){ - if (local_cid >= 0x40) return NULL; + if (local_cid >= 0x40u) return NULL; return (l2cap_fixed_channel_t*) l2cap_channel_item_by_cid(local_cid); } // used for Classic Channels + LE Data Channels. local_cid >= 0x40 #ifdef L2CAP_USES_CHANNELS static l2cap_channel_t * l2cap_get_channel_for_local_cid(uint16_t local_cid){ - if (local_cid < 0x40) return NULL; + if (local_cid < 0x40u) return NULL; return (l2cap_channel_t*) l2cap_channel_item_by_cid(local_cid); } @@ -1379,7 +1379,7 @@ uint16_t l2cap_max_mtu(void){ #ifdef ENABLE_BLE uint16_t l2cap_max_le_mtu(void){ - if (l2cap_le_custom_max_mtu != 0) return l2cap_le_custom_max_mtu; + if (l2cap_le_custom_max_mtu != 0u) return l2cap_le_custom_max_mtu; return l2cap_max_mtu(); } @@ -2119,7 +2119,7 @@ static bool l2cap_channel_ready_to_send(l2cap_channel_t * channel){ #ifdef ENABLE_LE_DATA_CHANNELS case L2CAP_CHANNEL_TYPE_LE_DATA_CHANNEL: if (channel->send_sdu_buffer == NULL) return false; - if (channel->credits_outgoing == 0) return false; + if (channel->credits_outgoing == 0u) return false; return hci_can_send_acl_le_packet_now() != 0; #endif #endif @@ -3052,7 +3052,7 @@ static int l2cap_le_signaling_handler_dispatch(hci_con_handle_t handle, uint8_t case CONNECTION_PARAMETER_UPDATE_REQUEST: // check size - if (len < 8) return 0; + if (len < 8u) return 0u; connection = hci_connection_for_handle(handle); if (connection){ if (connection->role != HCI_ROLE_MASTER){ @@ -3091,7 +3091,7 @@ static int l2cap_le_signaling_handler_dispatch(hci_con_handle_t handle, uint8_t case CONNECTION_PARAMETER_UPDATE_RESPONSE: // check size - if (len < 2) return 0; + if (len < 2u) return 0u; result = little_endian_read_16(command, 4); l2cap_emit_connection_parameter_update_response(handle, result); break; @@ -3127,7 +3127,7 @@ static int l2cap_le_signaling_handler_dispatch(hci_con_handle_t handle, uint8_t case LE_CREDIT_BASED_CONNECTION_REQUEST: // check size - if (len < 10) return 0; + if (len < 10u) return 0u; // get hci connection, bail if not found (must not happen) connection = hci_connection_for_handle(handle); @@ -3139,7 +3139,7 @@ static int l2cap_le_signaling_handler_dispatch(hci_con_handle_t handle, uint8_t source_cid = little_endian_read_16(command, 6); if (service){ - if (source_cid < 0x40){ + if (source_cid < 0x40u){ // 0x0009 Connection refused - Invalid Source CID l2cap_register_signaling_response(handle, LE_CREDIT_BASED_CONNECTION_REQUEST, sig_id, source_cid, 0x0009); return 1; @@ -3224,7 +3224,7 @@ static int l2cap_le_signaling_handler_dispatch(hci_con_handle_t handle, uint8_t case LE_CREDIT_BASED_CONNECTION_RESPONSE: // check size - if (len < 10) return 0; + if (len < 10u) return 0u; // Find channel for this sig_id and connection handle channel = NULL; @@ -3263,7 +3263,7 @@ static int l2cap_le_signaling_handler_dispatch(hci_con_handle_t handle, uint8_t case LE_FLOW_CONTROL_CREDIT: // check size - if (len < 4) return 0; + if (len < 4u) return 0u; // find channel local_cid = little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET + 0); @@ -3287,7 +3287,7 @@ static int l2cap_le_signaling_handler_dispatch(hci_con_handle_t handle, uint8_t case DISCONNECTION_REQUEST: // check size - if (len < 4) return 0; + if (len < 4u) return 0u; // find channel local_cid = little_endian_read_16(command, L2CAP_SIGNALING_COMMAND_DATA_OFFSET + 0); @@ -3575,7 +3575,7 @@ static void l2cap_acl_le_handler(hci_con_handle_t handle, uint8_t *packet, uint1 case L2CAP_CID_SIGNALING_LE: { uint16_t sig_id = packet[COMPLETE_L2CAP_HEADER + 1]; uint16_t len = little_endian_read_16(packet, COMPLETE_L2CAP_HEADER + 2); - if ((COMPLETE_L2CAP_HEADER + 4 + len) > size) break; + if ((COMPLETE_L2CAP_HEADER + 4u + len) > size) break; int valid = l2cap_le_signaling_handler_dispatch(handle, &packet[COMPLETE_L2CAP_HEADER], sig_id); if (!valid){ l2cap_register_signaling_response(handle, COMMAND_REJECT_LE, sig_id, 0, L2CAP_REJ_CMD_UNKNOWN); @@ -3603,7 +3603,7 @@ static void l2cap_acl_le_handler(hci_con_handle_t handle, uint8_t *packet, uint1 l2cap_channel = l2cap_get_channel_for_local_cid(channel_id); if (l2cap_channel) { // credit counting - if (l2cap_channel->credits_incoming == 0){ + if (l2cap_channel->credits_incoming == 0u){ log_error("LE Data Channel packet received but no incoming credits"); l2cap_channel->state = L2CAP_STATE_WILL_SEND_DISCONNECT_REQUEST; break; @@ -3622,8 +3622,8 @@ static void l2cap_acl_le_handler(hci_con_handle_t handle, uint8_t *packet, uint1 if(sdu_len > l2cap_channel->local_mtu) break; // SDU would be larger than our buffer l2cap_channel->receive_sdu_len = sdu_len; l2cap_channel->receive_sdu_pos = 0; - pos += 2; - size -= 2; + pos += 2u; + size -= 2u; } uint16_t fragment_size = size-COMPLETE_L2CAP_HEADER; uint16_t remaining_space = l2cap_channel->local_mtu - l2cap_channel->receive_sdu_pos; @@ -3775,7 +3775,7 @@ static void l2cap_emit_le_incoming_connection(l2cap_channel_t *channel) { channel->address_type, bd_addr_to_str(channel->address), channel->con_handle, channel->psm, channel->local_cid, channel->remote_cid, channel->remote_mtu); uint8_t event[19]; event[0] = L2CAP_EVENT_LE_INCOMING_CONNECTION; - event[1] = sizeof(event) - 2; + event[1] = sizeof(event) - 2u; event[2] = channel->address_type; reverse_bd_addr(channel->address, &event[3]); little_endian_store_16(event, 9, channel->con_handle); @@ -3793,7 +3793,7 @@ static void l2cap_emit_le_channel_opened(l2cap_channel_t *channel, uint8_t statu channel->local_cid, channel->remote_cid, channel->local_mtu, channel->remote_mtu); uint8_t event[23]; event[0] = L2CAP_EVENT_LE_CHANNEL_OPENED; - event[1] = sizeof(event) - 2; + event[1] = sizeof(event) - 2u; event[2] = status; event[3] = channel->address_type; reverse_bd_addr(channel->address, &event[4]); @@ -3812,7 +3812,7 @@ static void l2cap_emit_le_channel_closed(l2cap_channel_t * channel){ log_info("L2CAP_EVENT_LE_CHANNEL_CLOSED local_cid 0x%x", channel->local_cid); uint8_t event[4]; event[0] = L2CAP_EVENT_LE_CHANNEL_CLOSED; - event[1] = sizeof(event) - 2; + event[1] = sizeof(event) - 2u; little_endian_store_16(event, 2, channel->local_cid); hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event)); l2cap_dispatch_to_channel(channel, HCI_EVENT_PACKET, event, sizeof(event)); @@ -3830,14 +3830,14 @@ static void l2cap_le_send_pdu(l2cap_channel_t *channel){ uint16_t pos = 0; if (!channel->send_sdu_pos){ // store SDU len - channel->send_sdu_pos += 2; + channel->send_sdu_pos += 2u; little_endian_store_16(l2cap_payload, pos, channel->send_sdu_len); - pos += 2; + pos += 2u; } - uint16_t payload_size = btstack_min(channel->send_sdu_len + 2 - channel->send_sdu_pos, channel->remote_mps - pos); + uint16_t payload_size = btstack_min(channel->send_sdu_len + 2u - channel->send_sdu_pos, channel->remote_mps - pos); log_info("len %u, pos %u => payload %u, credits %u", channel->send_sdu_len, channel->send_sdu_pos, payload_size, channel->credits_outgoing); (void)memcpy(&l2cap_payload[pos], - &channel->send_sdu_buffer[channel->send_sdu_pos - 2], + &channel->send_sdu_buffer[channel->send_sdu_pos - 2u], payload_size); // -2 for virtual SDU len pos += payload_size; channel->send_sdu_pos += payload_size; @@ -3845,9 +3845,9 @@ static void l2cap_le_send_pdu(l2cap_channel_t *channel){ channel->credits_outgoing--; - hci_send_acl_packet_buffer(8 + pos); + hci_send_acl_packet_buffer(8u + pos); - if (channel->send_sdu_pos >= (channel->send_sdu_len + 2)){ + if (channel->send_sdu_pos >= (channel->send_sdu_len + 2u)){ channel->send_sdu_buffer = NULL; // send done event l2cap_emit_simple_event_with_cid(channel, L2CAP_EVENT_LE_PACKET_SENT); @@ -4017,7 +4017,7 @@ uint8_t l2cap_le_provide_credits(uint16_t local_cid, uint16_t credits){ uint32_t total_credits = channel->credits_incoming; total_credits += channel->new_credits_incoming; total_credits += credits; - if (total_credits > 0xffff){ + if (total_credits > 0xffffu){ log_error("l2cap_le_provide_credits overrun: current %u, scheduled %u, additional %u", channel->credits_incoming, channel->new_credits_incoming, credits); } diff --git a/src/l2cap_signaling.c b/src/l2cap_signaling.c index e6b69193c..0bd89f270 100644 --- a/src/l2cap_signaling.c +++ b/src/l2cap_signaling.c @@ -81,8 +81,8 @@ static uint16_t l2cap_create_signaling_internal(uint8_t * acl_buffer, hci_con_ha static const unsigned int num_l2cap_commands = sizeof(l2cap_signaling_commands_format) / sizeof(const char *); const char *format = NULL; - if ((cmd > 0) && (cmd <= num_l2cap_commands)) { - format = l2cap_signaling_commands_format[cmd-1]; + if ((cmd > 0u) && (cmd <= num_l2cap_commands)) { + format = l2cap_signaling_commands_format[cmd-1u]; } if (!format){ log_error("l2cap_create_signaling_internal: invalid command id 0x%02x", cmd); @@ -97,7 +97,7 @@ static uint16_t l2cap_create_signaling_internal(uint8_t * acl_buffer, hci_con_ha #endif // 0 - Connection handle : PB=pb : BC=00 - little_endian_store_16(acl_buffer, 0, handle | (pb << 12) | (0 << 14)); + little_endian_store_16(acl_buffer, 0u, handle | (pb << 12u) | (0u << 14u)); // 6 - L2CAP channel = 1 little_endian_store_16(acl_buffer, 6, cid); // 8 - Code @@ -115,7 +115,7 @@ static uint16_t l2cap_create_signaling_internal(uint8_t * acl_buffer, hci_con_ha case '2': // 16 bit value word = va_arg(argptr, int); // minimal va_arg is int: 2 bytes on 8+16 bit CPUs - acl_buffer[pos++] = word & 0xff; + acl_buffer[pos++] = word & 0xffu; if (*format == '2') { acl_buffer[pos++] = word >> 8; } @@ -137,11 +137,11 @@ static uint16_t l2cap_create_signaling_internal(uint8_t * acl_buffer, hci_con_ha // - the l2cap payload length is counted after the following channel id (only payload) // 2 - ACL length - little_endian_store_16(acl_buffer, 2, pos - 4); + little_endian_store_16(acl_buffer, 2u, pos - 4u); // 4 - L2CAP packet length - little_endian_store_16(acl_buffer, 4, pos - 6 - 2); + little_endian_store_16(acl_buffer, 4u, pos - 6u - 2u); // 10 - L2CAP signaling parameter length - little_endian_store_16(acl_buffer, 10, pos - 12); + little_endian_store_16(acl_buffer, 10u, pos - 12u); return pos; } diff --git a/tool/misc/fix-misra-10a.sh b/tool/misc/fix-misra-10.4a.sh similarity index 56% rename from tool/misc/fix-misra-10a.sh rename to tool/misc/fix-misra-10.4a.sh index 53319bb7a..948d8b0a9 100755 --- a/tool/misc/fix-misra-10a.sh +++ b/tool/misc/fix-misra-10.4a.sh @@ -7,11 +7,12 @@ BTSTACK_ROOT=`realpath $BTSTACK_REL` command -v spatch >/dev/null 2>&1 || { echo >&2 "spatch from cocinelle required but not installed. Aborting."; exit 1; } # append u to all literals -spatch --sp-file $BTSTACK_ROOT/tool/misc/append_u_to_constants.cocci --out-place --max-width 200 --dir $BTSTACK_ROOT/src/ -spatch --sp-file $BTSTACK_ROOT/tool/misc/append_u_to_constants.cocci --out-place --max-width 200 --dir $BTSTACK_ROOT/3rd-party/ +spatch --sp-file $BTSTACK_ROOT/tool/misc/append_u_to_constants.cocci --out-place --max-width 300 --dir $BTSTACK_ROOT/src/ +spatch --sp-file $BTSTACK_ROOT/tool/misc/append_u_to_constants.cocci --out-place --max-width 300 --dir $BTSTACK_ROOT/3rd-party/micro-ecc +spatch --sp-file $BTSTACK_ROOT/tool/misc/append_u_to_constants.cocci --out-place --max-width 300 --dir $BTSTACK_ROOT/3rd-party/rijndael # update only lines that are listed in cstat report -$BTSTACK_ROOT/tool/misc/fix-misra-10a.py +$BTSTACK_ROOT/tool/misc/fix-misra-10.4a.py # delete cocci output files -find $BTSTACK_ROOT/ -name "*.cocci_res" -delete +# find $BTSTACK_ROOT/ -name "*.cocci_res" -delete