MISRAC2012-Rule-8.9: inline const objects that are used by single function

This commit is contained in:
Matthias Ringwald 2020-01-17 11:30:10 +01:00
parent b15ccad8bc
commit 8334d3d848
16 changed files with 219 additions and 195 deletions

View File

@ -368,7 +368,7 @@ typedef struct EccPoint {
} EccPoint; } EccPoint;
static const uECC_word_t curve_p[uECC_WORDS] = uECC_CONCAT(Curve_P_, uECC_CURVE); static const uECC_word_t curve_p[uECC_WORDS] = uECC_CONCAT(Curve_P_, uECC_CURVE);
static const uECC_word_t curve_b[uECC_WORDS] = uECC_CONCAT(Curve_B_, uECC_CURVE); // Global object `curve_b' is only referenced from function `curve_x_side', it should be defined within that functions block scope
static const EccPoint curve_G = uECC_CONCAT(Curve_G_, uECC_CURVE); static const EccPoint curve_G = uECC_CONCAT(Curve_G_, uECC_CURVE);
static const uECC_word_t curve_n[uECC_N_WORDS] = uECC_CONCAT(Curve_N_, uECC_CURVE); static const uECC_word_t curve_n[uECC_N_WORDS] = uECC_CONCAT(Curve_N_, uECC_CURVE);
@ -2083,6 +2083,7 @@ void uECC_compress(const uint8_t public_key[uECC_BYTES*2], uint8_t compressed[uE
/* Computes result = x^3 + ax + b. result must not overlap x. */ /* Computes result = x^3 + ax + b. result must not overlap x. */
static void curve_x_side(uECC_word_t * RESTRICT result, const uECC_word_t * RESTRICT x) { static void curve_x_side(uECC_word_t * RESTRICT result, const uECC_word_t * RESTRICT x) {
static const uECC_word_t curve_b[uECC_WORDS] = uECC_CONCAT(Curve_B_, uECC_CURVE);
#if (uECC_CURVE == uECC_secp256k1) #if (uECC_CURVE == uECC_secp256k1)
vli_modSquare_fast(result, x); /* r = x^2 */ vli_modSquare_fast(result, x); /* r = x^2 */
vli_modMult_fast(result, result, x); /* r = x^3 */ vli_modMult_fast(result, result, x); /* r = x^3 */

View File

@ -72,21 +72,6 @@ typedef enum {
TC_W4_DISCONNECT TC_W4_DISCONNECT
} tc_state_t; } tc_state_t;
static const char * ancs_attribute_names[] = {
"AppIdentifier",
"IDTitle",
"IDSubtitle",
"IDMessage",
"IDMessageSize",
"IDDate"
};
static const int ANCS_ATTRBUTE_NAMES_COUNT = sizeof(ancs_attribute_names) / sizeof(char *);
static const uint8_t ancs_service_uuid[] = {0x79,0x05,0xF4,0x31,0xB5,0xCE,0x4E,0x99,0xA4,0x0F,0x4B,0x1E,0x12,0x2D,0x00,0xD0};
static const uint8_t ancs_notification_source_uuid[] = {0x9F,0xBF,0x12,0x0D,0x63,0x01,0x42,0xD9,0x8C,0x58,0x25,0xE6,0x99,0xA2,0x1D,0xBD};
static const uint8_t ancs_control_point_uuid[] = {0x69,0xD1,0xD8,0xF3,0x45,0xE1,0x49,0xA8,0x98,0x21,0x9B,0xBD,0xFD,0xAA,0xD9,0xD9};
static const uint8_t ancs_data_source_uuid[] = {0x22,0xEA,0xC6,0xE9,0x24,0xD6,0x4B,0xB5,0xBE,0x44,0xB3,0x6A,0xCE,0x7C,0x7B,0xFB};
static uint32_t ancs_notification_uid; static uint32_t ancs_notification_uid;
static uint16_t gc_handle; static uint16_t gc_handle;
static gatt_client_notification_t ancs_notification_source_notification; static gatt_client_notification_t ancs_notification_source_notification;
@ -144,6 +129,17 @@ static void ancs_chunk_parser_init(void){
} }
const char * ancs_client_attribute_name_for_id(int id){ const char * ancs_client_attribute_name_for_id(int id){
static const char * ancs_attribute_names[] = {
"AppIdentifier",
"IDTitle",
"IDSubtitle",
"IDMessage",
"IDMessageSize",
"IDDate"
};
static const uint16_t ANCS_ATTRBUTE_NAMES_COUNT = sizeof(ancs_attribute_names) / sizeof(char *);
if (id >= ANCS_ATTRBUTE_NAMES_COUNT) return NULL; if (id >= ANCS_ATTRBUTE_NAMES_COUNT) return NULL;
return ancs_attribute_names[id]; return ancs_attribute_names[id];
} }
@ -185,6 +181,12 @@ static void handle_hci_event(uint8_t packet_type, uint16_t channel, uint8_t *pac
UNUSED(channel); // ok: there is no channel UNUSED(channel); // ok: there is no channel
UNUSED(size); // ok: fixed format events read from HCI buffer UNUSED(size); // ok: fixed format events read from HCI buffer
static const uint8_t ancs_service_uuid[] = {0x79,0x05,0xF4,0x31,0xB5,0xCE,0x4E,0x99,0xA4,0x0F,0x4B,0x1E,0x12,0x2D,0x00,0xD0};
static const uint8_t ancs_notification_source_uuid[] = {0x9F,0xBF,0x12,0x0D,0x63,0x01,0x42,0xD9,0x8C,0x58,0x25,0xE6,0x99,0xA2,0x1D,0xBD};
static const uint8_t ancs_control_point_uuid[] = {0x69,0xD1,0xD8,0xF3,0x45,0xE1,0x49,0xA8,0x98,0x21,0x9B,0xBD,0xFD,0xAA,0xD9,0xD9};
static const uint8_t ancs_data_source_uuid[] = {0x22,0xEA,0xC6,0xE9,0x24,0xD6,0x4B,0xB5,0xBE,0x44,0xB3,0x6A,0xCE,0x7C,0x7B,0xFB};
int connection_encrypted; int connection_encrypted;
// handle connect / disconncet events first // handle connect / disconncet events first

View File

@ -55,11 +55,11 @@ typedef enum {
ATT_WRITE, ATT_WRITE,
} att_operation_t; } att_operation_t;
// Buetooth Base UUID 00000000-0000-1000-8000-00805F9B34FB in little endian
static const uint8_t bluetooth_base_uuid[] = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
static int is_Bluetooth_Base_UUID(uint8_t const *uuid){ static int is_Bluetooth_Base_UUID(uint8_t const *uuid){
// Bluetooth Base UUID 00000000-0000-1000-8000-00805F9B34FB in little endian
static const uint8_t bluetooth_base_uuid[] = { 0xfb, 0x34, 0x9b, 0x5f, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
if (memcmp(&uuid[0], &bluetooth_base_uuid[0], 12) != 0) return false; if (memcmp(&uuid[0], &bluetooth_base_uuid[0], 12) != 0) return false;
if (memcmp(&uuid[14], &bluetooth_base_uuid[14], 2) != 0) return false; if (memcmp(&uuid[14], &bluetooth_base_uuid[14], 2) != 0) return false;
return true; return true;

View File

@ -75,18 +75,6 @@ typedef struct {
uint16_t value_handle; uint16_t value_handle;
} device_information_field_t; } device_information_field_t;
const uint16_t device_information_characteristic_uuids[] = {
ORG_BLUETOOTH_CHARACTERISTIC_MANUFACTURER_NAME_STRING,
ORG_BLUETOOTH_CHARACTERISTIC_MODEL_NUMBER_STRING,
ORG_BLUETOOTH_CHARACTERISTIC_SERIAL_NUMBER_STRING,
ORG_BLUETOOTH_CHARACTERISTIC_HARDWARE_REVISION_STRING,
ORG_BLUETOOTH_CHARACTERISTIC_FIRMWARE_REVISION_STRING,
ORG_BLUETOOTH_CHARACTERISTIC_SOFTWARE_REVISION_STRING,
ORG_BLUETOOTH_CHARACTERISTIC_SYSTEM_ID,
ORG_BLUETOOTH_CHARACTERISTIC_IEEE_11073_20601_REGULATORY_CERTIFICATION_DATA_LIST,
ORG_BLUETOOTH_CHARACTERISTIC_PNP_ID
};
static device_information_field_t device_information_fields[NUM_INFORMATION_FIELDS]; static device_information_field_t device_information_fields[NUM_INFORMATION_FIELDS];
static uint8_t device_information_system_id[8]; static uint8_t device_information_system_id[8];
@ -94,7 +82,6 @@ static uint8_t device_information_ieee_regulatory_certification[4];
static uint8_t device_information_pnp_id[7]; static uint8_t device_information_pnp_id[7];
static att_service_handler_t device_information_service; static att_service_handler_t device_information_service;
static void set_string(device_information_field_id_t field_id, const char * text){ static void set_string(device_information_field_id_t field_id, const char * text){
device_information_fields[field_id].data = (uint8_t*) text; device_information_fields[field_id].data = (uint8_t*) text;
device_information_fields[field_id].len = strlen(text); device_information_fields[field_id].len = strlen(text);
@ -113,6 +100,19 @@ static uint16_t device_information_service_read_callback(hci_con_handle_t con_ha
void device_information_service_server_init(void){ void device_information_service_server_init(void){
const uint16_t device_information_characteristic_uuids[] = {
ORG_BLUETOOTH_CHARACTERISTIC_MANUFACTURER_NAME_STRING,
ORG_BLUETOOTH_CHARACTERISTIC_MODEL_NUMBER_STRING,
ORG_BLUETOOTH_CHARACTERISTIC_SERIAL_NUMBER_STRING,
ORG_BLUETOOTH_CHARACTERISTIC_HARDWARE_REVISION_STRING,
ORG_BLUETOOTH_CHARACTERISTIC_FIRMWARE_REVISION_STRING,
ORG_BLUETOOTH_CHARACTERISTIC_SOFTWARE_REVISION_STRING,
ORG_BLUETOOTH_CHARACTERISTIC_SYSTEM_ID,
ORG_BLUETOOTH_CHARACTERISTIC_IEEE_11073_20601_REGULATORY_CERTIFICATION_DATA_LIST,
ORG_BLUETOOTH_CHARACTERISTIC_PNP_ID
};
// get service handle range // get service handle range
uint16_t start_handle; uint16_t start_handle;
uint16_t end_handle; uint16_t end_handle;

View File

@ -59,10 +59,6 @@
#include "ble/gatt-service/nordic_spp_service_server.h" #include "ble/gatt-service/nordic_spp_service_server.h"
// //
static const uint8_t nordic_spp_profile_uuid128[] = { 0x6E, 0x40, 0x00, 0x01, 0xB5, 0xA3, 0xF3, 0x93, 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E };
static const uint8_t nordic_spp_rx_uuid128[] = { 0x6E, 0x40, 0x00, 0x02, 0xB5, 0xA3, 0xF3, 0x93, 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E };
static const uint8_t nordic_spp_tx_uuid128[] = { 0x6E, 0x40, 0x00, 0x03, 0xB5, 0xA3, 0xF3, 0x93, 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E };
static att_service_handler_t nordic_spp_service; static att_service_handler_t nordic_spp_service;
static void (*client_callback)(hci_con_handle_t con_handle, const uint8_t * data, uint16_t size); static void (*client_callback)(hci_con_handle_t con_handle, const uint8_t * data, uint16_t size);
@ -108,6 +104,11 @@ static int nordic_spp_service_write_callback(hci_con_handle_t con_handle, uint16
* @param callback for tx data from peer * @param callback for tx data from peer
*/ */
void nordic_spp_service_server_init(void (*callback)(hci_con_handle_t con_handle, const uint8_t * data, uint16_t size)){ void nordic_spp_service_server_init(void (*callback)(hci_con_handle_t con_handle, const uint8_t * data, uint16_t size)){
static const uint8_t nordic_spp_profile_uuid128[] = { 0x6E, 0x40, 0x00, 0x01, 0xB5, 0xA3, 0xF3, 0x93, 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E };
static const uint8_t nordic_spp_rx_uuid128[] = { 0x6E, 0x40, 0x00, 0x02, 0xB5, 0xA3, 0xF3, 0x93, 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E };
static const uint8_t nordic_spp_tx_uuid128[] = { 0x6E, 0x40, 0x00, 0x03, 0xB5, 0xA3, 0xF3, 0x93, 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E };
client_callback = callback; client_callback = callback;
// get service handle range // get service handle range

View File

@ -58,9 +58,6 @@
#define UBLOX_SPP_CREDITS_THRESHOLD 8 #define UBLOX_SPP_CREDITS_THRESHOLD 8
// //
static const uint8_t ublox_spp_profile_uuid128[] = { 0x24, 0x56, 0xE1, 0xB9, 0x26, 0xE2, 0x8F, 0x83, 0xE7, 0x44, 0xF3, 0x4F, 0x01, 0xE9, 0xD7, 0x01 };
static const uint8_t ublox_spp_fifo_uuid128[] = { 0x24, 0x56, 0xE1, 0xB9, 0x26, 0xE2, 0x8F, 0x83, 0xE7, 0x44, 0xF3, 0x4F, 0x01, 0xE9, 0xD7, 0x03 };
static const uint8_t ublox_spp_credits_uuid128[] = { 0x24, 0x56, 0xE1, 0xB9, 0x26, 0xE2, 0x8F, 0x83, 0xE7, 0x44, 0xF3, 0x4F, 0x01, 0xE9, 0xD7, 0x04 };
typedef struct { typedef struct {
hci_con_handle_t con_handle; hci_con_handle_t con_handle;
@ -206,6 +203,11 @@ static void ublox_spp_credits_callback(void * context){
*/ */
void ublox_spp_service_server_init(void (*client_data_callback)(hci_con_handle_t con_handle, const uint8_t * data, uint16_t size), void ublox_spp_service_server_init(void (*client_data_callback)(hci_con_handle_t con_handle, const uint8_t * data, uint16_t size),
void (*client_credits_callback)(hci_con_handle_t con_handle, uint16_t credits)){ void (*client_credits_callback)(hci_con_handle_t con_handle, uint16_t credits)){
static const uint8_t ublox_spp_profile_uuid128[] = { 0x24, 0x56, 0xE1, 0xB9, 0x26, 0xE2, 0x8F, 0x83, 0xE7, 0x44, 0xF3, 0x4F, 0x01, 0xE9, 0xD7, 0x01 };
static const uint8_t ublox_spp_fifo_uuid128[] = { 0x24, 0x56, 0xE1, 0xB9, 0x26, 0xE2, 0x8F, 0x83, 0xE7, 0x44, 0xF3, 0x4F, 0x01, 0xE9, 0xD7, 0x03 };
static const uint8_t ublox_spp_credits_uuid128[] = { 0x24, 0x56, 0xE1, 0xB9, 0x26, 0xE2, 0x8F, 0x83, 0xE7, 0x44, 0xF3, 0x4F, 0x01, 0xE9, 0xD7, 0x04 };
ublox_spp_service_t * instance = &ublox_spp; ublox_spp_service_t * instance = &ublox_spp;
instance->client_data_callback = client_data_callback; instance->client_data_callback = client_data_callback;
instance->client_credits_callback = client_credits_callback; instance->client_credits_callback = client_credits_callback;

View File

@ -100,11 +100,12 @@ static uint32_t num_valid_entries;
static const btstack_tlv_t * le_device_db_tlv_btstack_tlv_impl; static const btstack_tlv_t * le_device_db_tlv_btstack_tlv_impl;
static void * le_device_db_tlv_btstack_tlv_context; static void * le_device_db_tlv_btstack_tlv_context;
static uint32_t le_device_db_tlv_tag_for_index(uint8_t index){
static const char tag_0 = 'B'; static const char tag_0 = 'B';
static const char tag_1 = 'T'; static const char tag_1 = 'T';
static const char tag_2 = 'D'; static const char tag_2 = 'D';
static uint32_t le_device_db_tlv_tag_for_index(uint8_t index){
return (tag_0 << 24) | (tag_1 << 16) | (tag_2 << 8) | index; return (tag_0 << 24) | (tag_1 << 16) | (tag_2 << 8) | index;
} }

View File

@ -376,27 +376,6 @@ static uint16_t sm_active_connection_handle = HCI_CON_HANDLE_INVALID;
static int (*sm_get_oob_data)(uint8_t addres_type, bd_addr_t addr, uint8_t * oob_data) = NULL; static int (*sm_get_oob_data)(uint8_t addres_type, bd_addr_t addr, uint8_t * oob_data) = NULL;
static int (*sm_get_sc_oob_data)(uint8_t addres_type, bd_addr_t addr, uint8_t * oob_sc_peer_confirm, uint8_t * oob_sc_peer_random); static int (*sm_get_sc_oob_data)(uint8_t addres_type, bd_addr_t addr, uint8_t * oob_sc_peer_confirm, uint8_t * oob_sc_peer_random);
// horizontal: initiator capabilities
// vertial: responder capabilities
static const stk_generation_method_t stk_generation_method [5] [5] = {
{ JUST_WORKS, JUST_WORKS, PK_INIT_INPUT, JUST_WORKS, PK_INIT_INPUT },
{ JUST_WORKS, JUST_WORKS, PK_INIT_INPUT, JUST_WORKS, PK_INIT_INPUT },
{ PK_RESP_INPUT, PK_RESP_INPUT, PK_BOTH_INPUT, JUST_WORKS, PK_RESP_INPUT },
{ JUST_WORKS, JUST_WORKS, JUST_WORKS, JUST_WORKS, JUST_WORKS },
{ PK_RESP_INPUT, PK_RESP_INPUT, PK_INIT_INPUT, JUST_WORKS, PK_RESP_INPUT },
};
// uses numeric comparison if one side has DisplayYesNo and KeyboardDisplay combinations
#ifdef ENABLE_LE_SECURE_CONNECTIONS
static const stk_generation_method_t stk_generation_method_with_secure_connection[5][5] = {
{ JUST_WORKS, JUST_WORKS, PK_INIT_INPUT, JUST_WORKS, PK_INIT_INPUT },
{ JUST_WORKS, NUMERIC_COMPARISON, PK_INIT_INPUT, JUST_WORKS, NUMERIC_COMPARISON },
{ PK_RESP_INPUT, PK_RESP_INPUT, PK_BOTH_INPUT, JUST_WORKS, PK_RESP_INPUT },
{ JUST_WORKS, JUST_WORKS, JUST_WORKS, JUST_WORKS, JUST_WORKS },
{ PK_RESP_INPUT, NUMERIC_COMPARISON, PK_INIT_INPUT, JUST_WORKS, NUMERIC_COMPARISON },
};
#endif
static void sm_run(void); static void sm_run(void);
static void sm_done_for_handle(hci_con_handle_t con_handle); static void sm_done_for_handle(hci_con_handle_t con_handle);
static sm_connection_t * sm_get_connection_for_handle(hci_con_handle_t con_handle); static sm_connection_t * sm_get_connection_for_handle(hci_con_handle_t con_handle);
@ -750,6 +729,27 @@ static void sm_notify_client_status_reason(sm_connection_t * sm_conn, uint8_t st
// - OOB data availability // - OOB data availability
static void sm_setup_tk(void){ static void sm_setup_tk(void){
// horizontal: initiator capabilities
// vertial: responder capabilities
static const stk_generation_method_t stk_generation_method [5] [5] = {
{ JUST_WORKS, JUST_WORKS, PK_INIT_INPUT, JUST_WORKS, PK_INIT_INPUT },
{ JUST_WORKS, JUST_WORKS, PK_INIT_INPUT, JUST_WORKS, PK_INIT_INPUT },
{ PK_RESP_INPUT, PK_RESP_INPUT, PK_BOTH_INPUT, JUST_WORKS, PK_RESP_INPUT },
{ JUST_WORKS, JUST_WORKS, JUST_WORKS, JUST_WORKS, JUST_WORKS },
{ PK_RESP_INPUT, PK_RESP_INPUT, PK_INIT_INPUT, JUST_WORKS, PK_RESP_INPUT },
};
// uses numeric comparison if one side has DisplayYesNo and KeyboardDisplay combinations
#ifdef ENABLE_LE_SECURE_CONNECTIONS
static const stk_generation_method_t stk_generation_method_with_secure_connection[5][5] = {
{ JUST_WORKS, JUST_WORKS, PK_INIT_INPUT, JUST_WORKS, PK_INIT_INPUT },
{ JUST_WORKS, NUMERIC_COMPARISON, PK_INIT_INPUT, JUST_WORKS, NUMERIC_COMPARISON },
{ PK_RESP_INPUT, PK_RESP_INPUT, PK_BOTH_INPUT, JUST_WORKS, PK_RESP_INPUT },
{ JUST_WORKS, JUST_WORKS, JUST_WORKS, JUST_WORKS, JUST_WORKS },
{ PK_RESP_INPUT, NUMERIC_COMPARISON, PK_INIT_INPUT, JUST_WORKS, NUMERIC_COMPARISON },
};
#endif
// default: just works // default: just works
setup->sm_stk_generation_method = JUST_WORKS; setup->sm_stk_generation_method = JUST_WORKS;
@ -1530,11 +1530,13 @@ static void f4_engine(sm_connection_t * sm_conn, const sm_key256_t u, const sm_k
sm_cmac_message_start(x, message_len, sm_cmac_sc_buffer, &sm_sc_cmac_done); sm_cmac_message_start(x, message_len, sm_cmac_sc_buffer, &sm_sc_cmac_done);
} }
static const sm_key_t f5_salt = { 0x6C ,0x88, 0x83, 0x91, 0xAA, 0xF5, 0xA5, 0x38, 0x60, 0x37, 0x0B, 0xDB, 0x5A, 0x60, 0x83, 0xBE};
static const uint8_t f5_key_id[] = { 0x62, 0x74, 0x6c, 0x65 }; static const uint8_t f5_key_id[] = { 0x62, 0x74, 0x6c, 0x65 };
static const uint8_t f5_length[] = { 0x01, 0x00}; static const uint8_t f5_length[] = { 0x01, 0x00};
static void f5_calculate_salt(sm_connection_t * sm_conn){ static void f5_calculate_salt(sm_connection_t * sm_conn){
static const sm_key_t f5_salt = { 0x6C ,0x88, 0x83, 0x91, 0xAA, 0xF5, 0xA5, 0x38, 0x60, 0x37, 0x0B, 0xDB, 0x5A, 0x60, 0x83, 0xBE};
log_info("f5_calculate_salt"); log_info("f5_calculate_salt");
// calculate salt for f5 // calculate salt for f5
const uint16_t message_len = 32; const uint16_t message_len = 32;
@ -3439,6 +3441,8 @@ static int sm_validate_stk_generation_method(void){
} }
} }
static void sm_pdu_handler(uint8_t packet_type, hci_con_handle_t con_handle, uint8_t *packet, uint16_t size){
// size of complete sm_pdu used to validate input // size of complete sm_pdu used to validate input
static const uint8_t sm_pdu_size[] = { static const uint8_t sm_pdu_size[] = {
0, // 0x00 invalid opcode 0, // 0x00 invalid opcode
@ -3458,8 +3462,6 @@ static const uint8_t sm_pdu_size[] = {
2, // 0x0e keypress notification 2, // 0x0e keypress notification
}; };
static void sm_pdu_handler(uint8_t packet_type, hci_con_handle_t con_handle, uint8_t *packet, uint16_t size){
if ((packet_type == HCI_EVENT_PACKET) && (packet[0] == L2CAP_EVENT_CAN_SEND_NOW)){ if ((packet_type == HCI_EVENT_PACKET) && (packet[0] == L2CAP_EVENT_CAN_SEND_NOW)){
sm_run(); sm_run();
} }
@ -4290,6 +4292,9 @@ static void sm_handle_random_result_oob(void * arg){
sm_run(); sm_run();
} }
uint8_t sm_generate_sc_oob_data(void (*callback)(const uint8_t * confirm_value, const uint8_t * random_value)){ uint8_t sm_generate_sc_oob_data(void (*callback)(const uint8_t * confirm_value, const uint8_t * random_value)){
static btstack_crypto_random_t sm_crypto_random_oob_request;
if (sm_sc_oob_state != SM_SC_OOB_IDLE) return ERROR_CODE_COMMAND_DISALLOWED; if (sm_sc_oob_state != SM_SC_OOB_IDLE) return ERROR_CODE_COMMAND_DISALLOWED;
sm_sc_oob_callback = callback; sm_sc_oob_callback = callback;
sm_sc_oob_state = SM_SC_OOB_W4_RANDOM; sm_sc_oob_state = SM_SC_OOB_W4_RANDOM;

View File

@ -45,6 +45,21 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
/**
* @brief Initialize base99 decoder
* @param context
*/
void btstack_base64_decoder_init(btstack_base64_decoder_t * context){
memset(context, 0, sizeof(btstack_base64_decoder_t));
}
/**
* @brief Decode single byte
* @param context
* @returns value, or BTSTACK_BASE64_DECODER_COMPLETE, BTSTACK_BASE64_DECODER_INVALID
*/
int btstack_base64_decoder_process_byte(btstack_base64_decoder_t * context, uint8_t c){
// map ascii char to 6-bit value // map ascii char to 6-bit value
static const uint8_t table[256] = { static const uint8_t table[256] = {
99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
@ -65,21 +80,6 @@ static const uint8_t table[256] = {
99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99
}; };
/**
* @brief Initialize base99 decoder
* @param context
*/
void btstack_base64_decoder_init(btstack_base64_decoder_t * context){
memset(context, 0, sizeof(btstack_base64_decoder_t));
}
/**
* @brief Decode single byte
* @param context
* @returns value, or BTSTACK_BASE64_DECODER_COMPLETE, BTSTACK_BASE64_DECODER_INVALID
*/
int btstack_base64_decoder_process_byte(btstack_base64_decoder_t * context, uint8_t c){
// handle '=' // handle '='
if (c == '='){ if (c == '='){
if ((context->pos == 2) || (context->pos == 3)){ if ((context->pos == 2) || (context->pos == 3)){

View File

@ -54,8 +54,6 @@
* btstack_hid_parser.c * btstack_hid_parser.c
*/ */
const int hid_item_sizes[] = { 0, 1, 2, 4 };
#ifdef HID_PARSER_PRETTY_PRINT #ifdef HID_PARSER_PRETTY_PRINT
static const char * type_names[] = { static const char * type_names[] = {
@ -150,6 +148,9 @@ static void hid_pretty_print_item(btstack_hid_parser_t * parser, hid_descriptor_
// parse descriptor item and read up to 32-bit bit value // parse descriptor item and read up to 32-bit bit value
void btstack_hid_parse_descriptor_item(hid_descriptor_item_t * item, const uint8_t * hid_descriptor, uint16_t hid_descriptor_len){ void btstack_hid_parse_descriptor_item(hid_descriptor_item_t * item, const uint8_t * hid_descriptor, uint16_t hid_descriptor_len){
const int hid_item_sizes[] = { 0, 1, 2, 4 };
// parse item header // parse item header
if (hid_descriptor_len < 1) return; if (hid_descriptor_len < 1) return;
uint16_t pos = 0; uint16_t pos = 0;

View File

@ -174,9 +174,11 @@ int32_t btstack_time_delta(uint32_t time_a, uint32_t time_b){
return (int32_t)(time_a - time_b); return (int32_t)(time_a - time_b);
} }
static const char * char_to_nibble = "0123456789ABCDEF";
char char_for_nibble(int nibble){ char char_for_nibble(int nibble){
static const char * char_to_nibble = "0123456789ABCDEF";
if (nibble < 16){ if (nibble < 16){
return char_to_nibble[nibble]; return char_to_nibble[nibble];
} else { } else {

View File

@ -110,10 +110,6 @@ pktlog_hdr;
static int dump_file = -1; static int dump_file = -1;
static int dump_format; static int dump_format;
static union {
uint8_t header_bluez[HCIDUMP_HDR_SIZE];
uint8_t header_packetlogger[PKTLOG_HDR_SIZE];
} header;
#ifdef HAVE_POSIX_FILE_IO #ifdef HAVE_POSIX_FILE_IO
static char time_string[40]; static char time_string[40];
static int max_nr_packets = -1; static int max_nr_packets = -1;
@ -268,6 +264,11 @@ static void printf_timestamp(void){
void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len) { void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len) {
static union {
uint8_t header_bluez[HCIDUMP_HDR_SIZE];
uint8_t header_packetlogger[PKTLOG_HDR_SIZE];
} header;
if (dump_file < 0) return; // not activated yet if (dump_file < 0) return; // not activated yet
#ifdef HAVE_POSIX_FILE_IO #ifdef HAVE_POSIX_FILE_IO

View File

@ -378,8 +378,6 @@ typedef enum {
// write state // write state
static TX_STATE tx_state; static TX_STATE tx_state;
static uint8_t packet_sent_event[] = { HCI_EVENT_TRANSPORT_PACKET_SENT, 0};
static void (*packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size) = dummy_handler; static void (*packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size) = dummy_handler;
// packet reader state machine // packet reader state machine
@ -471,12 +469,15 @@ static void hci_transport_em9304_spi_block_read(void){
} }
static void hci_transport_em9304_spi_block_sent(void){ static void hci_transport_em9304_spi_block_sent(void){
static const uint8_t packet_sent_event[] = { HCI_EVENT_TRANSPORT_PACKET_SENT, 0};
switch (tx_state){ switch (tx_state){
case TX_W4_PACKET_SENT: case TX_W4_PACKET_SENT:
// packet fully sent, reset state // packet fully sent, reset state
tx_state = TX_IDLE; tx_state = TX_IDLE;
// notify upper stack that it can send again // notify upper stack that it can send again
packet_handler(HCI_EVENT_PACKET, &packet_sent_event[0], sizeof(packet_sent_event)); packet_handler(HCI_EVENT_PACKET, (uint8_t *) &packet_sent_event[0], sizeof(packet_sent_event));
break; break;
default: default:
break; break;
@ -535,6 +536,9 @@ static void dummy_handler(uint8_t packet_type, uint8_t *packet, uint16_t size){
// --- end of eHCILL implementation --------- // --- end of eHCILL implementation ---------
// configure and return h4 singleton
const hci_transport_t * hci_transport_em9304_spi_instance(const btstack_em9304_spi_t * em9304_spi_driver) {
static const hci_transport_t hci_transport_em9304_spi = { static const hci_transport_t hci_transport_em9304_spi = {
/* const char * name; */ "H4", /* const char * name; */ "H4",
/* void (*init) (const void *transport_config); */ &hci_transport_em9304_spi_init, /* void (*init) (const void *transport_config); */ &hci_transport_em9304_spi_init,
@ -548,8 +552,6 @@ static const hci_transport_t hci_transport_em9304_spi = {
/* void (*set_sco_config)(uint16_t voice_setting, int num_connections); */ NULL, /* void (*set_sco_config)(uint16_t voice_setting, int num_connections); */ NULL,
}; };
// configure and return h4 singleton
const hci_transport_t * hci_transport_em9304_spi_instance(const btstack_em9304_spi_t * em9304_spi_driver) {
btstack_em9304_spi = em9304_spi_driver; btstack_em9304_spi = em9304_spi_driver;
return &hci_transport_em9304_spi; return &hci_transport_em9304_spi;
} }

View File

@ -136,8 +136,6 @@ static uint8_t * ehcill_tx_data;
static uint16_t ehcill_tx_len; // 0 == no outgoing packet static uint16_t ehcill_tx_len; // 0 == no outgoing packet
#endif #endif
static uint8_t packet_sent_event[] = { HCI_EVENT_TRANSPORT_PACKET_SENT, 0};
static void (*packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size) = dummy_handler; static void (*packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size) = dummy_handler;
// packet reader state machine // packet reader state machine
@ -314,6 +312,9 @@ static void hci_transport_h4_block_read(void){
} }
static void hci_transport_h4_block_sent(void){ static void hci_transport_h4_block_sent(void){
static const uint8_t packet_sent_event[] = { HCI_EVENT_TRANSPORT_PACKET_SENT, 0};
switch (tx_state){ switch (tx_state){
case TX_W4_PACKET_SENT: case TX_W4_PACKET_SENT:
// packet fully sent, reset state // packet fully sent, reset state
@ -715,6 +716,10 @@ static void hci_transport_h4_ehcill_handle_ehcill_command_sent(void){
#endif #endif
// --- end of eHCILL implementation --------- // --- end of eHCILL implementation ---------
// configure and return h4 singleton
const hci_transport_t * hci_transport_h4_instance(const btstack_uart_block_t * uart_driver) {
static const hci_transport_t hci_transport_h4 = { static const hci_transport_t hci_transport_h4 = {
/* const char * name; */ "H4", /* const char * name; */ "H4",
/* void (*init) (const void *transport_config); */ &hci_transport_h4_init, /* void (*init) (const void *transport_config); */ &hci_transport_h4_init,
@ -728,8 +733,6 @@ static const hci_transport_t hci_transport_h4 = {
/* void (*set_sco_config)(uint16_t voice_setting, int num_connections); */ NULL, /* void (*set_sco_config)(uint16_t voice_setting, int num_connections); */ NULL,
}; };
// configure and return h4 singleton
const hci_transport_t * hci_transport_h4_instance(const btstack_uart_block_t * uart_driver) {
btstack_uart = uart_driver; btstack_uart = uart_driver;
return &hci_transport_h4; return &hci_transport_h4;
} }

View File

@ -98,10 +98,7 @@ typedef enum {
static const uint8_t link_control_sync[] = { 0x01, 0x7e}; static const uint8_t link_control_sync[] = { 0x01, 0x7e};
static const uint8_t link_control_sync_response[] = { 0x02, 0x7d}; static const uint8_t link_control_sync_response[] = { 0x02, 0x7d};
static const uint8_t link_control_config[] = { 0x03, 0xfc, LINK_CONFIG_FIELD}; static const uint8_t link_control_config[] = { 0x03, 0xfc, LINK_CONFIG_FIELD};
static const uint8_t link_control_config_prefix_len = 2;
static const uint8_t link_control_config_response_empty[] = { 0x04, 0x7b};
static const uint8_t link_control_config_response[] = { 0x04, 0x7b, LINK_CONFIG_FIELD}; static const uint8_t link_control_config_response[] = { 0x04, 0x7b, LINK_CONFIG_FIELD};
static const uint8_t link_control_config_response_prefix_len = 2;
static const uint8_t link_control_wakeup[] = { 0x05, 0xfa}; static const uint8_t link_control_wakeup[] = { 0x05, 0xfa};
static const uint8_t link_control_woken[] = { 0x06, 0xf9}; static const uint8_t link_control_woken[] = { 0x06, 0xf9};
static const uint8_t link_control_sleep[] = { 0x07, 0x78}; static const uint8_t link_control_sleep[] = { 0x07, 0x78};
@ -159,6 +156,9 @@ static void hci_transport_slip_init(void);
// ----------------------------- // -----------------------------
// CRC16-CCITT Calculation - compromise: use 32 byte table - 512 byte table would be faster, but that's too large // CRC16-CCITT Calculation - compromise: use 32 byte table - 512 byte table would be faster, but that's too large
static uint16_t crc16_ccitt_update (uint16_t crc, uint8_t ch){
static const uint16_t crc16_ccitt_table[] ={ static const uint16_t crc16_ccitt_table[] ={
0x0000, 0x1081, 0x2102, 0x3183, 0x0000, 0x1081, 0x2102, 0x3183,
0x4204, 0x5285, 0x6306, 0x7387, 0x4204, 0x5285, 0x6306, 0x7387,
@ -166,7 +166,6 @@ static const uint16_t crc16_ccitt_table[] ={
0xc60c, 0xd68d, 0xe70e, 0xf78f 0xc60c, 0xd68d, 0xe70e, 0xf78f
}; };
static uint16_t crc16_ccitt_update (uint16_t crc, uint8_t ch){
crc = (crc >> 4) ^ crc16_ccitt_table[(crc ^ ch) & 0x000f]; crc = (crc >> 4) ^ crc16_ccitt_table[(crc ^ ch) & 0x000f];
crc = (crc >> 4) ^ crc16_ccitt_table[(crc ^ (ch >> 4)) & 0x000f]; crc = (crc >> 4) ^ crc16_ccitt_table[(crc ^ (ch >> 4)) & 0x000f];
return crc; return crc;
@ -330,6 +329,7 @@ static void hci_transport_link_send_config_response(void){
static void hci_transport_link_send_config_response_empty(void){ static void hci_transport_link_send_config_response_empty(void){
log_debug("link send config response empty"); log_debug("link send config response empty");
static const uint8_t link_control_config_response_empty[] = { 0x04, 0x7b};
hci_transport_link_send_control(link_control_config_response_empty, sizeof(link_control_config_response_empty)); hci_transport_link_send_control(link_control_config_response_empty, sizeof(link_control_config_response_empty));
} }
@ -518,6 +518,9 @@ static void hci_transport_h5_emit_sleep_state(int sleep_active){
static void hci_transport_h5_process_frame(uint16_t frame_size){ 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 < 4) return;
uint8_t * slip_header = &hci_packet_with_pre_buffer[HCI_INCOMING_PRE_BUFFER_SIZE]; uint8_t * slip_header = &hci_packet_with_pre_buffer[HCI_INCOMING_PRE_BUFFER_SIZE];
@ -920,6 +923,9 @@ static void hci_transport_h5_reset_link(void){
hci_transport_link_init(); hci_transport_link_init();
} }
// configure and return h5 singleton
const hci_transport_t * hci_transport_h5_instance(const btstack_uart_block_t * uart_driver) {
static const hci_transport_t hci_transport_h5 = { static const hci_transport_t hci_transport_h5 = {
/* const char * name; */ "H5", /* const char * name; */ "H5",
/* void (*init) (const void *transport_config); */ &hci_transport_h5_init, /* void (*init) (const void *transport_config); */ &hci_transport_h5_init,
@ -933,8 +939,6 @@ static const hci_transport_t hci_transport_h5 = {
/* void (*set_sco_config)(uint16_t voice_setting, int num_connections); */ NULL, /* void (*set_sco_config)(uint16_t voice_setting, int num_connections); */ NULL,
}; };
// configure and return h5 singleton
const hci_transport_t * hci_transport_h5_instance(const btstack_uart_block_t * uart_driver) {
btstack_uart = uart_driver; btstack_uart = uart_driver;
return &hci_transport_h5; return &hci_transport_h5;
} }

View File

@ -50,6 +50,8 @@
#include <string.h> #include <string.h>
static uint16_t l2cap_create_signaling_internal(uint8_t * acl_buffer, hci_con_handle_t handle, uint16_t cid, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr){
static const char *l2cap_signaling_commands_format[] = { static const char *l2cap_signaling_commands_format[] = {
"2D", // 0x01 command reject: reason {cmd not understood (0), sig MTU exceeded (2:max sig MTU), invalid CID (4:req CID)}, data len, data "2D", // 0x01 command reject: reason {cmd not understood (0), sig MTU exceeded (2:max sig MTU), invalid CID (4:req CID)}, data len, data
"22", // 0x02 connection request: PSM, Source CID "22", // 0x02 connection request: PSM, Source CID
@ -76,11 +78,8 @@ NULL, // 0x11 non-supported AMP command
"22", // 0x16 le flow control credit: source cid, credits "22", // 0x16 le flow control credit: source cid, credits
#endif #endif
}; };
static const unsigned int num_l2cap_commands = sizeof(l2cap_signaling_commands_format) / sizeof(const char *); static const unsigned int num_l2cap_commands = sizeof(l2cap_signaling_commands_format) / sizeof(const char *);
static uint16_t l2cap_create_signaling_internal(uint8_t * acl_buffer, hci_con_handle_t handle, uint16_t cid, L2CAP_SIGNALING_COMMANDS cmd, uint8_t identifier, va_list argptr){
const char *format = NULL; const char *format = NULL;
if ((cmd > 0) && (cmd <= num_l2cap_commands)) { if ((cmd > 0) && (cmd <= num_l2cap_commands)) {
format = l2cap_signaling_commands_format[cmd-1]; format = l2cap_signaling_commands_format[cmd-1];