From 733efd364cca5f160e182c9cbed3e5a313547e82 Mon Sep 17 00:00:00 2001 From: Ossama Othman Date: Mon, 18 May 2015 17:00:55 -0700 Subject: [PATCH] Fixed CAGetNetworkInformation() aggregation problem. CAGetNetworkInformation() was not displaying information of adapters for all transports. Fixed CALocalConnectivity_t* array aggregation in underlying CAGetNetworkInfo() function so that interface information from all transports is correctly combined into the array passed back to the caller. Change-Id: I699ceeb3e8652acc495037085f88c359e206fa7d Signed-off-by: Ossama Othman Reviewed-on: https://gerrit.iotivity.org/gerrit/1028 Tested-by: jenkins-iotivity Reviewed-by: Abhishek Sharma Reviewed-by: Erich Keane --- .../csdk/connectivity/src/cainterfacecontroller.c | 75 ++++++++++------------ 1 file changed, 35 insertions(+), 40 deletions(-) diff --git a/resource/csdk/connectivity/src/cainterfacecontroller.c b/resource/csdk/connectivity/src/cainterfacecontroller.c index 18a8257..2abc0a8 100644 --- a/resource/csdk/connectivity/src/cainterfacecontroller.c +++ b/resource/csdk/connectivity/src/cainterfacecontroller.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include "cainterfacecontroller.h" #include "caipadapter.h" @@ -207,39 +207,42 @@ void CAStopAdapter(CATransportType_t transportType) CAResult_t CAGetNetworkInfo(CALocalConnectivity_t **info, uint32_t *size) { + if (info == NULL || size == NULL) + { + return CA_STATUS_INVALID_PARAM; + } + CALocalConnectivity_t *tempInfo[CA_TRANSPORT_TYPE_NUM] = { 0 }; uint32_t tempSize[CA_TRANSPORT_TYPE_NUM] = { 0 }; - // #1. get information each adapter - uint8_t index = 0; CAResult_t res = CA_STATUS_FAILED; - for (index = 0; index < CA_TRANSPORT_TYPE_NUM; index++) + uint32_t resSize = 0; + for (int index = 0; index < CA_TRANSPORT_TYPE_NUM; index++) { if (g_adapterHandler[index].GetnetInfo != NULL) { - res = g_adapterHandler[index].GetnetInfo(&tempInfo[index], &tempSize[index]); + // #1. get information for each adapter + res = g_adapterHandler[index].GetnetInfo(&tempInfo[index], + &tempSize[index]); - OIC_LOG_V(DEBUG, TAG, "%d adapter network info size is %d res:%d", index, - tempSize[index], res); - } - } + // #2. total size + if (res == CA_STATUS_OK) + { + resSize += tempSize[index]; + } - uint32_t resSize = 0; - for (index = 0; index < CA_TRANSPORT_TYPE_NUM; index++) - { - // check information - if (tempInfo[index] == NULL || tempSize[index] <= 0) - { - continue; + OIC_LOG_V(DEBUG, + TAG, + "%d adapter network info size is %" PRIu32 " res:%d", + index, + tempSize[index], + res); } - - // #2. total size - resSize += tempSize[index]; } OIC_LOG_V(DEBUG, TAG, "network info total size is %d!", resSize); - if (resSize <= 0) + if (resSize == 0) { if (res == CA_ADAPTER_NOT_ENABLED || res == CA_NOT_SUPPORTED) { @@ -251,46 +254,39 @@ CAResult_t CAGetNetworkInfo(CALocalConnectivity_t **info, uint32_t *size) // #3. add data into result // memory allocation - CALocalConnectivity_t *resInfo = (CALocalConnectivity_t *) OICCalloc( - resSize, sizeof(CALocalConnectivity_t)); + CALocalConnectivity_t * resInfo = OICCalloc(resSize, sizeof(*resInfo)); CA_MEMORY_ALLOC_CHECK(resInfo); - uint8_t pos = 0; - for (index = 0; index < CA_TRANSPORT_TYPE_NUM; index++) + // #4. save data + *info = resInfo; + *size = resSize; + + for (int index = 0; index < CA_TRANSPORT_TYPE_NUM; index++) { // check information - if (tempInfo[index] == NULL || tempSize[index] <= 0) + if (tempSize[index] == 0) { continue; } - memcpy(resInfo + pos, tempInfo[index], sizeof(CALocalConnectivity_t) * tempSize[index]); + memcpy(resInfo, + tempInfo[index], + sizeof(*resInfo) * tempSize[index]); - pos += tempSize[index]; + resInfo += tempSize[index]; // free adapter data OICFree(tempInfo[index]); tempInfo[index] = NULL; } - // #5. save data - if ( info != NULL ) - { - *info = resInfo; - } - - if (size) - { - *size = resSize; - } - OIC_LOG(DEBUG, TAG, "each network info save success!"); return CA_STATUS_OK; // memory error label. memory_error_exit: - for (index = 0; index < CA_TRANSPORT_TYPE_NUM; index++) + for (int index = 0; index < CA_TRANSPORT_TYPE_NUM; index++) { OICFree(tempInfo[index]); @@ -490,4 +486,3 @@ void CATerminateAdapters() } } } - -- 2.7.4