Commit 733efd36 authored by Ossama Othman's avatar Ossama Othman Committed by Erich Keane

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: default avatarOssama Othman <ossama.othman@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1028Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarAbhishek Sharma <ce.abhishek@samsung.com>
Reviewed-by: default avatarErich Keane <erich.keane@intel.com>
parent c1f588fe
......@@ -21,7 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <inttypes.h>
#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]);
OIC_LOG_V(DEBUG, TAG, "%d adapter network info size is %d res:%d", index,
tempSize[index], res);
}
}
// #1. get information for each adapter
res = g_adapterHandler[index].GetnetInfo(&tempInfo[index],
&tempSize[index]);
uint32_t resSize = 0;
for (index = 0; index < CA_TRANSPORT_TYPE_NUM; index++)
{
// check information
if (tempInfo[index] == NULL || tempSize[index] <= 0)
// #2. total size
if (res == CA_STATUS_OK)
{
continue;
resSize += tempSize[index];
}
// #2. total size
resSize += tempSize[index];
OIC_LOG_V(DEBUG,
TAG,
"%d adapter network info size is %" PRIu32 " res:%d",
index,
tempSize[index],
res);
}
}
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()
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment