UPSTREAM: core/service: Fix calling driver .accept multiple times

service_accept shall not call driver .accept callback multiple times.

BUG=chromium:547822

Change-Id: I59869764c6ec3ae26dee73a606905d84315cf317
Reviewed-on: https://chromium-review.googlesource.com/308737
Commit-Ready: Jakub x Jakub Pawlowski <jpawlowski@chromium.org>
Tested-by: Jakub x Jakub Pawlowski <jpawlowski@chromium.org>
Reviewed-by: Arman Uguray <armansito@chromium.org>
Reviewed-by: Jakub x Jakub Pawlowski <jpawlowski@chromium.org>
diff --git a/src/service.c b/src/service.c
index cae2804..2ed72fb 100644
--- a/src/service.c
+++ b/src/service.c
@@ -184,6 +184,18 @@
 	char addr[18];
 	int err;
 
+	switch (service->state) {
+	case BTD_SERVICE_STATE_UNAVAILABLE:
+		return -EINVAL;
+	case BTD_SERVICE_STATE_DISCONNECTED:
+		break;
+	case BTD_SERVICE_STATE_CONNECTING:
+	case BTD_SERVICE_STATE_CONNECTED:
+		return -EALREADY;
+	case BTD_SERVICE_STATE_DISCONNECTING:
+		return -EBUSY;
+	}
+
 	if (!service->profile->accept)
 		goto done;