]> granicus.if.org Git - esp-idf/commitdiff
protocomm : version endpoint behavior simplified
authorAnurag Kar <anurag.kar@espressif.com>
Fri, 8 Feb 2019 06:36:23 +0000 (12:06 +0530)
committerbot <bot@espressif.com>
Mon, 18 Feb 2019 08:18:44 +0000 (08:18 +0000)
List of changes:
* Version endpoint now sends the set version string instead of verifying the incoming version string. This simplifies fetching version info from the provisioning application.
* esp_prov script updated to expect version string as response.

components/protocomm/src/common/protocomm.c
tools/esp_prov/esp_prov.py

index 94ebc8e81ad9d779dc6f7af49071d3be146933b2..ff4901a0ba3cef90e498547f77bd26aaf87395fb 100644 (file)
@@ -305,40 +305,22 @@ static int protocomm_version_handler(uint32_t session_id,
                                      uint8_t **outbuf, ssize_t *outlen,
                                      void *priv_data)
 {
-    const char *resp_match = "SUCCESS";
-    const char *resp_fail  = "FAIL";
-    bool match = false;
-    char *version = strndup((const char *)inbuf, inlen);
     protocomm_t *pc = (protocomm_t *) priv_data;
-    *outbuf = NULL;
-    *outlen = 0;
-
-    if ((pc->ver != NULL) && (version != NULL)) {
-        ESP_LOGV(TAG, "Protocol version of device : %s", pc->ver);
-        ESP_LOGV(TAG, "Protocol version of client : %s", version);
-        if (strcmp(pc->ver, version) == 0) {
-            match = true;
-        }
-    } else if ((pc->ver == NULL) && (version == NULL)) {
-        match = true;
-    }
-    free(version);
-
-    if (!match) {
-        ESP_LOGE(TAG, "Protocol version mismatch");
+    if (!pc->ver) {
+        *outlen = 0;
+        *outbuf = NULL;
+        return ESP_OK;
     }
 
-    const char *result_msg = match ? resp_match : resp_fail;
-
     /* Output is a non null terminated string with length specified */
-    *outlen = strlen(result_msg);
-    *outbuf = malloc(strlen(result_msg));
+    *outlen = strlen(pc->ver);
+    *outbuf = malloc(*outlen);
     if (outbuf == NULL) {
-        ESP_LOGE(TAG, "Failed to allocate memory for version check response");
+        ESP_LOGE(TAG, "Failed to allocate memory for version response");
         return ESP_ERR_NO_MEM;
     }
 
-    memcpy(*outbuf, result_msg, *outlen);
+    memcpy(*outbuf, pc->ver, *outlen);
     return ESP_OK;
 }
 
index 10ad6713405a69e9f9bbd34b433d500f8327e505..0ea172da538e3c07eeb76ed0de1fa897f9a1af53 100644 (file)
@@ -59,7 +59,7 @@ def get_transport(sel_transport, softap_endpoint=None, ble_devname=None):
 def version_match(tp, protover):
     try:
         response = tp.send_data('proto-ver', protover)
-        if response != "SUCCESS":
+        if response != protover:
             return False
         return True
     except RuntimeError as e: