diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-07-09 01:12:06 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2021-07-09 01:12:06 +0000 |
commit | c63cf170628092f4d71ed47f4bedc23bb0078d4a (patch) | |
tree | 73d43aa675b410d5d5845c9cd031f58edcb742e0 | |
parent | 25c517c24618c8d14fa8914ce7034e36968a096c (diff) | |
parent | 58d171a8a4c958f04c11f881c118d1c0f7d5049e (diff) | |
download | chre-c63cf170628092f4d71ed47f4bedc23bb0078d4a.tar.gz |
Snap for 7533212 from 58d171a8a4c958f04c11f881c118d1c0f7d5049e to sc-release
Change-Id: I805422f664348f6a84f79c04c259996e5e9912ef
-rw-r--r-- | chpp/clients.c | 43 | ||||
-rw-r--r-- | chpp/clients/gnss.c | 25 | ||||
-rw-r--r-- | chpp/clients/wifi.c | 27 | ||||
-rw-r--r-- | chpp/clients/wwan.c | 20 | ||||
-rw-r--r-- | chpp/include/chpp/app.h | 7 | ||||
-rw-r--r-- | chpp/include/chpp/clients.h | 14 | ||||
-rw-r--r-- | chpp/transport.c | 13 |
7 files changed, 70 insertions, 79 deletions
diff --git a/chpp/clients.c b/chpp/clients.c index 389c9cbb..06b0d63d 100644 --- a/chpp/clients.c +++ b/chpp/clients.c @@ -73,7 +73,6 @@ static bool chppIsClientApiReady(struct ChppClientState *clientState) { if (clientState->initialized) { switch (clientState->openState) { case (CHPP_OPEN_STATE_CLOSED): - case (CHPP_OPEN_STATE_PSEUDO_OPEN): case (CHPP_OPEN_STATE_WAITING_TO_OPEN): { // result remains false break; @@ -467,15 +466,14 @@ bool chppSendTimestampedRequestAndWaitTimeout( } void chppClientPseudoOpen(struct ChppClientState *clientState) { - if (clientState->openState == CHPP_OPEN_STATE_CLOSED) { - clientState->openState = CHPP_OPEN_STATE_PSEUDO_OPEN; - } + clientState->pseudoOpen = true; } bool chppClientSendOpenRequest(struct ChppClientState *clientState, struct ChppRequestResponseState *openRRState, - uint16_t openCommand, bool reopen) { + uint16_t openCommand, bool blocking) { bool result = false; + uint8_t priorState = clientState->openState; #ifdef CHPP_CLIENT_ENABLED_TIMESYNC chppTimesyncMeasureOffset(clientState->appContext); @@ -487,31 +485,28 @@ bool chppClientSendOpenRequest(struct ChppClientState *clientState, if (request == NULL) { CHPP_LOG_OOM(); - } else if (reopen) { - CHPP_LOGD("Reopening service"); - uint8_t priorState = clientState->openState; + } else { clientState->openState = CHPP_OPEN_STATE_OPENING; - if (!chppSendTimestampedRequestOrFail( - clientState, openRRState, request, sizeof(*request), - CHPP_CLIENT_REQUEST_TIMEOUT_INFINITE)) { - clientState->openState = CHPP_OPEN_STATE_CLOSED; - CHPP_LOGE("Failed to reopen service in state %" PRIu8, priorState); - if (priorState == CHPP_OPEN_STATE_PSEUDO_OPEN) { - clientState->openState = CHPP_OPEN_STATE_PSEUDO_OPEN; - } + + if (blocking) { + CHPP_LOGD("Opening service - blocking"); + result = chppSendTimestampedRequestAndWait(clientState, openRRState, + request, sizeof(*request)); } else { - result = true; + CHPP_LOGD("Opening service - non-blocking"); + result = chppSendTimestampedRequestOrFail( + clientState, openRRState, request, sizeof(*request), + CHPP_CLIENT_REQUEST_TIMEOUT_INFINITE); } - } else { - CHPP_LOGD("Opening service"); - clientState->openState = CHPP_OPEN_STATE_OPENING; - if (!chppSendTimestampedRequestAndWait(clientState, openRRState, request, - sizeof(*request))) { + if (!result) { + CHPP_LOGE("Service open fail from state=%" PRIu8 " psudo=%d blocking=%d", + priorState, clientState->pseudoOpen, blocking); clientState->openState = CHPP_OPEN_STATE_CLOSED; - CHPP_LOGE("Failed to open service"); + + } else if (blocking) { + result = (clientState->openState == CHPP_OPEN_STATE_OPENED); } - result = (clientState->openState == CHPP_OPEN_STATE_OPENED); } return result; diff --git a/chpp/clients/gnss.c b/chpp/clients/gnss.c index 7ac88749..b98a2db9 100644 --- a/chpp/clients/gnss.c +++ b/chpp/clients/gnss.c @@ -323,7 +323,7 @@ static void chppGnssClientNotifyReset(void *clientContext) { false /* clearOnly */); if (gnssClientContext->client.openState != CHPP_OPEN_STATE_OPENED && - gnssClientContext->client.openState != CHPP_OPEN_STATE_PSEUDO_OPEN) { + !gnssClientContext->client.pseudoOpen) { CHPP_LOGW("GNSS client reset but wasn't open"); } else { CHPP_LOGI("GNSS client reopening from state=%" PRIu8, @@ -332,7 +332,7 @@ static void chppGnssClientNotifyReset(void *clientContext) { chppClientSendOpenRequest(&gGnssClientContext.client, &gGnssClientContext.rRState[CHPP_GNSS_OPEN], CHPP_GNSS_OPEN, - /*reopen=*/true); + /*blocking=*/false); } } @@ -345,12 +345,12 @@ static void chppGnssClientNotifyMatch(void *clientContext) { struct ChppGnssClientState *gnssClientContext = (struct ChppGnssClientState *)clientContext; - if (gnssClientContext->client.openState == CHPP_OPEN_STATE_PSEUDO_OPEN) { - CHPP_LOGD("Previously pseudo-open GNSS client reopening"); + if (gnssClientContext->client.pseudoOpen) { + CHPP_LOGD("Pseudo-open GNSS client opening"); chppClientSendOpenRequest(&gGnssClientContext.client, &gGnssClientContext.rRState[CHPP_GNSS_OPEN], CHPP_GNSS_OPEN, - /*reopen=*/true); + /*blocking=*/false); } } @@ -384,10 +384,7 @@ static void chppGnssGetCapabilitiesResult( struct ChppGnssClientState *clientContext, uint8_t *buf, size_t len) { if (len < sizeof(struct ChppGnssGetCapabilitiesResponse)) { struct ChppAppHeader *rxHeader = (struct ChppAppHeader *)buf; - CHPP_LOGE("GetCapabilities failed at service err=%" PRIu8, rxHeader->error); - if (rxHeader->error == CHPP_APP_ERROR_NONE) { - CHPP_LOGE("Missing err"); - } + CHPP_LOGE("GetCapabilities resp. too short. err=%" PRIu8, rxHeader->error); } else { struct ChppGnssGetCapabilitiesParameters *result = @@ -423,9 +420,9 @@ static void chppGnssControlLocationSessionResult( // Short response length indicates an error struct ChppAppHeader *rxHeader = (struct ChppAppHeader *)buf; - CHPP_LOGE("ControlLocation failed at service err=%" PRIu8, rxHeader->error); + CHPP_LOGE("ControlLocation resp. too short. err=%" PRIu8, rxHeader->error); + if (rxHeader->error == CHPP_APP_ERROR_NONE) { - CHPP_LOGE("Missing err"); rxHeader->error = CHPP_APP_ERROR_INVALID_LENGTH; } gCallbacks->locationStatusChangeCallback( @@ -463,9 +460,9 @@ static void chppGnssControlMeasurementSessionResult( // Short response length indicates an error struct ChppAppHeader *rxHeader = (struct ChppAppHeader *)buf; - CHPP_LOGE("Measurement failed at service err=%" PRIu8, rxHeader->error); + CHPP_LOGE("Measurement resp. too short. err=%" PRIu8, rxHeader->error); + if (rxHeader->error == CHPP_APP_ERROR_NONE) { - CHPP_LOGE("Missing err"); rxHeader->error = CHPP_APP_ERROR_INVALID_LENGTH; } gCallbacks->measurementStatusChangeCallback( @@ -618,7 +615,7 @@ static bool chppGnssClientOpen(const struct chrePalSystemApi *systemApi, result = chppClientSendOpenRequest( &gGnssClientContext.client, &gGnssClientContext.rRState[CHPP_GNSS_OPEN], CHPP_GNSS_OPEN, - /*reopen=*/false); + /*blocking=*/true); } #ifdef CHPP_GNSS_CLIENT_OPEN_ALWAYS_SUCCESS diff --git a/chpp/clients/wifi.c b/chpp/clients/wifi.c index 03886c05..387889a9 100644 --- a/chpp/clients/wifi.c +++ b/chpp/clients/wifi.c @@ -321,7 +321,7 @@ static void chppWifiClientNotifyReset(void *clientContext) { chppCheckWifiScanEventNotificationReset(); if (wifiClientContext->client.openState != CHPP_OPEN_STATE_OPENED && - wifiClientContext->client.openState != CHPP_OPEN_STATE_PSEUDO_OPEN) { + !wifiClientContext->client.pseudoOpen) { CHPP_LOGW("WiFi client reset but wasn't open"); } else { CHPP_LOGI("WiFi client reopening from state=%" PRIu8, @@ -329,7 +329,7 @@ static void chppWifiClientNotifyReset(void *clientContext) { chppClientSendOpenRequest(&wifiClientContext->client, &wifiClientContext->rRState[CHPP_WIFI_OPEN], CHPP_WIFI_OPEN, - /*reopen=*/true); + /*blocking=*/false); } } @@ -342,12 +342,12 @@ static void chppWifiClientNotifyMatch(void *clientContext) { struct ChppWifiClientState *wifiClientContext = (struct ChppWifiClientState *)clientContext; - if (wifiClientContext->client.openState == CHPP_OPEN_STATE_PSEUDO_OPEN) { - CHPP_LOGD("Previously pseudo-open WiFi client reopening"); + if (wifiClientContext->client.pseudoOpen) { + CHPP_LOGD("Pseudo-open WiFi client opening"); chppClientSendOpenRequest(&wifiClientContext->client, &wifiClientContext->rRState[CHPP_WIFI_OPEN], CHPP_WIFI_OPEN, - /*reopen=*/true); + /*blocking=*/false); } } @@ -401,10 +401,7 @@ static void chppWifiGetCapabilitiesResult( struct ChppWifiClientState *clientContext, uint8_t *buf, size_t len) { if (len < sizeof(struct ChppWifiGetCapabilitiesResponse)) { struct ChppAppHeader *rxHeader = (struct ChppAppHeader *)buf; - CHPP_LOGE("GetCapabilities failed at service err=%" PRIu8, rxHeader->error); - if (rxHeader->error == CHPP_APP_ERROR_NONE) { - CHPP_LOGE("Missing err"); - } + CHPP_LOGE("GetCapabilities resp. too short. err=%" PRIu8, rxHeader->error); } else { struct ChppWifiGetCapabilitiesParameters *result = @@ -440,9 +437,9 @@ static void chppWifiConfigureScanMonitorResult( // Short response length indicates an error struct ChppAppHeader *rxHeader = (struct ChppAppHeader *)buf; - CHPP_LOGE("Scan monitor failed at service err=%" PRIu8, rxHeader->error); + CHPP_LOGE("ScanMonitor resp. too short. err=%" PRIu8, rxHeader->error); + if (rxHeader->error == CHPP_APP_ERROR_NONE) { - CHPP_LOGE("Missing err"); rxHeader->error = CHPP_APP_ERROR_INVALID_LENGTH; } gCallbacks->scanMonitorStatusChangeCallback( @@ -489,9 +486,9 @@ static void chppWifiRequestScanResult(struct ChppWifiClientState *clientContext, // Short response length indicates an error struct ChppAppHeader *rxHeader = (struct ChppAppHeader *)buf; - CHPP_LOGE("Scan request failed at service err=%" PRIu8, rxHeader->error); + CHPP_LOGE("ScanRequest resp. too short. err=%" PRIu8, rxHeader->error); + if (rxHeader->error == CHPP_APP_ERROR_NONE) { - CHPP_LOGE("Missing err"); rxHeader->error = CHPP_APP_ERROR_INVALID_LENGTH; } gCallbacks->scanResponseCallback(false, @@ -522,7 +519,7 @@ static void chppWifiRequestRangingResult( struct ChppAppHeader *rxHeader = (struct ChppAppHeader *)buf; if (rxHeader->error != CHPP_APP_ERROR_NONE) { - CHPP_LOGE("Ranging request failed at service err=%" PRIu8, rxHeader->error); + CHPP_LOGE("RangingRequest failed at service err=%" PRIu8, rxHeader->error); gCallbacks->rangingEventCallback(chppAppErrorToChreError(rxHeader->error), NULL); @@ -644,7 +641,7 @@ static bool chppWifiClientOpen(const struct chrePalSystemApi *systemApi, result = chppClientSendOpenRequest( &gWifiClientContext.client, &gWifiClientContext.rRState[CHPP_WIFI_OPEN], CHPP_WIFI_OPEN, - /*reopen=*/false); + /*blocking=*/true); } #ifdef CHPP_WIFI_CLIENT_OPEN_ALWAYS_SUCCESS diff --git a/chpp/clients/wwan.c b/chpp/clients/wwan.c index 2e230390..836d9a42 100644 --- a/chpp/clients/wwan.c +++ b/chpp/clients/wwan.c @@ -243,7 +243,7 @@ static void chppWwanClientNotifyReset(void *clientContext) { false /* clearOnly */); if (wwanClientContext->client.openState != CHPP_OPEN_STATE_OPENED && - wwanClientContext->client.openState != CHPP_OPEN_STATE_PSEUDO_OPEN) { + !wwanClientContext->client.pseudoOpen) { CHPP_LOGW("WWAN client reset but wasn't open"); } else { CHPP_LOGI("WWAN client reopening from state=%" PRIu8, @@ -251,7 +251,7 @@ static void chppWwanClientNotifyReset(void *clientContext) { chppClientSendOpenRequest(&wwanClientContext->client, &wwanClientContext->rRState[CHPP_WWAN_OPEN], CHPP_WWAN_OPEN, - /*reopen=*/true); + /*blocking=*/false); } } @@ -264,12 +264,12 @@ static void chppWwanClientNotifyMatch(void *clientContext) { struct ChppWwanClientState *wwanClientContext = (struct ChppWwanClientState *)clientContext; - if (wwanClientContext->client.openState == CHPP_OPEN_STATE_PSEUDO_OPEN) { - CHPP_LOGD("Previously pseudo-open WWAN client reopening"); + if (wwanClientContext->client.pseudoOpen) { + CHPP_LOGD("Pseudo-open WWAN client opening"); chppClientSendOpenRequest(&wwanClientContext->client, &wwanClientContext->rRState[CHPP_WWAN_OPEN], CHPP_WWAN_OPEN, - /*reopen=*/true); + /*blocking=*/false); } } @@ -303,10 +303,7 @@ static void chppWwanGetCapabilitiesResult( struct ChppWwanClientState *clientContext, uint8_t *buf, size_t len) { if (len < sizeof(struct ChppWwanGetCapabilitiesResponse)) { struct ChppAppHeader *rxHeader = (struct ChppAppHeader *)buf; - CHPP_LOGE("GetCapabilities failed at service err=%" PRIu8, rxHeader->error); - if (rxHeader->error == CHPP_APP_ERROR_NONE) { - CHPP_LOGE("Missing err"); - } + CHPP_LOGE("GetCapabilities resp. too short. err=%" PRIu8, rxHeader->error); } else { struct ChppWwanGetCapabilitiesParameters *result = @@ -346,10 +343,9 @@ static void chppWwanGetCellInfoAsyncResult( if (len == sizeof(struct ChppAppHeader)) { // Short response length indicates an error - CHPP_LOGE("GetCellInfo failed at service err=%" PRIu8, rxHeader->error); + CHPP_LOGE("GetCellInfo resp. too short. err=%" PRIu8, rxHeader->error); if (rxHeader->error == CHPP_APP_ERROR_NONE) { - CHPP_LOGE("Missing err"); errorCode = CHPP_APP_ERROR_INVALID_LENGTH; } else { errorCode = chppAppErrorToChreError(rxHeader->error); @@ -423,7 +419,7 @@ static bool chppWwanClientOpen(const struct chrePalSystemApi *systemApi, result = chppClientSendOpenRequest( &gWwanClientContext.client, &gWwanClientContext.rRState[CHPP_WWAN_OPEN], CHPP_WWAN_OPEN, - /*reopen=*/false); + /*blocking=*/true); } #ifdef CHPP_WWAN_CLIENT_OPEN_ALWAYS_SUCCESS diff --git a/chpp/include/chpp/app.h b/chpp/include/chpp/app.h index 163da5a2..35694bfc 100644 --- a/chpp/include/chpp/app.h +++ b/chpp/include/chpp/app.h @@ -157,10 +157,9 @@ enum ChppAppErrorCode { */ enum ChppOpenState { CHPP_OPEN_STATE_CLOSED = 0, // Closed - CHPP_OPEN_STATE_PSEUDO_OPEN = 1, // Closed but open returns success - CHPP_OPEN_STATE_OPENING = 2, // Enables the open request to pass - CHPP_OPEN_STATE_WAITING_TO_OPEN = 3, // Waiting for open response - CHPP_OPEN_STATE_OPENED = 4, // Opened + CHPP_OPEN_STATE_OPENING = 1, // Enables the open request to pass + CHPP_OPEN_STATE_WAITING_TO_OPEN = 2, // Waiting for open response + CHPP_OPEN_STATE_OPENED = 3, // Opened }; /** diff --git a/chpp/include/chpp/clients.h b/chpp/include/chpp/clients.h index 62ad045d..bf757fa9 100644 --- a/chpp/include/chpp/clients.h +++ b/chpp/include/chpp/clients.h @@ -76,6 +76,7 @@ struct ChppClientState { uint8_t transaction; // Next Transaction ID to be used uint8_t openState; // As defined in enum ChppOpenState + bool pseudoOpen : 1; // Client to be opened upon a reset bool initialized : 1; // Is initialized bool everInitialized : 1; // Synchronization primitives initialized @@ -336,22 +337,21 @@ bool chppSendTimestampedRequestAndWaitTimeout( void chppClientPseudoOpen(struct ChppClientState *clientState); /** - * Sends a client request for the open command. Setting reopen to true indicates - * that the service is being reopened. - * - * The command will be sent non-blocking if reopening after a reset, and - * blocking otherwise. + * Sends a client request for the open command in a blocking or non-blocking + * manner. + * A non-blocking open is used to for reopening a service after a reset or for + * opening a pseudo-open service. * * @param clientState State variable of the client. * @param openRRState Request/response state for the open command. * @param openCommand Open command to be sent. - * @param reopen Indicates that this is a reopen (vs. initial open) request. + * @param blocking Indicates a blocking (vs. non-blocking) open request. * * @return Indicates success or failure. */ bool chppClientSendOpenRequest(struct ChppClientState *clientState, struct ChppRequestResponseState *openRRState, - uint16_t openCommand, bool reopen); + uint16_t openCommand, bool blocking); /** * Processes a service response for the open command. diff --git a/chpp/transport.c b/chpp/transport.c index 4500de05..7c4823f9 100644 --- a/chpp/transport.c +++ b/chpp/transport.c @@ -529,6 +529,11 @@ static void chppProcessResetAck(struct ChppTransportState *context) { #else chppEnqueueTxPacket(context, CHPP_TRANSPORT_ERROR_NONE); #endif + + // Inform the App Layer that a reset has completed + chppMutexUnlock(&context->mutex); + chppAppProcessReset(context->appContext); + chppMutexLock(&context->mutex); } /** @@ -930,7 +935,7 @@ static void chppClearTxDatagramQueue(struct ChppTransportState *context) { static void chppTransportDoWork(struct ChppTransportState *context) { bool havePacketForLinkLayer = false; struct ChppTransportHeader *txHeader; - struct ChppAppHeader *timeoutResponse; + struct ChppAppHeader *timeoutResponse = NULL; // Note: For a future ACK window >1, there needs to be a loop outside the lock chppMutexLock(&context->mutex); @@ -1200,8 +1205,10 @@ static void chppReset(struct ChppTransportState *transportContext, chppMutexUnlock(&transportContext->mutex); chppTransportSendReset(transportContext, resetType, error); - // Inform the App Layer - chppAppProcessReset(appContext); + // Inform the App Layer that a reset has completed + if (resetType == CHPP_TRANSPORT_ATTR_RESET_ACK) { + chppAppProcessReset(appContext); + } // else reset is sent out. Rx of reset-ack will indicate completion. } /** |