Check the certification mode in the runtime 89/275389/1
authorDohyun Pyun <dh79.pyun@samsung.com>
Mon, 23 May 2022 05:25:26 +0000 (14:25 +0900)
committerDohyun Pyun <dh79.pyun@samsung.com>
Tue, 24 May 2022 05:35:40 +0000 (14:35 +0900)
Change-Id: Ibde861ed71f0998d61fdbab25681c8226df19ed7
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 40c074a..de348c2 100644 (file)
@@ -22,6 +22,7 @@
 #include "src/shared/gatt-client.h"
 #if defined TIZEN_FEATURE_BLUEZ_MODIFY
 #include "../log.h"
+#include "../../profile.h"
 #endif
 
 #include <assert.h>
@@ -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;
index 733a21d..714f217 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
@@ -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,