aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Stange <stange@google.com>2022-04-20 19:44:09 +0000
committerAnthony Stange <stange@google.com>2022-04-20 20:42:49 +0000
commit091f7c5f20d687657cef79719c735846173d784c (patch)
treebb3597756f7943a5f59e9b5cf77f3cd4169dfbfc
parentf3bc782e6fe69ff17087b21d3575436a23a45daf (diff)
downloadchre-091f7c5f20d687657cef79719c735846173d784c.tar.gz
Fix CHPP NAN sub/cancel handling
For async work, CHPP uses a response to indicate that the service accepted the response and a notification to deliver the data. Fix sub/sub_cancel to abide by this scheme to prevent duplicate RX when using NAN since previously a response was used to deliver the callback data when sub/cancel was run. Bug: 206614765 Test: Run CHPP instance locally Change-Id: I9fc666626cbc28451a6631885a450ea6871664ed
-rw-r--r--chpp/clients/wifi.c111
-rw-r--r--chpp/services/wifi.c4
2 files changed, 95 insertions, 20 deletions
diff --git a/chpp/clients/wifi.c b/chpp/clients/wifi.c
index 71e411f3..0c8db890 100644
--- a/chpp/clients/wifi.c
+++ b/chpp/clients/wifi.c
@@ -163,6 +163,9 @@ static void chppWifiDiscoveryEventNotification(uint8_t *buf, size_t len);
static void chppWifiNanServiceLostEventNotification(uint8_t *buf, size_t len);
static void chppWifiNanServiceTerminatedEventNotification(uint8_t *buf,
size_t len);
+static void chppWifiRequestNanSubscribeNotification(uint8_t *buf, size_t len);
+static void chppWifiNanSubscriptionCanceledNotification(uint8_t *buf,
+ size_t len);
static void chppWifiNanSubscriptionCanceledResult(uint8_t *buf, size_t len);
/************************************************
@@ -300,6 +303,16 @@ static enum ChppAppErrorCode chppDispatchWifiNotification(void *clientContext,
break;
}
+ case CHPP_WIFI_REQUEST_NAN_SUB: {
+ chppWifiRequestNanSubscribeNotification(buf, len);
+ break;
+ }
+
+ case CHPP_WIFI_REQUEST_NAN_SUB_CANCEL: {
+ chppWifiNanSubscriptionCanceledNotification(buf, len);
+ break;
+ }
+
default: {
error = CHPP_APP_ERROR_INVALID_COMMAND;
break;
@@ -552,35 +565,45 @@ static void chppWifiRequestRangingResult(
/**
* Handles the service response for the NAN subscribe client request.
*
+ * This function is called from chppDispatchWifiResponse().
+ *
* @param buf Input data. Cannot be null.
+ * @param len Length of input data in bytes.
*/
static void chppWifiRequestNanSubscribeResult(uint8_t *buf, size_t len) {
- uint8_t errorCode = CHRE_ERROR_NONE;
- uint32_t subscriptionId = 0;
+ UNUSED_VAR(len);
+
+ struct ChppAppHeader *rxHeader = (struct ChppAppHeader *)buf;
+
+ if (rxHeader->error != CHPP_APP_ERROR_NONE) {
+ gCallbacks->nanServiceIdentifierCallback(
+ chppAppErrorToChreError(rxHeader->error), 0 /* subscriptionId */);
- if (len < sizeof(struct ChppWifiNanServiceIdentifier)) {
- errorCode = CHRE_ERROR;
} else {
- struct ChppWifiNanServiceIdentifier *id =
- (struct ChppWifiNanServiceIdentifier *)buf;
- errorCode = id->errorCode;
- subscriptionId = id->subscriptionId;
+ CHPP_LOGD("NAN sub accepted at service");
}
- gCallbacks->nanServiceIdentifierCallback(errorCode, subscriptionId);
}
+/**
+ * Handles the service response for the NAN subscription cancel client request.
+ *
+ * This function is called from chppDispatchWifiResponse().
+ *
+ * @param buf Input data. Cannot be null.
+ * @param len Length of input data in bytes.
+ */
static void chppWifiNanSubscriptionCanceledResult(uint8_t *buf, size_t len) {
- uint8_t errorCode = CHRE_ERROR_NONE;
- uint32_t subscriptionId = 0;
- if (len < (sizeof(struct ChppWifiNanSubscriptionCanceledResponse))) {
- errorCode = CHRE_ERROR;
+ UNUSED_VAR(len);
+
+ struct ChppAppHeader *rxHeader = (struct ChppAppHeader *)buf;
+
+ if (rxHeader->error != CHPP_APP_ERROR_NONE) {
+ gCallbacks->nanSubscriptionCanceledCallback(
+ chppAppErrorToChreError(rxHeader->error), 0 /* subscriptionId */);
+
} else {
- struct ChppWifiNanSubscriptionCanceledResponse *chppNotif =
- (struct ChppWifiNanSubscriptionCanceledResponse *)buf;
- errorCode = chppNotif->errorCode;
- subscriptionId = chppNotif->subscriptionId;
+ CHPP_LOGD("NAN sub cancel accepted at service");
}
- gCallbacks->nanSubscriptionCanceledCallback(errorCode, subscriptionId);
}
/**
@@ -676,6 +699,8 @@ static void chppWifiRangingEventNotification(
/**
* Handles the NAN discovery event service notification.
*
+ * This function is called from chppDispatchWifiNotification().
+ *
* @param buf Input data. Cannot be null.
* @param len Length of input data in bytes.
*/
@@ -700,6 +725,8 @@ static void chppWifiDiscoveryEventNotification(uint8_t *buf, size_t len) {
/**
* Handles the NAN connection lost event service notification.
*
+ * This function is called from chppDispatchWifiNotification().
+ *
* @param buf Input data. Cannot be null.
* @param len Length of input data in bytes.
*/
@@ -722,6 +749,8 @@ static void chppWifiNanServiceLostEventNotification(uint8_t *buf, size_t len) {
/**
* Handles the NAN subscription termination event service notification.
*
+ * This function is called from chppDispatchWifiNotification().
+ *
* @param buf Input data. Cannot be null.
* @param len Length of input data in bytes.
*/
@@ -743,6 +772,52 @@ static void chppWifiNanServiceTerminatedEventNotification(uint8_t *buf,
}
/**
+ * Handles the service response for the NAN subscribe client request.
+ *
+ * This function is called from chppDispatchWifiNotification().
+ *
+ * @param buf Input data. Cannot be null.
+ * @param len Length of input data in bytes.
+ */
+static void chppWifiRequestNanSubscribeNotification(uint8_t *buf, size_t len) {
+ uint8_t errorCode = CHRE_ERROR_NONE;
+ uint32_t subscriptionId = 0;
+
+ if (len < sizeof(struct ChppWifiNanServiceIdentifier)) {
+ errorCode = CHRE_ERROR;
+ } else {
+ struct ChppWifiNanServiceIdentifier *id =
+ (struct ChppWifiNanServiceIdentifier *)buf;
+ errorCode = id->errorCode;
+ subscriptionId = id->subscriptionId;
+ }
+ gCallbacks->nanServiceIdentifierCallback(errorCode, subscriptionId);
+}
+
+/**
+ * Handles the service response for the NAN subscription cancel client request.
+ *
+ * This function is called from chppDispatchWifiNotification().
+ *
+ * @param buf Input data. Cannot be null.
+ * @param len Length of input data in bytes.
+ */
+static void chppWifiNanSubscriptionCanceledNotification(uint8_t *buf,
+ size_t len) {
+ uint8_t errorCode = CHRE_ERROR_NONE;
+ uint32_t subscriptionId = 0;
+ if (len < (sizeof(struct ChppWifiNanSubscriptionCanceledResponse))) {
+ errorCode = CHRE_ERROR;
+ } else {
+ struct ChppWifiNanSubscriptionCanceledResponse *chppNotif =
+ (struct ChppWifiNanSubscriptionCanceledResponse *)buf;
+ errorCode = chppNotif->errorCode;
+ subscriptionId = chppNotif->subscriptionId;
+ }
+ gCallbacks->nanSubscriptionCanceledCallback(errorCode, subscriptionId);
+}
+
+/**
* Initializes the WiFi client upon an open request from CHRE and responds
* with the result.
*
diff --git a/chpp/services/wifi.c b/chpp/services/wifi.c
index b503b204..40e80596 100644
--- a/chpp/services/wifi.c
+++ b/chpp/services/wifi.c
@@ -845,7 +845,7 @@ static void chppWifiServiceNanIdentifierCallback(uint8_t errorCode,
} else {
id->header.command = CHPP_WIFI_REQUEST_NAN_SUB;
id->header.handle = gWifiServiceContext.service.handle;
- id->header.type = CHPP_MESSAGE_TYPE_SERVICE_RESPONSE;
+ id->header.type = CHPP_MESSAGE_TYPE_SERVICE_NOTIFICATION;
id->header.error = CHPP_APP_ERROR_NONE;
id->header.transaction =
gWifiServiceContext.requestNanSubscribe.transaction;
@@ -992,7 +992,7 @@ static void chppWifiServiceNanSubscriptionCanceledCallback(
} else {
response->header.command = CHPP_WIFI_REQUEST_NAN_SUB_CANCEL;
response->header.handle = gWifiServiceContext.service.handle;
- response->header.type = CHPP_MESSAGE_TYPE_SERVICE_RESPONSE;
+ response->header.type = CHPP_MESSAGE_TYPE_SERVICE_NOTIFICATION;
response->header.error = CHPP_APP_ERROR_NONE;
response->header.transaction =
gWifiServiceContext.requestNanSubscribeCancel.transaction;