Check the certification mode in the runtime 48/275348/1
authorDohyun Pyun <dh79.pyun@samsung.com>
Mon, 23 May 2022 05:25:26 +0000 (14:25 +0900)
committerDohyun Pyun <dh79.pyun@samsung.com>
Mon, 23 May 2022 05:25:26 +0000 (14:25 +0900)
Change-Id: I6d646248178de5d08193088864d7da4e60eceabf
Signed-off-by: Dohyun Pyun <dh79.pyun@samsung.com>
profile.h
src/shared/gatt-client.c
src/shared/gatt-server.c

index 3df75a5..8209fd5 100755 (executable)
--- 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__ */
 
index 376ec2c..c855de7 100644 (file)
@@ -35,6 +35,7 @@
 #include "src/shared/gatt-client.h"
 #if defined TIZEN_FEATURE_BLUEZ_MODIFY
 #include "../log.h"
+#include "../../profile.h"
 #endif
 
 #include <assert.h>
@@ -1783,43 +1784,50 @@ static bool notify_data_write_ccc(struct notify_data *notify_data, bool enable,
                        return false;
        }
 
-#ifndef TIZEN_CERTIFICATE
+#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
-       /* 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;
-
        att_id = 0;
 
-       if (pdu[2] & 0x01)
-               notify = true;
-
-       if (pdu[2] & 0x02)
-               indicate = true;
-
-       if (notify == true) {
-               pdu[2] = 0x01;
-
+       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 (indicate == true) {
-               pdu[2] = 0x02;
+               if (pdu[2] & 0x01)
+                       notify = true;
 
-               att_id = bt_att_send(notify_data->client->att, BT_ATT_OP_WRITE_REQ,
-                                                       pdu, sizeof(pdu), callback,
-                                                       NULL,
-                                                       NULL);
+               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
 
@@ -1855,9 +1863,11 @@ static void enable_ccc_callback(uint8_t opcode, const void *pdu,
 {
        struct notify_data *notify_data = user_data;
 
-#ifdef TIZEN_CERTIFICATE
-       if (notify_data == NULL)
-               return;
+#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);
index 8edd31a..d27c8dd 100644 (file)
 #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
@@ -543,10 +547,12 @@ 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 (start == 0x00ff && end == 0x00ff) {
-                       ecode = BT_ATT_ERROR_AUTHENTICATION;
-                       goto error;
+#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;
@@ -862,20 +868,22 @@ static void write_cb(struct bt_att_chan *chan, uint8_t opcode, const void *pdu,
                goto error;
        }
 
-#ifdef TIZEN_CERTIFICATE
-       /* GATT/SR/GAW/BI-05-C
-          Write Characteristic Value - Insufficient Authentication (0x05)
-          For 0x2aff UUID, return authentication error
-          We need to register 0x2aff UUID for this
-       */
-       const bt_uuid_t *uuid;
-       static const bt_uuid_t error_uuid = { .type = BT_UUID16,
-                                               .value.u16 = 0x2aff };
+#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
+                  We need to register 0x2aff UUID for this
+               */
+               const bt_uuid_t *uuid;
+               static const bt_uuid_t error_uuid = { .type = BT_UUID16,
+                                                       .value.u16 = 0x2aff };
 
-       uuid = gatt_db_attribute_get_type(attr);
-       if (!bt_uuid_cmp(&error_uuid, uuid)) {
-               ecode = BT_ATT_ERROR_AUTHENTICATION;
-               goto error;
+               uuid = gatt_db_attribute_get_type(attr);
+               if (!bt_uuid_cmp(&error_uuid, uuid)) {
+                       ecode = BT_ATT_ERROR_AUTHENTICATION;
+                       goto error;
+               }
        }
 #endif
 
@@ -1007,33 +1015,37 @@ static void handle_read_req(struct bt_att_chan *chan,
 
        attr = gatt_db_get_attribute(server->db, handle);
        if (!attr) {
-#ifdef TIZEN_CERTIFICATE
-               /* GATT/SR/GAR/BI-34-C
-                  GATT/SR/GAR/BI-35-C
-                  Read Characteristic Value - Invalid Transport Access over LE or BR/EDR (0x80)
-                  For 0x00FF UUID, return Invalid Transport Access Error
-                  We need to register 0x00FF UUID for this
-
-                  GATT/SR/GAR/BI-04-C
-                  Read Characteristic Value . Insufficient Authentication (0x05)
-                  For 0x2aff UUID, return authentication error
-                  We need to register 0x2aff UUID for this
-               */
-
-               const bt_uuid_t *uuid;
-               char uuidstr[MAX_LEN_UUID_STR + 1];
-
-               static const bt_uuid_t error_uuid = { .type = BT_UUID16,
-                                                       .value.u16 = 0x2aff };
-
-               uuid = gatt_db_attribute_get_type(attr);
-
-               bt_uuid_to_string(uuid, uuidstr, sizeof(uuidstr));
-
-               if (handle == 0x00FF) {
-                       ecode = 0x80;
-               } else if (!bt_uuid_cmp(&error_uuid, uuid)) {
-                       ecode = BT_ATT_ERROR_AUTHENTICATION;
+#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)
+                          For 0x00FF UUID, return Invalid Transport Access Error
+                          We need to register 0x00FF UUID for this
+
+                          GATT/SR/GAR/BI-04-C
+                          Read Characteristic Value . Insufficient Authentication (0x05)
+                          For 0x2aff UUID, return authentication error
+                          We need to register 0x2aff UUID for this
+                       */
+
+                       const bt_uuid_t *uuid;
+                       char uuidstr[MAX_LEN_UUID_STR + 1];
+
+                       static const bt_uuid_t error_uuid = { .type = BT_UUID16,
+                                                               .value.u16 = 0x2aff };
+
+                       uuid = gatt_db_attribute_get_type(attr);
+
+                       bt_uuid_to_string(uuid, uuidstr, sizeof(uuidstr));
+
+                       if (handle == 0x00FF) {
+                               ecode = 0x80;
+                       } else if (!bt_uuid_cmp(&error_uuid, uuid)) {
+                               ecode = BT_ATT_ERROR_AUTHENTICATION;
+                       } else {
+                               ecode = BT_ATT_ERROR_INVALID_HANDLE;
+                       }
                } else {
                        ecode = BT_ATT_ERROR_INVALID_HANDLE;
                }
@@ -1043,21 +1055,23 @@ static void handle_read_req(struct bt_att_chan *chan,
                goto error;
        }
 
-#ifdef TIZEN_CERTIFICATE
-       /* GATT/SR/GAR/BI-04-C
-          Read Characteristic Value . Insufficient Authentication (0x05)
-          For 0x2AFF UUID, return authentication error
-          We need to register 0x2aff UUID for this
+#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
+                  We need to register 0x2aff UUID for this
 
-       */
-       const bt_uuid_t *uuid;
-       static const bt_uuid_t error_uuid = { .type = BT_UUID16,
-                                               .value.u16 = 0x2aff };
+               */
+               const bt_uuid_t *uuid;
+               static const bt_uuid_t error_uuid = { .type = BT_UUID16,
+                                                       .value.u16 = 0x2aff };
 
-       uuid = gatt_db_attribute_get_type(attr);
-       if (!bt_uuid_cmp(&error_uuid, uuid)) {
-               ecode = BT_ATT_ERROR_AUTHENTICATION;
-               goto error;
+               uuid = gatt_db_attribute_get_type(attr);
+               if (!bt_uuid_cmp(&error_uuid, uuid)) {
+                       ecode = BT_ATT_ERROR_AUTHENTICATION;
+                       goto error;
+               }
        }
 #endif
 
@@ -1470,22 +1484,24 @@ static void prep_write_cb(struct bt_att_chan *chan, uint8_t opcode,
                goto error;
        }
 
-#ifdef TIZEN_CERTIFICATE
-       /* GATT/SR/GAW/BI-12-C
-          Write Long Characteristic Value - Insufficient Authentication (0x05)
-          For 0x2af8 or 0x2aff UUID, return authentication error
-          We need to register 0x2af8 or 0x2aff UUID for this
-       */
-       const bt_uuid_t *uuid;
-       static const bt_uuid_t long_uuid = { .type = BT_UUID16,
-                                               .value.u16 = 0x2af8 };
-       static const bt_uuid_t error_uuid = { .type = BT_UUID16,
-                                               .value.u16 = 0x2aff };
-
-       uuid = gatt_db_attribute_get_type(attr);
-       if (!bt_uuid_cmp(&long_uuid, uuid) || !bt_uuid_cmp(&error_uuid, uuid)) {
-               ecode = BT_ATT_ERROR_AUTHENTICATION;
-               goto error;
+#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
+                  We need to register 0x2af8 or 0x2aff UUID for this
+               */
+               const bt_uuid_t *uuid;
+               static const bt_uuid_t long_uuid = { .type = BT_UUID16,
+                                                       .value.u16 = 0x2af8 };
+               static const bt_uuid_t error_uuid = { .type = BT_UUID16,
+                                                       .value.u16 = 0x2aff };
+
+               uuid = gatt_db_attribute_get_type(attr);
+               if (!bt_uuid_cmp(&long_uuid, uuid) || !bt_uuid_cmp(&error_uuid, uuid)) {
+                       ecode = BT_ATT_ERROR_AUTHENTICATION;
+                       goto error;
+               }
        }
 #endif