ble/device_information_service: add att_status to events

This commit is contained in:
Milanka Ringwald 2021-03-05 14:44:06 +01:00
parent 878c87a845
commit 48691b0d3d
3 changed files with 167 additions and 73 deletions

View File

@ -83,16 +83,16 @@ typedef struct {
static device_information_service_client_t device_information_service_client;
static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
static void device_information_service_emit_string_value(device_information_service_client_t * client, uint8_t subevent, const uint8_t * value, uint16_t value_len);
static void device_information_service_emit_system_id(device_information_service_client_t * client, uint8_t subevent, const uint8_t * value, uint16_t value_len);
static void device_information_service_emit_certification_data_list(device_information_service_client_t * client, uint8_t subevent, const uint8_t * value, uint16_t value_len);
static void device_information_service_emit_pnp_id(device_information_service_client_t * client, uint8_t subevent, const uint8_t * value, uint16_t value_len);
static void device_information_service_emit_string_value(device_information_service_client_t * client, uint8_t subevent, uint8_t att_status, const uint8_t * value, uint16_t value_len);
static void device_information_service_emit_system_id(device_information_service_client_t * client, uint8_t subevent, uint8_t att_status, const uint8_t * value, uint16_t value_len);
static void device_information_service_emit_certification_data_list(device_information_service_client_t * client, uint8_t subevent, uint8_t att_status, const uint8_t * value, uint16_t value_len);
static void device_information_service_emit_pnp_id(device_information_service_client_t * client, uint8_t subevent, uint8_t att_status, const uint8_t * value, uint16_t value_len);
// list of uuids and how they are reported as events
static struct device_information_characteristic {
uint16_t uuid;
uint8_t subevent;
void (*handle_value)(device_information_service_client_t * client, uint8_t subevent, const uint8_t * value, uint16_t value_len);
void (*handle_value)(device_information_service_client_t * client, uint8_t subevent, uint8_t att_status, const uint8_t * value, uint16_t value_len);
} device_information_characteristics[] = {
{ORG_BLUETOOTH_CHARACTERISTIC_MANUFACTURER_NAME_STRING, GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_MANUFACTURER_NAME, device_information_service_emit_string_value},
{ORG_BLUETOOTH_CHARACTERISTIC_MODEL_NUMBER_STRING, GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_MODEL_NUMBER, device_information_service_emit_string_value},
@ -136,8 +136,8 @@ static void device_information_service_emit_query_done(device_information_servic
(*client->client_handler)(HCI_EVENT_PACKET, 0, event, pos);
}
static void device_information_service_emit_string_value(device_information_service_client_t * client, uint8_t subevent, const uint8_t * value, uint16_t value_len){
uint8_t event[5 + DEVICE_INFORMATION_MAX_STRING_LEN + 1];
static void device_information_service_emit_string_value(device_information_service_client_t * client, uint8_t subevent, uint8_t att_status, const uint8_t * value, uint16_t value_len){
uint8_t event[6 + DEVICE_INFORMATION_MAX_STRING_LEN + 1];
int pos = 0;
event[pos++] = HCI_EVENT_GATTSERVICE_META;
@ -145,6 +145,7 @@ static void device_information_service_emit_string_value(device_information_serv
event[pos++] = subevent;
little_endian_store_16(event, pos, client->con_handle);
pos += 2;
event[pos++] = att_status;
uint16_t bytes_to_copy = btstack_min(value_len, DEVICE_INFORMATION_MAX_STRING_LEN);
memcpy((char*)&event[pos], value, bytes_to_copy);
@ -155,8 +156,42 @@ static void device_information_service_emit_string_value(device_information_serv
(*client->client_handler)(HCI_EVENT_PACKET, 0, event, pos);
}
static void device_information_service_emit_system_id(device_information_service_client_t * client, uint8_t subevent, const uint8_t * value, uint16_t value_len){
if (value_len != 13) return;
static void device_information_service_emit_system_id(device_information_service_client_t * client, uint8_t subevent, uint8_t att_status, const uint8_t * value, uint16_t value_len){
if (value_len != 8) return;
uint8_t event[14];
uint16_t pos = 0;
event[pos++] = HCI_EVENT_GATTSERVICE_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = subevent;
little_endian_store_16(event, pos, client->con_handle);
pos += 2;
event[pos++] = att_status;
memcpy(event+pos, value, 8);
pos += 8;
(*client->client_handler)(HCI_EVENT_PACKET, 0, event, pos);
}
static void device_information_service_emit_certification_data_list(device_information_service_client_t * client, uint8_t subevent, uint8_t att_status, const uint8_t * value, uint16_t value_len){
if (value_len != 4) return;
uint8_t event[10];
int pos = 0;
event[pos++] = HCI_EVENT_GATTSERVICE_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = subevent;
little_endian_store_16(event, pos, client->con_handle);
pos += 2;
event[pos++] = att_status;
memcpy(event + pos, value, 4);
pos += 4;
(*client->client_handler)(HCI_EVENT_PACKET, 0, event, pos);
}
static void device_information_service_emit_pnp_id(device_information_service_client_t * client, uint8_t subevent, uint8_t att_status, const uint8_t * value, uint16_t value_len){
if (value_len != 7) return;
uint8_t event[13];
uint16_t pos = 0;
@ -165,43 +200,9 @@ static void device_information_service_emit_system_id(device_information_service
event[pos++] = subevent;
little_endian_store_16(event, pos, client->con_handle);
pos += 2;
memcpy(event+pos, value, 8);
pos += 8;
(*client->client_handler)(HCI_EVENT_PACKET, 0, event, pos);
}
static void device_information_service_emit_certification_data_list(device_information_service_client_t * client, uint8_t subevent, const uint8_t * value, uint16_t value_len){
if (value_len != 9) return;
uint8_t event[9];
int pos = 0;
event[pos++] = HCI_EVENT_GATTSERVICE_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = subevent;
little_endian_store_16(event, pos, client->con_handle);
pos += 2;
memcpy(event + pos, value, 4);
pos += 4;
(*client->client_handler)(HCI_EVENT_PACKET, 0, event, pos);
}
static void device_information_service_emit_pnp_id(device_information_service_client_t * client, uint8_t subevent, const uint8_t * value, uint16_t value_len){
if (value_len != 12) return;
uint8_t event[12];
uint16_t pos = 0;
event[pos++] = HCI_EVENT_GATTSERVICE_META;
event[pos++] = sizeof(event) - 2;
event[pos++] = subevent;
little_endian_store_16(event, pos, client->con_handle);
pos += 2;
memcpy(event + pos, value, 9);
pos += 9;
event[pos++] = att_status;
memcpy(event + pos, value, 7);
pos += 7;
(*client->client_handler)(HCI_EVENT_PACKET, 0, event, pos);
}
@ -266,6 +267,7 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
(device_information_characteristics[client->characteristic_index].handle_value(
client, device_information_characteristics[client->characteristic_index].subevent,
ATT_ERROR_SUCCESS,
gatt_event_characteristic_value_query_result_get_value(packet),
gatt_event_characteristic_value_query_result_get_value_length(packet)));
break;
@ -295,9 +297,11 @@ static void handle_gatt_client_event(uint8_t packet_type, uint16_t channel, uint
case DEVICE_INFORMATION_CLIENT_STATE_W4_CHARACTERISTIC_RESULT:
if (att_status != ATT_ERROR_SUCCESS){
device_information_service_emit_query_done(client, att_status);
device_information_service_finalize_client(client);
break;
(device_information_characteristics[client->characteristic_index].handle_value(
client, device_information_characteristics[client->characteristic_index].subevent,
att_status,
gatt_event_characteristic_value_query_result_get_value(packet),
gatt_event_characteristic_value_query_result_get_value_length(packet)));
}
// check if there is another characteristic to query

View File

@ -3097,57 +3097,64 @@ typedef uint8_t sm_key_t[16];
#define GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_DONE 0x06
/**
* @format 1HT
* @format 1H1T
* @param subevent_code
* @param con_handle
* @param att_status
* @param value
*/
#define GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_MANUFACTURER_NAME 0x07
/**
* @format 1HT
* @format 1H1T
* @param subevent_code
* @param con_handle
* @param att_status
* @param value
*/
#define GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_MODEL_NUMBER 0x08
/**
* @format 1HT
* @format 1H1T
* @param subevent_code
* @param con_handle
* @param att_status
* @param value
*/
#define GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_SERIAL_NUMBER 0x09
/**
* @format 1HT
* @format 1H1T
* @param subevent_code
* @param con_handle
* @param att_status
* @param value
*/
#define GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_HARDWARE_REVISION 0x0A
/**
* @format 1HT
* @format 1H1T
* @param subevent_code
* @param con_handle
* @param att_status
* @param value
*/
#define GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_FIRMWARE_REVISION 0x0B
/**
* @format 1HT
* @format 1H1T
* @param subevent_code
* @param con_handle
* @param att_status
* @param value
*/
#define GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_SOFTWARE_REVISION 0x0C
/**
* @format 1H413
* @format 1H1413
* @param subevent_code
* @param con_handle
* @param att_status
* @param manufacturer_identifier_low
* @param manufacturer_identifier_high
* @param organizationally_unique_identifier
@ -3155,18 +3162,20 @@ typedef uint8_t sm_key_t[16];
#define GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_SYSTEM_ID 0x0D
/**
* @format 1H22
* @format 1H122
* @param subevent_code
* @param con_handle
* @param att_status
* @param device_information_ieee_regulatory_certification_value_a
* @param device_information_ieee_regulatory_certification_value_b
*/
#define GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_IEEE_11073_20601_REGULATORY_CERTIFICATION_DATA_LIST 0x0E
/**
* @format 1H1222
* @format 1H11222
* @param subevent_code
* @param con_handle
* @param att_status
* @param vendor_source_id
* @param vendor_id
* @param product_id

View File

@ -9168,6 +9168,15 @@ static inline uint8_t gattservice_subevent_device_information_done_get_att_statu
static inline hci_con_handle_t gattservice_subevent_device_information_manufacturer_name_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field att_status from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_MANUFACTURER_NAME
* @param event packet
* @return att_status
* @note: btstack_type 1
*/
static inline uint8_t gattservice_subevent_device_information_manufacturer_name_get_att_status(const uint8_t * event){
return event[5];
}
/**
* @brief Get field value from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_MANUFACTURER_NAME
* @param event packet
@ -9175,7 +9184,7 @@ static inline hci_con_handle_t gattservice_subevent_device_information_manufactu
* @note: btstack_type T
*/
static inline const char * gattservice_subevent_device_information_manufacturer_name_get_value(const uint8_t * event){
return (const char *) &event[5];
return (const char *) &event[6];
}
/**
@ -9187,6 +9196,15 @@ static inline const char * gattservice_subevent_device_information_manufacturer_
static inline hci_con_handle_t gattservice_subevent_device_information_model_number_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field att_status from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_MODEL_NUMBER
* @param event packet
* @return att_status
* @note: btstack_type 1
*/
static inline uint8_t gattservice_subevent_device_information_model_number_get_att_status(const uint8_t * event){
return event[5];
}
/**
* @brief Get field value from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_MODEL_NUMBER
* @param event packet
@ -9194,7 +9212,7 @@ static inline hci_con_handle_t gattservice_subevent_device_information_model_num
* @note: btstack_type T
*/
static inline const char * gattservice_subevent_device_information_model_number_get_value(const uint8_t * event){
return (const char *) &event[5];
return (const char *) &event[6];
}
/**
@ -9206,6 +9224,15 @@ static inline const char * gattservice_subevent_device_information_model_number_
static inline hci_con_handle_t gattservice_subevent_device_information_serial_number_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field att_status from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_SERIAL_NUMBER
* @param event packet
* @return att_status
* @note: btstack_type 1
*/
static inline uint8_t gattservice_subevent_device_information_serial_number_get_att_status(const uint8_t * event){
return event[5];
}
/**
* @brief Get field value from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_SERIAL_NUMBER
* @param event packet
@ -9213,7 +9240,7 @@ static inline hci_con_handle_t gattservice_subevent_device_information_serial_nu
* @note: btstack_type T
*/
static inline const char * gattservice_subevent_device_information_serial_number_get_value(const uint8_t * event){
return (const char *) &event[5];
return (const char *) &event[6];
}
/**
@ -9225,6 +9252,15 @@ static inline const char * gattservice_subevent_device_information_serial_number
static inline hci_con_handle_t gattservice_subevent_device_information_hardware_revision_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field att_status from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_HARDWARE_REVISION
* @param event packet
* @return att_status
* @note: btstack_type 1
*/
static inline uint8_t gattservice_subevent_device_information_hardware_revision_get_att_status(const uint8_t * event){
return event[5];
}
/**
* @brief Get field value from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_HARDWARE_REVISION
* @param event packet
@ -9232,7 +9268,7 @@ static inline hci_con_handle_t gattservice_subevent_device_information_hardware_
* @note: btstack_type T
*/
static inline const char * gattservice_subevent_device_information_hardware_revision_get_value(const uint8_t * event){
return (const char *) &event[5];
return (const char *) &event[6];
}
/**
@ -9244,6 +9280,15 @@ static inline const char * gattservice_subevent_device_information_hardware_revi
static inline hci_con_handle_t gattservice_subevent_device_information_firmware_revision_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field att_status from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_FIRMWARE_REVISION
* @param event packet
* @return att_status
* @note: btstack_type 1
*/
static inline uint8_t gattservice_subevent_device_information_firmware_revision_get_att_status(const uint8_t * event){
return event[5];
}
/**
* @brief Get field value from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_FIRMWARE_REVISION
* @param event packet
@ -9251,7 +9296,7 @@ static inline hci_con_handle_t gattservice_subevent_device_information_firmware_
* @note: btstack_type T
*/
static inline const char * gattservice_subevent_device_information_firmware_revision_get_value(const uint8_t * event){
return (const char *) &event[5];
return (const char *) &event[6];
}
/**
@ -9263,6 +9308,15 @@ static inline const char * gattservice_subevent_device_information_firmware_revi
static inline hci_con_handle_t gattservice_subevent_device_information_software_revision_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field att_status from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_SOFTWARE_REVISION
* @param event packet
* @return att_status
* @note: btstack_type 1
*/
static inline uint8_t gattservice_subevent_device_information_software_revision_get_att_status(const uint8_t * event){
return event[5];
}
/**
* @brief Get field value from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_SOFTWARE_REVISION
* @param event packet
@ -9270,7 +9324,7 @@ static inline hci_con_handle_t gattservice_subevent_device_information_software_
* @note: btstack_type T
*/
static inline const char * gattservice_subevent_device_information_software_revision_get_value(const uint8_t * event){
return (const char *) &event[5];
return (const char *) &event[6];
}
/**
@ -9282,6 +9336,15 @@ static inline const char * gattservice_subevent_device_information_software_revi
static inline hci_con_handle_t gattservice_subevent_device_information_system_id_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field att_status from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_SYSTEM_ID
* @param event packet
* @return att_status
* @note: btstack_type 1
*/
static inline uint8_t gattservice_subevent_device_information_system_id_get_att_status(const uint8_t * event){
return event[5];
}
/**
* @brief Get field manufacturer_identifier_low from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_SYSTEM_ID
* @param event packet
@ -9289,7 +9352,7 @@ static inline hci_con_handle_t gattservice_subevent_device_information_system_id
* @note: btstack_type 4
*/
static inline uint32_t gattservice_subevent_device_information_system_id_get_manufacturer_identifier_low(const uint8_t * event){
return little_endian_read_32(event, 5);
return little_endian_read_32(event, 6);
}
/**
* @brief Get field manufacturer_identifier_high from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_SYSTEM_ID
@ -9298,7 +9361,7 @@ static inline uint32_t gattservice_subevent_device_information_system_id_get_man
* @note: btstack_type 1
*/
static inline uint8_t gattservice_subevent_device_information_system_id_get_manufacturer_identifier_high(const uint8_t * event){
return event[9];
return event[10];
}
/**
* @brief Get field organizationally_unique_identifier from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_SYSTEM_ID
@ -9307,7 +9370,7 @@ static inline uint8_t gattservice_subevent_device_information_system_id_get_manu
* @note: btstack_type 3
*/
static inline uint32_t gattservice_subevent_device_information_system_id_get_organizationally_unique_identifier(const uint8_t * event){
return little_endian_read_24(event, 10);
return little_endian_read_24(event, 11);
}
/**
@ -9319,6 +9382,15 @@ static inline uint32_t gattservice_subevent_device_information_system_id_get_org
static inline hci_con_handle_t gattservice_subevent_device_information_ieee_11073_20601_regulatory_certification_data_list_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field att_status from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_IEEE_11073_20601_REGULATORY_CERTIFICATION_DATA_LIST
* @param event packet
* @return att_status
* @note: btstack_type 1
*/
static inline uint8_t gattservice_subevent_device_information_ieee_11073_20601_regulatory_certification_data_list_get_att_status(const uint8_t * event){
return event[5];
}
/**
* @brief Get field device_information_ieee_regulatory_certification_value_a from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_IEEE_11073_20601_REGULATORY_CERTIFICATION_DATA_LIST
* @param event packet
@ -9326,7 +9398,7 @@ static inline hci_con_handle_t gattservice_subevent_device_information_ieee_1107
* @note: btstack_type 2
*/
static inline uint16_t gattservice_subevent_device_information_ieee_11073_20601_regulatory_certification_data_list_get_device_information_ieee_regulatory_certification_value_a(const uint8_t * event){
return little_endian_read_16(event, 5);
return little_endian_read_16(event, 6);
}
/**
* @brief Get field device_information_ieee_regulatory_certification_value_b from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_IEEE_11073_20601_REGULATORY_CERTIFICATION_DATA_LIST
@ -9335,7 +9407,7 @@ static inline uint16_t gattservice_subevent_device_information_ieee_11073_20601_
* @note: btstack_type 2
*/
static inline uint16_t gattservice_subevent_device_information_ieee_11073_20601_regulatory_certification_data_list_get_device_information_ieee_regulatory_certification_value_b(const uint8_t * event){
return little_endian_read_16(event, 7);
return little_endian_read_16(event, 8);
}
/**
@ -9347,6 +9419,15 @@ static inline uint16_t gattservice_subevent_device_information_ieee_11073_20601_
static inline hci_con_handle_t gattservice_subevent_device_information_pnp_id_get_con_handle(const uint8_t * event){
return little_endian_read_16(event, 3);
}
/**
* @brief Get field att_status from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_PNP_ID
* @param event packet
* @return att_status
* @note: btstack_type 1
*/
static inline uint8_t gattservice_subevent_device_information_pnp_id_get_att_status(const uint8_t * event){
return event[5];
}
/**
* @brief Get field vendor_source_id from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_PNP_ID
* @param event packet
@ -9354,7 +9435,7 @@ static inline hci_con_handle_t gattservice_subevent_device_information_pnp_id_ge
* @note: btstack_type 1
*/
static inline uint8_t gattservice_subevent_device_information_pnp_id_get_vendor_source_id(const uint8_t * event){
return event[5];
return event[6];
}
/**
* @brief Get field vendor_id from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_PNP_ID
@ -9363,7 +9444,7 @@ static inline uint8_t gattservice_subevent_device_information_pnp_id_get_vendor_
* @note: btstack_type 2
*/
static inline uint16_t gattservice_subevent_device_information_pnp_id_get_vendor_id(const uint8_t * event){
return little_endian_read_16(event, 6);
return little_endian_read_16(event, 7);
}
/**
* @brief Get field product_id from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_PNP_ID
@ -9372,7 +9453,7 @@ static inline uint16_t gattservice_subevent_device_information_pnp_id_get_vendor
* @note: btstack_type 2
*/
static inline uint16_t gattservice_subevent_device_information_pnp_id_get_product_id(const uint8_t * event){
return little_endian_read_16(event, 8);
return little_endian_read_16(event, 9);
}
/**
* @brief Get field product_version from event GATTSERVICE_SUBEVENT_DEVICE_INFORMATION_PNP_ID
@ -9381,7 +9462,7 @@ static inline uint16_t gattservice_subevent_device_information_pnp_id_get_produc
* @note: btstack_type 2
*/
static inline uint16_t gattservice_subevent_device_information_pnp_id_get_product_version(const uint8_t * event){
return little_endian_read_16(event, 10);
return little_endian_read_16(event, 11);
}
/**