From 11e9ac4e3a7357627bece3ee2582a3ca131b6a05 Mon Sep 17 00:00:00 2001 From: Dohyun Pyun Date: Mon, 23 May 2022 14:25:26 +0900 Subject: [PATCH] Check the certification mode in the runtime Change-Id: Ibde861ed71f0998d61fdbab25681c8226df19ed7 Signed-off-by: Dohyun Pyun --- profile.h | 30 ++++++++++++++++++++++++++++ src/shared/gatt-client.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ src/shared/gatt-server.c | 26 +++++++++++++++++++----- 3 files changed, 102 insertions(+), 5 deletions(-) diff --git a/profile.h b/profile.h index 3df75a5..8209fd5 100755 --- a/profile.h +++ b/profile.h @@ -31,6 +31,9 @@ #define TYPE_FIELD "string" #define FEATURE_TAG "platform" #define MODEL_CONFIG_TAG "model-config" +#define CERTI_STACK_FILE "/var/lib/bluetooth/stack_test" +#define CERTI_PROFILE_FILE "/var/lib/bluetooth/profile_test" + typedef enum { TIZEN_PROFILE_UNKNOWN = 0, @@ -54,8 +57,16 @@ typedef enum { TIZEN_MODEL_ROBOT = 0x80, } tizen_model_t; +typedef enum { + TIZEN_CERTI_MODE_UNKNOWN = 0, + TIZEN_CERTI_MODE_DISABLE = 0x1, + TIZEN_CERTI_MODE_STACK = 0x2, + TIZEN_CERTI_MODE_PROFILE = 0x4, +} tizen_certifcation_mode_t; + static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN; static tizen_model_t model = TIZEN_MODEL_UNKNOWN; +static tizen_certifcation_mode_t certification_mode = TIZEN_CERTI_MODE_UNKNOWN; static inline int __get_profile_from_model_config_xml(const char *field, char **value) { @@ -212,6 +223,23 @@ static inline tizen_model_t _get_tizen_model(void) return model; } +static inline tizen_certifcation_mode_t _get_tizen_certification_mode(void) +{ + if (__builtin_expect(certification_mode != TIZEN_CERTI_MODE_UNKNOWN, 1)) + return certification_mode; + + if (access(CERTI_STACK_FILE, F_OK) == 0) + certification_mode |= TIZEN_CERTI_MODE_STACK; + + if (access(CERTI_PROFILE_FILE, F_OK) == 0) + certification_mode |= TIZEN_CERTI_MODE_PROFILE; + + if (certification_mode == TIZEN_CERTI_MODE_UNKNOWN) + certification_mode = TIZEN_CERTI_MODE_DISABLE; + + return certification_mode; +} + #define TIZEN_FEATURE_BLUEZ_BRCM_CHIP ((_get_tizen_profile()) == TIZEN_PROFILE_IVI) #define TIZEN_FEATURE_BLUEZ_WEARABLE ((_get_tizen_profile()) == TIZEN_PROFILE_WEARABLE) #define TIZEN_FEATURE_BLUEZ_SMS_ONLY ((_get_tizen_profile()) == TIZEN_PROFILE_WEARABLE) @@ -222,6 +250,8 @@ static inline tizen_model_t _get_tizen_model(void) #define TIZEN_FEATURE_BLUEZ_SPRD_PAGE_SCAN ((_get_tizen_model()) == TIZEN_MODEL_TM1) #define TIZEN_FEATURE_BLUEZ_SPEAKER_REFERENCE ((_get_tizen_model()) == TIZEN_MODEL_RPI3 && (_get_tizen_profile()) == TIZEN_PROFILE_COMMON) #define TIZEN_FEATURE_ROBOT_REFERENCE ((_get_tizen_model()) == TIZEN_MODEL_ROBOT) +#define TIZEN_FEATURE_BLUEZ_STACK_CERTIFICATION (((_get_tizen_certification_mode()) & TIZEN_CERTI_MODE_STACK) != 0) +#define TIZEN_FEATURE_BLUEZ_PROFILE_CERTIFICATION (((_get_tizen_certification_mode()) & TIZEN_CERTI_MODE_PROFILE) != 0) #endif /* __TIZEN_PROFILE_H__ */ diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c index 40c074a..de348c2 100644 --- a/src/shared/gatt-client.c +++ b/src/shared/gatt-client.c @@ -22,6 +22,7 @@ #include "src/shared/gatt-client.h" #if defined TIZEN_FEATURE_BLUEZ_MODIFY #include "../log.h" +#include "../../profile.h" #endif #include @@ -1772,10 +1773,53 @@ static bool notify_data_write_ccc(struct notify_data *notify_data, bool enable, return false; } +#ifndef TIZEN_FEATURE_BLUEZ_MODIFY att_id = bt_att_send(notify_data->client->att, BT_ATT_OP_WRITE_REQ, pdu, sizeof(pdu), callback, notify_data_ref(notify_data), notify_data_unref); +#else + att_id = 0; + + if (!TIZEN_FEATURE_BLUEZ_STACK_CERTIFICATION) { + att_id = bt_att_send(notify_data->client->att, BT_ATT_OP_WRITE_REQ, + pdu, sizeof(pdu), callback, + notify_data_ref(notify_data), + notify_data_unref); + } else { + /* GAP/SEC/SEM/BV-56-C, GAP/SEC/SEM/BV-59-C + PTS expects to recieve the sperated value for notify and indicate + So seperate the value and send it + */ + bool notify = false; + bool indicate = false; + + if (pdu[2] & 0x01) + notify = true; + + if (pdu[2] & 0x02) + indicate = true; + + if (notify == true) { + pdu[2] = 0x01; + + att_id = bt_att_send(notify_data->client->att, BT_ATT_OP_WRITE_REQ, + pdu, sizeof(pdu), callback, + notify_data_ref(notify_data), + notify_data_unref); + } + + if (indicate == true) { + pdu[2] = 0x02; + + att_id = bt_att_send(notify_data->client->att, BT_ATT_OP_WRITE_REQ, + pdu, sizeof(pdu), callback, + NULL, + NULL); + } + } +#endif + notify_data->chrc->ccc_write_id = notify_data->att_id = att_id; return !!att_id; @@ -1808,6 +1852,13 @@ static void enable_ccc_callback(uint8_t opcode, const void *pdu, { struct notify_data *notify_data = user_data; +#if defined TIZEN_FEATURE_BLUEZ_MODIFY + if (TIZEN_FEATURE_BLUEZ_STACK_CERTIFICATION) { + if (notify_data == NULL) + return; + } +#endif + assert(notify_data->chrc->ccc_write_id); notify_data->chrc->ccc_write_id = 0; diff --git a/src/shared/gatt-server.c b/src/shared/gatt-server.c index 733a21d..714f217 100644 --- a/src/shared/gatt-server.c +++ b/src/shared/gatt-server.c @@ -25,6 +25,10 @@ #include "src/shared/util.h" #include "src/shared/timeout.h" +#ifdef TIZEN_FEATURE_BLUEZ_MODIFY +#include "../../profile.h" +#endif + #ifndef MAX #define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif @@ -512,11 +516,13 @@ static void read_by_type_cb(struct bt_att_chan *chan, uint8_t opcode, gatt_db_read_by_type(server->db, start, end, type, q); if (queue_isempty(q)) { -#ifdef TIZEN_CERTIFICATE +#if defined TIZEN_FEATURE_BLUEZ_MODIFY + if (TIZEN_FEATURE_BLUEZ_STACK_CERTIFICATION) { if (start == 0x00ff && end == 0x00ff) { ecode = BT_ATT_ERROR_AUTHENTICATION; goto error; } + } #endif ecode = BT_ATT_ERROR_ATTRIBUTE_NOT_FOUND; goto error; @@ -837,7 +843,8 @@ static void write_cb(struct bt_att_chan *chan, uint8_t opcode, const void *pdu, goto error; } -#ifdef TIZEN_CERTIFICATE +#if defined TIZEN_FEATURE_BLUEZ_MODIFY + if (TIZEN_FEATURE_BLUEZ_STACK_CERTIFICATION) { /* GATT/SR/GAW/BI-05-C Write Characteristic Value - Insufficient Authentication (0x05) For 0x2aff UUID, return authentication error @@ -852,6 +859,7 @@ static void write_cb(struct bt_att_chan *chan, uint8_t opcode, const void *pdu, ecode = BT_ATT_ERROR_AUTHENTICATION; goto error; } + } #endif util_debug(server->debug_callback, server->debug_data, @@ -961,7 +969,8 @@ static void handle_read_req(struct bt_att_chan *chan, attr = gatt_db_get_attribute(server->db, handle); if (!attr) { -#ifdef TIZEN_CERTIFICATE +#if defined TIZEN_FEATURE_BLUEZ_MODIFY + if (TIZEN_FEATURE_BLUEZ_STACK_CERTIFICATION) { /* GATT/SR/GAR/BI-34-C GATT/SR/GAR/BI-35-C Read Characteristic Value - Invalid Transport Access over LE or BR/EDR (0x80) @@ -991,13 +1000,17 @@ static void handle_read_req(struct bt_att_chan *chan, } else { ecode = BT_ATT_ERROR_INVALID_HANDLE; } + } else { + ecode = BT_ATT_ERROR_INVALID_HANDLE; + } #else ecode = BT_ATT_ERROR_INVALID_HANDLE; #endif goto error; } -#ifdef TIZEN_CERTIFICATE +#if defined TIZEN_FEATURE_BLUEZ_MODIFY + if (TIZEN_FEATURE_BLUEZ_STACK_CERTIFICATION) { /* GATT/SR/GAR/BI-04-C Read Characteristic Value . Insufficient Authentication (0x05) For 0x2AFF UUID, return authentication error @@ -1013,6 +1026,7 @@ static void handle_read_req(struct bt_att_chan *chan, ecode = BT_ATT_ERROR_AUTHENTICATION; goto error; } + } #endif util_debug(server->debug_callback, server->debug_data, @@ -1411,7 +1425,8 @@ static void prep_write_cb(struct bt_att_chan *chan, uint8_t opcode, goto error; } -#ifdef TIZEN_CERTIFICATE +#if defined TIZEN_FEATURE_BLUEZ_MODIFY + if (TIZEN_FEATURE_BLUEZ_STACK_CERTIFICATION) { /* GATT/SR/GAW/BI-12-C Write Long Characteristic Value - Insufficient Authentication (0x05) For 0x2af8 or 0x2aff UUID, return authentication error @@ -1428,6 +1443,7 @@ static void prep_write_cb(struct bt_att_chan *chan, uint8_t opcode, ecode = BT_ATT_ERROR_AUTHENTICATION; goto error; } + } #endif util_debug(server->debug_callback, server->debug_data, -- 2.7.4