Diff between 46f47fc8a1683100c7d08200f420fbb41a3a6754 and e4dae82fb742a3e568aaed2dfb65a123441d92ca

Changed Files

File Additions Deletions Status
doc/advertising-api.txt +13 -5 modified
src/advertising.c +8 -5 modified

Full Patch

diff --git a/doc/advertising-api.txt b/doc/advertising-api.txt
index 1c18ae3..8207b59 100644
--- a/doc/advertising-api.txt
+++ b/doc/advertising-api.txt
@@ -82,19 +82,27 @@ Methods		RegisterAdvertisement(object advertisement, dict options)
 
 			Registers an advertisement object to be sent over the LE
 			Advertising channel.  The service must be exported
-			under interface LEAdvertisement1. InvalidArguments
-			indicates that the object has invalid or conflicting
-			properties.  InvalidLength indicates that the data
+			under interface LEAdvertisement1.
+
+			InvalidArguments error indicates that the object has
+			invalid or conflicting properties.
+
+			InvalidLength error indicates that the data
 			provided generates a data packet which is too long.
+
 			The properties of this object are parser when it is
 			registered, and any changes are ignored.
-			Currently only one advertisement at a time is supported,
-			attempting to register two advertisements will result in
+
+			If the same object is registered twice it will result in
 			an AlreadyExists error.
 
+			If the maximum number of advertisement instances is
+			reached it will result in NotPermitted error.
+
 			Possible errors: org.bluez.Error.InvalidArguments
 					 org.bluez.Error.AlreadyExists
 					 org.bluez.Error.InvalidLength
+					 org.bluez.Error.NotPermitted
 
 		UnregisterAdvertisement(object advertisement)
 
diff --git a/src/advertising.c b/src/advertising.c
index de07a98..1bea0d1 100644
--- a/src/advertising.c
+++ b/src/advertising.c
@@ -627,11 +627,6 @@ static struct btd_adv_client *client_create(struct btd_adv_manager *manager,
 	if (!client->data)
 		goto fail;
 
-	client->instance = util_get_uid(&manager->instance_bitmap,
-							manager->max_ads);
-	if (!client->instance)
-		goto fail;
-
 	client->manager = manager;
 
 	return client;
@@ -675,6 +670,14 @@ static DBusMessage *register_advertisement(DBusConnection *conn,
 		return btd_error_failed(msg,
 					"Failed to register advertisement");
 
+	client->instance = util_get_uid(&manager->instance_bitmap,
+							manager->max_ads);
+	if (!client->instance) {
+		client_free(client);
+		return btd_error_not_permitted(msg,
+					"Maximum advertisements reached");
+	}
+
 	DBG("Registered advertisement at path %s", match.path);
 
 	queue_push_tail(manager->clients, client);