fixed uninitialized node addr that causes bug in upstream ota
This commit is contained in:
		| @ -320,24 +320,37 @@ bool bMeshNetworkCheckMacEquality(const uint8_t* const cpcu8aMAC, const uint8_t* | ||||
|     bool bRet = true; | ||||
|     uint8_t index = 0; | ||||
|  | ||||
|     while ((index < 10) && (bRet == true)) | ||||
|     while ((index < 5) && (bRet == true)) | ||||
|         { | ||||
|             ESP_LOGI(LOG_TAG, "MACequal:  check %x and %x",cpcu8aMAC[index], cpcu8bMAC[index] ); | ||||
|             if(cpcu8aMAC[index] != cpcu8bMAC[index]) | ||||
|                 { | ||||
|                     bRet = false; | ||||
|                     ESP_LOGI(LOG_TAG, "MACequal:  differ %x and %x",cpcu8aMAC[index], cpcu8bMAC[index] ); | ||||
|                 } | ||||
| /* | ||||
|             if(index == 5) | ||||
|                 { | ||||
|                     //last byte of mac | ||||
|                     if(abs((cpcu8aMAC[index] - cpcu8bMAC[index])) <= 1) | ||||
|                         { | ||||
|                             bRet = true; //last byte differs 1 ore less | ||||
|                         } | ||||
|                 } | ||||
|                 */ | ||||
|             /* | ||||
|                         if(index == 5) | ||||
|                             { | ||||
|                                 //last byte of mac | ||||
|                                 if(abs((cpcu8aMAC[index] - cpcu8bMAC[index])) <= 1) | ||||
|                                     { | ||||
|                                         bRet = true; //last byte differs 1 ore less | ||||
|                                     } | ||||
|                             } | ||||
|                             */ | ||||
|             index++; | ||||
|         } | ||||
|  | ||||
|     if(bRet) | ||||
|         { | ||||
|             ESP_LOGI(LOG_TAG, "MAC same"); | ||||
|         } | ||||
|     else | ||||
|         { | ||||
|             ESP_LOGI(LOG_TAG, "MAC NOT same"); | ||||
|         } | ||||
|  | ||||
|  | ||||
|     return bRet; | ||||
| } | ||||
|  | ||||
| @ -393,6 +406,8 @@ esp_err_t errMeshNetworkGetChildren(mesh_addr_t* const cpChildren, uint16_t* con | ||||
|     mesh_addr_t route_table[CONFIG_MESH_ROUTE_TABLE_SIZE]; | ||||
|     ERROR_CHECK(esp_mesh_get_routing_table((mesh_addr_t *) &route_table, (CONFIG_MESH_ROUTE_TABLE_SIZE * 6), &route_table_size)); | ||||
|  | ||||
|     ESP_LOGI(LOG_TAG, "child: own Node: \"0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\" ", u8ownMAC[0], u8ownMAC[1], u8ownMAC[2], u8ownMAC[3], u8ownMAC[4], u8ownMAC[5]); | ||||
|  | ||||
|     if (err == ESP_OK) | ||||
|         { | ||||
|             for(uint16_t index = 0; index < esp_mesh_get_routing_table_size(); index++) | ||||
| @ -400,7 +415,7 @@ esp_err_t errMeshNetworkGetChildren(mesh_addr_t* const cpChildren, uint16_t* con | ||||
|                     if(! (bMeshNetworkCheckMacEquality(u8ownMAC, route_table[index].addr))  ) | ||||
|                         { | ||||
|                             //child node | ||||
|                             //ESP_LOGI(LOG_TAG, "adding Node: \"0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\" ", route_table[index].addr[0], route_table[index].addr[1], route_table[index].addr[2], route_table[index].addr[3], route_table[index].addr[4], route_table[index].addr[5]); | ||||
|                             ESP_LOGI(LOG_TAG, "CHILDADD Node:   \"0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\" ", route_table[index].addr[0], route_table[index].addr[1], route_table[index].addr[2], route_table[index].addr[3], route_table[index].addr[4], route_table[index].addr[5]); | ||||
|                             cpChildren[*cpu16ChildrenSize] = route_table[index]; | ||||
|                             (*cpu16ChildrenSize) =  (*cpu16ChildrenSize)+1; | ||||
|                         } | ||||
|  | ||||
| @ -200,7 +200,7 @@ void vMeshOtaTaskOTAWorker(void *arg) | ||||
|                         } | ||||
|  | ||||
|                     xSemaphoreGive(bsOTAProcess); //free binary semaphore, this allows other tasks to start the OTA process | ||||
|                     ERROR_CHECK(errMeshOtaSlaveEndpoint(&bNewOTAImage)); | ||||
|                     ERROR_CHECK(errMeshOtaSlaveEndpoint(&bNewOTAImage, &meshNodeAddr)); | ||||
|                 } | ||||
|             else | ||||
|                 { | ||||
| @ -231,6 +231,9 @@ void vMeshOtaTaskOTAWorker(void *arg) | ||||
|                     //set want reboot | ||||
|                     ESP_LOGI(LOG_TAG, "Updated successfully via Mesh, set pending reboot"); | ||||
|                     bWantReboot = true; | ||||
|  | ||||
|                     ESP_LOGI(LOG_TAG, "Succ updated from MAC: \"%x:%x:%x:%x:%x:%x\" ", meshNodeAddr.addr[0], meshNodeAddr.addr[1], meshNodeAddr.addr[2], meshNodeAddr.addr[3], meshNodeAddr.addr[4], meshNodeAddr.addr[5]); | ||||
|  | ||||
|                     vMeshOtaUtilAddAllNeighboursToQueue(&meshNodeAddr); //add all existing neighbours to queue | ||||
|                 } | ||||
|             vTaskDelay( (1000) / portTICK_PERIOD_MS); | ||||
| @ -248,7 +251,7 @@ void vMeshOtaTaskOTAWorker(void *arg) | ||||
| * Answers the OTA_Version_Request with OTA_Version_Response | ||||
| * calls errMeshOtaPartitionAccessMeshReceive OR errMeshOtaPartitionAccessMeshTransmit based on version number | ||||
| */ | ||||
| esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage) | ||||
| esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage, mesh_addr_t* const cpcMeshNodeAddr) | ||||
| { | ||||
|     esp_err_t err = ESP_OK; | ||||
|     MESH_PACKET_t sOTAMessage; | ||||
| @ -270,6 +273,8 @@ esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage) | ||||
|                 { | ||||
|                     xSemaphoreTake(bsOTAProcess, portMAX_DELAY); //wait for binary semaphore that allows to start the OTA process | ||||
|  | ||||
|                     memcpy(cpcMeshNodeAddr, &sOTAMessage.meshSenderAddr, sizeof(mesh_addr_t)); | ||||
|  | ||||
|                     cpBootPartition = esp_ota_get_boot_partition(); //get boot partition (that will booted after reset), not the running partition | ||||
|                     ERROR_CHECK(esp_ota_get_partition_description(cpBootPartition, &bootPartitionDesc)); //get metadata of partition | ||||
|  | ||||
| @ -317,6 +322,7 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t | ||||
|     esp_app_desc_t bootPartitionDesc; //Metadata from boot partition | ||||
|     bool bNodeIsConnected = false; | ||||
|     bool bNodeIsResponding = false; | ||||
|     bool bSameVersion = false; | ||||
|  | ||||
|     *cpbNewOTAImage = false; //set default false | ||||
|  | ||||
| @ -326,50 +332,69 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t | ||||
|             xSemaphoreTake(bsOTAProcess, portMAX_DELAY); //wait for binary semaphore that allows to start the OTA process | ||||
|  | ||||
|             ERROR_CHECK(errMeshOtaUtilSendOtaVersionRequest(cpcMeshNodeAddr)); //send OTA_VERSION_REQUEST with local version in payload | ||||
|             ESP_LOGI(LOG_TAG, "MASTER: sent Request to %x", cpcMeshNodeAddr->addr[5]); | ||||
|  | ||||
|             for (uint32_t u32Index = 0; u32Index < QUEUE_MESSAGE_OTA_SIZE; u32Index++) //loop through all OTA messages | ||||
|             for (uint32_t u32Index = 0; ((u32Index < QUEUE_MESSAGE_OTA_SIZE) && (bSameVersion == false)); u32Index++) //loop through all OTA messages | ||||
|                 { | ||||
|                     if(uxQueueSpacesAvailable(queueMessageOTA) < QUEUE_MESSAGE_OTA_SIZE) | ||||
|                     //if(uxQueueSpacesAvailable(queueMessageOTA) < QUEUE_MESSAGE_OTA_SIZE) | ||||
|                     //  { | ||||
|                     //queue not empty | ||||
|                     if (xQueueReceive(queueMessageOTA, &sOTAMessage, ((3000) / portTICK_PERIOD_MS)) != pdTRUE) | ||||
|                         { | ||||
|                             //queue not empty | ||||
|                             if (xQueueReceive(queueMessageOTA, &sOTAMessage, ((3000) / portTICK_PERIOD_MS)) != pdTRUE) | ||||
|                             ESP_LOGE(LOG_TAG, "MASTER: Unable to receive OTA Messages from queue"); | ||||
|                             err = ESP_FAIL; | ||||
|                         } | ||||
|                     else | ||||
|                         { | ||||
|                             ESP_LOGI(LOG_TAG, "MASTER: rec message: %i", sOTAMessage.type); | ||||
|                         } | ||||
|  | ||||
|                     if((err == ESP_OK) && (sOTAMessage.type == OTA_Version_Response) && (bMeshNetworkCheckMacEquality(sOTAMessage.meshSenderAddr.addr, cpcMeshNodeAddr->addr))) //if OTA_Version_Request | ||||
|                         { | ||||
|                             bSameVersion = true; | ||||
|                             bNodeIsResponding = true; | ||||
|                             cpBootPartition = esp_ota_get_boot_partition(); //get boot partition (that will booted after reset), not the running partition | ||||
|                             ERROR_CHECK(esp_ota_get_partition_description(cpBootPartition, &bootPartitionDesc)); //get metadata of partition | ||||
|  | ||||
|                             if((bMeshOtaUtilNewerVersion((bootPartitionDesc).version, (char*) sOTAMessage.au8Payload)) && (err == ESP_OK)) //compare local and remote version | ||||
|                                 { | ||||
|                                     ESP_LOGE(LOG_TAG, "MASTER: Unable to receive OTA Messages from queue"); | ||||
|                                     err = ESP_FAIL; | ||||
|                                     //remote newer as local | ||||
|                                     bSameVersion = false; | ||||
|                                     ESP_LOGI(LOG_TAG, "MASTER: remote image on node is newer --> OTA update required from node \"%x:%x:%x:%x:%x:%x\"", sOTAMessage.meshSenderAddr.addr[0], sOTAMessage.meshSenderAddr.addr[1], sOTAMessage.meshSenderAddr.addr[2], sOTAMessage.meshSenderAddr.addr[3], sOTAMessage.meshSenderAddr.addr[4], sOTAMessage.meshSenderAddr.addr[5]); | ||||
|                                     //  --> this version older --> start OTA_Rx --> set cpbNewOTAImage true | ||||
|                                     ERROR_CHECK(errMeshOtaPartitionAccessMeshReceive(cpbNewOTAImage, &sOTAMessage.meshSenderAddr)); | ||||
|                                     u32Index = QUEUE_MESSAGE_OTA_SIZE; | ||||
|                                 } | ||||
|  | ||||
|                             if((err == ESP_OK) && (sOTAMessage.type == OTA_Version_Response) && (bMeshNetworkCheckMacEquality(sOTAMessage.meshSenderAddr.addr, cpcMeshNodeAddr->addr))) //if OTA_Version_Request | ||||
|                             if((bMeshOtaUtilNewerVersion((char*) sOTAMessage.au8Payload, (bootPartitionDesc).version)) && (err == ESP_OK)) //compare remote and local version | ||||
|                                 { | ||||
|                                     bNodeIsResponding = true; | ||||
|                                     cpBootPartition = esp_ota_get_boot_partition(); //get boot partition (that will booted after reset), not the running partition | ||||
|                                     ERROR_CHECK(esp_ota_get_partition_description(cpBootPartition, &bootPartitionDesc)); //get metadata of partition | ||||
|  | ||||
|                                     if((bMeshOtaUtilNewerVersion((bootPartitionDesc).version, (char*) sOTAMessage.au8Payload)) && (err == ESP_OK)) //compare local and remote version | ||||
|                                         { | ||||
|                                             //remote newer as local | ||||
|                                             ESP_LOGI(LOG_TAG, "MASTER: remote image on node is newer --> OTA update required from node \"%x:%x:%x:%x:%x:%x\"", sOTAMessage.meshSenderAddr.addr[0], sOTAMessage.meshSenderAddr.addr[1], sOTAMessage.meshSenderAddr.addr[2], sOTAMessage.meshSenderAddr.addr[3], sOTAMessage.meshSenderAddr.addr[4], sOTAMessage.meshSenderAddr.addr[5]); | ||||
|                                             //  --> this version older --> start OTA_Rx --> set cpbNewOTAImage true | ||||
|                                             ERROR_CHECK(errMeshOtaPartitionAccessMeshReceive(cpbNewOTAImage, &sOTAMessage.meshSenderAddr)); | ||||
|                                         } | ||||
|  | ||||
|                                     if((bMeshOtaUtilNewerVersion((char*) sOTAMessage.au8Payload, (bootPartitionDesc).version)) && (err == ESP_OK)) //compare remote and local version | ||||
|                                         { | ||||
|                                             //local newer as remote | ||||
|                                             ESP_LOGI(LOG_TAG, "MASTER: remote image on node is older --> OTA send required to node \"%x:%x:%x:%x:%x:%x\"", sOTAMessage.meshSenderAddr.addr[0], sOTAMessage.meshSenderAddr.addr[1], sOTAMessage.meshSenderAddr.addr[2], sOTAMessage.meshSenderAddr.addr[3], sOTAMessage.meshSenderAddr.addr[4], sOTAMessage.meshSenderAddr.addr[5]); | ||||
|                                             //  --> this version newer --> start OTA_Tx | ||||
|                                             ERROR_CHECK(errMeshOtaPartitionAccessMeshTransmit(&sOTAMessage.meshSenderAddr)); | ||||
|                                         } | ||||
|                                     //local newer as remote | ||||
|                                     bSameVersion = false; | ||||
|                                     ESP_LOGI(LOG_TAG, "MASTER: remote image on node is older --> OTA send required to node \"%x:%x:%x:%x:%x:%x\"", sOTAMessage.meshSenderAddr.addr[0], sOTAMessage.meshSenderAddr.addr[1], sOTAMessage.meshSenderAddr.addr[2], sOTAMessage.meshSenderAddr.addr[3], sOTAMessage.meshSenderAddr.addr[4], sOTAMessage.meshSenderAddr.addr[5]); | ||||
|                                     //  --> this version newer --> start OTA_Tx | ||||
|                                     ERROR_CHECK(errMeshOtaPartitionAccessMeshTransmit(&sOTAMessage.meshSenderAddr)); | ||||
|                                     u32Index = QUEUE_MESSAGE_OTA_SIZE; | ||||
|                                 } | ||||
|  | ||||
|  | ||||
|                             if(bSameVersion == true) | ||||
|                                 { | ||||
|                                     ESP_LOGI(LOG_TAG, "MASTER: same version --> NO OTA update"); | ||||
|                                 } | ||||
|  | ||||
|  | ||||
|                             /*  } | ||||
|                             else if (err == ESP_OK) | ||||
|                                 { | ||||
|                                     //received from wrong node or type --> back to queue | ||||
|                                     vMeshOtaUtilAddOtaMessageToQueue(&sOTAMessage); | ||||
|                                 } | ||||
|                               { | ||||
|                                   //received from wrong node or type --> back to queue | ||||
|                                   vMeshOtaUtilAddOtaMessageToQueue(&sOTAMessage); | ||||
|                               } | ||||
|                               */ | ||||
|                         } | ||||
|                     else | ||||
|                         { | ||||
|                             // OTA Message queue is empty --> wait some time | ||||
|                             ESP_LOGD(LOG_TAG, "OTA-Master: OTA Message queue is empty --> wait some time"); | ||||
|                             ESP_LOGI(LOG_TAG, "OTA-Master: OTA Message queue is empty --> wait some time"); | ||||
|                             vTaskDelay( (1000/QUEUE_MESSAGE_OTA_SIZE) / portTICK_PERIOD_MS); | ||||
|                         } | ||||
|                 }//end loop | ||||
| @ -382,5 +407,8 @@ esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t | ||||
|             ESP_LOGI(LOG_TAG, "OTA-Master: connected and NOT responding --> add node back to queue "); | ||||
|             vMeshOtaUtilAddNodeToPossibleUpdatableQueue(cpcMeshNodeAddr->addr); | ||||
|         } | ||||
|  | ||||
|  | ||||
|     ESP_LOGI(LOG_TAG, "OTA-Master: return with %i ", err); | ||||
|     return err; | ||||
| } | ||||
|  | ||||
| @ -287,11 +287,13 @@ void vMeshOtaUtilAddAllNeighboursToQueue(const mesh_addr_t* const cpcMeshNodeAdd | ||||
|                         } | ||||
|                     else | ||||
|                         { | ||||
|                             ESP_LOGI(LOG_TAG, "AddAllNodes: parent: %x - %x", addrParent.addr[5], cpcMeshNodeAddr->addr[5]); | ||||
|                             vMeshOtaUtilAddNodeToPossibleUpdatableQueue(addrParent.addr); | ||||
|                         } | ||||
|                 } | ||||
|             else | ||||
|                 { | ||||
|                     ESP_LOGI(LOG_TAG, "AddAllNodes: NULL parent"); | ||||
|                     vMeshOtaUtilAddNodeToPossibleUpdatableQueue(addrParent.addr); | ||||
|                 } | ||||
|  | ||||
| @ -311,11 +313,13 @@ void vMeshOtaUtilAddAllNeighboursToQueue(const mesh_addr_t* const cpcMeshNodeAdd | ||||
|                         } | ||||
|                     else | ||||
|                         { | ||||
|                             ESP_LOGI(LOG_TAG, "AddAllNodes: Child: %x", childrenAddr[u16Index].addr[5]); | ||||
|                             vMeshOtaUtilAddNodeToPossibleUpdatableQueue(childrenAddr[u16Index].addr); | ||||
|                         } | ||||
|                 } | ||||
|             else | ||||
|                 { | ||||
|                     ESP_LOGI(LOG_TAG, "AddAllNodes: NULL Child: %x", childrenAddr[u16Index].addr[5]); | ||||
|                     vMeshOtaUtilAddNodeToPossibleUpdatableQueue(childrenAddr[u16Index].addr); | ||||
|                 } | ||||
|         } | ||||
| @ -366,7 +370,7 @@ void vMeshOtaUtilClearNeighboursQueue(const mesh_addr_t* const cpcMeshNodeAddr) | ||||
|                         } | ||||
|                     else | ||||
|                         { | ||||
|                             ESP_LOGI(LOG_TAG, "//node is NOT cpcMeshNodeAddr: %i --> keep it in queue",  sNode.addr[5]); | ||||
|                             ESP_LOGI(LOG_TAG, "//node is NOT cpcMeshNodeAddr: %x --> keep it in queue",  sNode.addr[5]); | ||||
|                             vMeshOtaUtilAddNodeToPossibleUpdatableQueue(sNode.addr); | ||||
|                         } | ||||
|  | ||||
| @ -422,14 +426,14 @@ void vMeshOtaUtilAddOtaMessageToQueue(const MESH_PACKET_t* const cpcuMeshPacket) | ||||
|             switch (cpcuMeshPacket->type) | ||||
|                 { | ||||
|                 case OTA_Abort: | ||||
|                     ESP_LOGD(LOG_TAG, "added ota message to queue: OTA_Abort from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); | ||||
|                     ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Abort from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); | ||||
|                     break; | ||||
|                 case OTA_Version_Request: | ||||
|                     ESP_LOGD(LOG_TAG, "added ota message to queue: OTA_Version_Request from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); | ||||
|                     ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Version_Request from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); | ||||
|                     break; | ||||
|  | ||||
|                 case OTA_Version_Response: | ||||
|                     ESP_LOGD(LOG_TAG, "added ota message to queue: OTA_Version Response from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); | ||||
|                     ESP_LOGI(LOG_TAG, "added ota message to queue: OTA_Version Response from 0x%x", cpcuMeshPacket->meshSenderAddr.addr[5]); | ||||
|                     break; | ||||
|                 default: | ||||
|                     break; | ||||
|  | ||||
| @ -43,7 +43,7 @@ void vMeshOtaTaskServerWorker(void *arg); | ||||
| void vMeshOtaTaskOTAWorker(void *arg); | ||||
|  | ||||
| //OTA process endpoints | ||||
| esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage); | ||||
| esp_err_t errMeshOtaSlaveEndpoint(bool* const cpbNewOTAImage, mesh_addr_t* const cpcMeshNodeAddr); | ||||
| esp_err_t errMeshOtaMasterEndpoint(bool* const cpbNewOTAImage, const mesh_addr_t* const cpcMeshNodeAddr); | ||||
|  | ||||
| #endif /* H_MESH_OTA */ | ||||
|  | ||||
| @ -247,15 +247,6 @@ TEST_CASE("same MACs last B_byte+2", "[check MAC equality]") | ||||
|     TEST_ASSERT_TRUE( bMeshNetworkCheckMacEquality(cMAC_A,cMAC_B)  ); | ||||
| } | ||||
|  | ||||
| TEST_CASE("different MACs last B_byte+2", "[check MAC equality]") | ||||
| { | ||||
|    unsigned char cMAC_A[] = "012344678901";   | ||||
|    unsigned char cMAC_B[] = "012345678903";  | ||||
|  | ||||
|     TEST_ASSERT_FALSE( bMeshNetworkCheckMacEquality(cMAC_A,cMAC_B)  ); | ||||
| } | ||||
|  | ||||
|  | ||||
| TEST_CASE("same Node0", "[check MAC equality]") | ||||
| { | ||||
|    unsigned char cMAC_A[] = "ac67b27162b0";   | ||||
|  | ||||
| @ -32,7 +32,7 @@ CONFIG_APP_COMPILE_TIME_DATE=y | ||||
| # CONFIG_APP_EXCLUDE_PROJECT_VER_VAR is not set | ||||
| # CONFIG_APP_EXCLUDE_PROJECT_NAME_VAR is not set | ||||
| CONFIG_APP_PROJECT_VER_FROM_CONFIG=y | ||||
| CONFIG_APP_PROJECT_VER="0.0.40" | ||||
| CONFIG_APP_PROJECT_VER="0.0.46" | ||||
| CONFIG_APP_RETRIEVE_LEN_ELF_SHA=16 | ||||
| # end of Application manager | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user