[OTP] Fix PTS fail cases
[platform/core/connectivity/bluetooth-frwk.git] / bt-otp / bt-otpserver.c
index f283dd0..8cc4493 100644 (file)
@@ -398,8 +398,10 @@ int _bt_otp_prepare_ots(void)
        }
 
        /* Characteristic Object Properties */
-       props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ;
-       perms = BLUETOOTH_GATT_PERMISSION_READ;
+       props = BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ |
+                       BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE;
+       perms = BLUETOOTH_GATT_PERMISSION_READ |
+                       BLUETOOTH_GATT_PERMISSION_WRITE;
        char_uuid = _otp_convert_uuid_to_uuid128(OTP_OBJECT_PROP_UUID);
        ret = add_new_characteristic(char_uuid, perms, props,
                                        &otp_object_prop_obj_path);
@@ -1152,6 +1154,11 @@ int _bt_otp_oacp_write_cb(char *value, int len, int offset,
                g_free(uuid);
                break;
        case OACP_DELETE:
+               if (opcode == OACP_DELETE &&
+                               ~(selected_object->props & OBJECT_DELETE)) {
+                       ret = OACP_PROCEDURE_NOT_SUPPORTED;
+                       goto fail;
+               }
                snprintf(absolute_file_path, sizeof(absolute_file_path),
                                                "%s%s", directory, selected_object->name);
 
@@ -1170,6 +1177,11 @@ int _bt_otp_oacp_write_cb(char *value, int len, int offset,
                ret = OACP_OPCODE_NOT_SUPPORTED;
                break;
        case OACP_EXECUTE:
+               if (opcode == OACP_EXECUTE &&
+                               ~(selected_object->props & OBJECT_EXECUTE)) {
+                       ret = OACP_PROCEDURE_NOT_SUPPORTED;
+                       goto fail;
+               }
                snprintf(absolute_file_path, sizeof(absolute_file_path),
                                        "file://%s%s", directory, selected_object->name);
 
@@ -1186,6 +1198,18 @@ int _bt_otp_oacp_write_cb(char *value, int len, int offset,
                break;
        case OACP_READ:
        case OACP_WRITE:
+               if (opcode == OACP_WRITE &&
+                               ~(selected_object->props & OBJECT_WRITE)) {
+                       ret = OACP_PROCEDURE_NOT_SUPPORTED;
+                       goto fail;
+               }
+
+               if (opcode == OACP_READ &&
+                               ~(selected_object->props & OBJECT_READ)) {
+                       ret = OACP_PROCEDURE_NOT_SUPPORTED;
+                       goto fail;
+               }
+
                object_offset = (uint32_t)(value[4] & 0xFF) << 24 |
                                (uint32_t)(value[3] & 0xFF) << 16 |
                                (uint32_t)(value[2] & 0xFF) << 8  |
@@ -1220,7 +1244,7 @@ int _bt_otp_oacp_write_cb(char *value, int len, int offset,
 
                err = _bt_otp_open_otc_and_listen(remote_addr, "ListenOtc");
                if (err != BLUETOOTH_ERROR_NONE) {
-                       ret = OACP_OPERATION_FAILED;
+                       ret = OACP_CHANNEL_UNAVAILABLE;
                        _bt_otp_free_oacp_op();
                        goto fail;
                }
@@ -1651,6 +1675,7 @@ void _bt_otp_gatt_char_property_changed_event(GVariant *msg,
                                guint16 offset = 0;
                                char *value = NULL;
                                struct indicate_info info;
+
                                g_variant_get(var, "(&s&s&syq@ay)",
                                                &char_path, &svc_handle,
                                                &addr, &req_id, &offset, &val);
@@ -1664,9 +1689,15 @@ void _bt_otp_gatt_char_property_changed_event(GVariant *msg,
 
                                if (len != 0) {
                                        if (!g_strcmp0(char_path, otp_oacp_obj_path)) {
-                                               result = _bt_otp_oacp_write_cb(value, len, offset, addr, &info);
+                                               if (!OACP_indicate)
+                                                       result = BLUETOOTH_ERROR_CCC_IMPROPERLY_CONFIGURED;
+                                               else
+                                                       result = _bt_otp_oacp_write_cb(value, len, offset, addr, &info);
                                        } else if (!g_strcmp0(char_path, otp_olcp_obj_path)) {
-                                               result = _bt_otp_olcp_write_cb(value, len, offset, &info);
+                                               if (!OLCP_indicate)
+                                                       result = BLUETOOTH_ERROR_CCC_IMPROPERLY_CONFIGURED;
+                                               else
+                                                       result = _bt_otp_olcp_write_cb(value, len, offset, &info);
                                        } else if (!g_strcmp0(char_path, otp_object_name_obj_path)) {
                                                if (oacp_create) {
                                                        /* OACP_CREATE is ongoing */