Bluetooth: Host: Add a configuration for writable name

In the file gatt.c, GAP service contains the Device Name
characteristic. If writable, authentication and authorization may
be defined by a higher layer specification.It means that GATT
clients can write to device name GAP characteristic without
bonding. So we add a configuration for writable name without
bonding.

Signed-off-by: Jun Huang <huangjun6@xiaomi.com>
Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
diff --git a/subsys/bluetooth/host/Kconfig.gatt b/subsys/bluetooth/host/Kconfig.gatt
index 22994ff..54a0f20 100644
--- a/subsys/bluetooth/host/Kconfig.gatt
+++ b/subsys/bluetooth/host/Kconfig.gatt
@@ -192,6 +192,23 @@
 	  Enabling this option allows remote GATT clients to write to device
 	  name GAP characteristic.
 
+if BT_DEVICE_NAME_GATT_WRITABLE
+config DEVICE_NAME_GATT_WRITABLE_ENCRYPT
+	bool "Encryption required to write name by remote GATT clients"
+	default y
+	help
+	  Enabling this option requires the connection to be encrypted to write
+	  to the device name GAP characteristic.
+
+
+config DEVICE_NAME_GATT_WRITABLE_AUTHEN
+	bool "Authentication required to write name by remote GATT clients"
+	help
+	  Enabling this option requires the connection to be encrypted and
+	  authenticated to write to the device name GAP characteristic.
+
+endif #BT_DEVICE_NAME_GATT_WRITABLE
+
 if BT_DEBUG
 
 config BT_DEBUG_ATT
diff --git a/subsys/bluetooth/host/gatt.c b/subsys/bluetooth/host/gatt.c
index 1d7575f..cd0c072 100644
--- a/subsys/bluetooth/host/gatt.c
+++ b/subsys/bluetooth/host/gatt.c
@@ -175,7 +175,14 @@
 	/* Require pairing for writes to device name */
 	BT_GATT_CHARACTERISTIC(BT_UUID_GAP_DEVICE_NAME,
 			       BT_GATT_CHRC_READ | BT_GATT_CHRC_WRITE,
-			       BT_GATT_PERM_READ | BT_GATT_PERM_WRITE_ENCRYPT,
+			       BT_GATT_PERM_READ |
+#if defined(CONFIG_DEVICE_NAME_GATT_WRITABLE_AUTHEN)
+			       BT_GATT_PERM_WRITE_AUTHEN,
+#elif defined(CONFIG_DEVICE_NAME_GATT_WRITABLE_ENCRYPT)
+			       BT_GATT_PERM_WRITE_ENCRYPT,
+#else
+			       BT_GATT_PERM_WRITE,
+#endif
 			       read_name, write_name, bt_dev.name),
 #else
 	BT_GATT_CHARACTERISTIC(BT_UUID_GAP_DEVICE_NAME, BT_GATT_CHRC_READ,