Move security identity to CAInfo_t.
Propagate security to OCClientResponse for application.
Change-Id: I535577bedf0ed4f46a97249add56aec6928d2d84
Signed-off-by: John Light <john.j.light@intel.com>
Signed-off-by: Sakthivel Samidurai <sakthivel.samidurai@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2144
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
{
CATransportAdapter_t adapter; // adapter type
CATransportFlags_t flags; // transport modifiers
+ uint16_t port; // for IP
char addr[MAX_ADDR_STR_SIZE_CA]; // address for all
uint32_t interface; // usually zero for default interface
- uint16_t port; // for IP
- CARemoteId_t identity; // endpoint identity
} CAEndpoint_t;
/**
+ * Endpoint information for secure messages
+ */
+typedef struct
+{
+ CAEndpoint_t endpoint; /**< endpoint */
+ CARemoteId_t identity; /**< endpoint identity */
+} CASecureEndpoint_t;
+
+/**
* @enum CAResult_t
* Enums for CA return values
*/
CAPayload_t payload; /**< payload of the request */
size_t payloadSize; /**< size in bytes of the payload */
CAURI_t resourceUri; /**< Resource URI information **/
+ CARemoteId_t identity; /**< endpoint identity */
} CAInfo_t;
/**
*/
typedef struct
{
- int fd;
- uint16_t port;
+ int fd; /**< socket fd */
+ uint16_t port; /**< socket port */
} CASocket_t;
#define HISTORYSIZE (4)
typedef struct
{
- CATransportFlags_t clientFlags;
- CATransportFlags_t serverFlags;
- bool client;
- bool server;
+ int ifindex; /**< network interface index */
+} CAIfItem_t;
+
+typedef struct
+{
+ CATransportFlags_t clientFlags; /**< flag for client */
+ CATransportFlags_t serverFlags; /**< flag for server */
+ bool client; /**< client mode */
+ bool server; /**< server mode */
struct sockets
{
int shutdownFds[2]; /**< shutdown pipe */
int selectTimeout; /**< in seconds */
int maxfd; /**< highest fd (for select) */
- int numInterfaces; /**< number of active interfaces */
bool started; /**< the IP adapter has started */
bool terminate; /**< the IP adapter needs to stop */
bool ipv6enabled; /**< IPv6 enabled by OCInit flags */
bool ipv4enabled; /**< IPv4 enabled by OCInit flags */
bool dualstack; /**< IPv6 and IPv4 enabled */
+
+ struct networkmonitors
+ {
+ CAIfItem_t *ifitems; /**< current network interface index list */
+ int numifitems; /**< number of current network interfaces */
+ } nm;
} ip;
struct calayer
* This will be used during the receive of network requests and response.
* @see SendUnicastData(), SendMulticastData()
*/
-typedef void (*CANetworkPacketReceivedCallback)(const CAEndpoint_t *endPoint,
+typedef void (*CANetworkPacketReceivedCallback)(const CASecureEndpoint_t *sep,
const void *data, uint32_t dataLen);
/**
*/
extern void OCGetDtlsPskCredentials(CADtlsPskCredsBlob_t **credInfo);
-typedef void (*CAPacketReceivedCallback)(const CAEndpoint_t *endpoint,
+typedef void (*CAPacketReceivedCallback)(const CASecureEndpoint_t *sep,
const void *data, uint32_t dataLength);
typedef void (*CAPacketSendCallback)(CAEndpoint_t *endpoint,
* @retval ::CA_STATUS_FAILED Operation failed.
*
*/
-CAResult_t CAAdapterNetDtlsDecrypt(const CAEndpoint_t *endpoint,
+CAResult_t CAAdapterNetDtlsDecrypt(const CASecureEndpoint_t *sep,
uint8_t *data,
uint32_t dataLen);
/**
* Callback to be notified on reception of any data from remote OIC devices.
*
- * @param[in] endpoint network endpoint description.
+ * @param[in] sep network endpoint description.
* @param[in] data Data received from remote OIC device.
* @param[in] dataLength Length of data in bytes.
* @pre Callback must be registered using CAIPSetPacketReceiveCallback().
*/
-typedef void (*CAIPPacketReceivedCallback)(const CAEndpoint_t *endpoint,
+typedef void (*CAIPPacketReceivedCallback)(const CASecureEndpoint_t *sep,
const void *data,
uint32_t dataLength);
*/
static CAGetDTLSCredentialsHandler g_getCredentialsCallback = NULL;
-static CAEndpoint_t *GetPeerInfo(const CAEndpoint_t *peer)
+static CASecureEndpoint_t *GetPeerInfo(const CAEndpoint_t *peer)
{
uint32_t list_index = 0;
uint32_t list_length = 0;
return NULL;
}
- CAEndpoint_t *peerInfo;
+ CASecureEndpoint_t *peerInfo = NULL;
list_length = u_arraylist_length(g_caDtlsContext->peerInfoList);
for (list_index = 0; list_index < list_length; list_index++)
{
- peerInfo = (CAEndpoint_t *)u_arraylist_get(g_caDtlsContext->peerInfoList, list_index);
+ peerInfo = (CASecureEndpoint_t *)u_arraylist_get(g_caDtlsContext->peerInfoList, list_index);
if (NULL == peerInfo)
{
continue;
}
- if((0 == strncmp(peer->addr, peerInfo->addr, MAX_ADDR_STR_SIZE_CA)) &&
- (peer->port == peerInfo->port))
+ if((0 == strncmp(peer->addr, peerInfo->endpoint.addr, MAX_ADDR_STR_SIZE_CA)) &&
+ (peer->port == peerInfo->endpoint.port))
{
return peerInfo;
}
return NULL;
}
-static CAResult_t CAAddIdToPeerInfoList(const char *peerAddr, uint16_t port,
- const unsigned char *id, uint16_t id_length, CATransportFlags_t flag)
+static CAResult_t CAAddIdToPeerInfoList(const char *peerAddr, uint32_t port,
+ const unsigned char *id, uint16_t id_length)
{
if(NULL == peerAddr
|| NULL == id
return CA_STATUS_INVALID_PARAM;
}
- CAEndpoint_t *peer = (CAEndpoint_t *)OICCalloc(1, sizeof (CAEndpoint_t));
+ CASecureEndpoint_t *peer = (CASecureEndpoint_t *)OICCalloc(1, sizeof (CASecureEndpoint_t));
if (NULL == peer)
{
OIC_LOG(ERROR, NET_DTLS_TAG, "peerInfo malloc failed!");
return CA_MEMORY_ALLOC_FAILED;
}
- OICStrcpy(peer->addr, sizeof(peer->addr), peerAddr);
- peer->port = port;
- peer->flags = flag;
- peer->flags |= CA_SECURE;
- peer->adapter = CA_ADAPTER_IP;
+ OICStrcpy(peer->endpoint.addr, sizeof(peer->endpoint.addr), peerAddr);
+ peer->endpoint.port = port;
memcpy(peer->identity.id, id, id_length);
peer->identity.id_length = id_length;
- if(NULL != GetPeerInfo(peer))
+ if (NULL != GetPeerInfo(&peer->endpoint))
{
OIC_LOG(ERROR, NET_DTLS_TAG, "CAAddIdToPeerInfoList peer already exist");
OICFree(peer);
stCADtlsAddrInfo_t *addrInfo = (stCADtlsAddrInfo_t *)session;
- CAEndpoint_t endpoint = { 0 };
- CAConvertAddrToName(&(addrInfo->addr.st), endpoint.addr, &endpoint.port);
- endpoint.flags = addrInfo->addr.st.ss_family == AF_INET ? CA_IPV4 : CA_IPV6;
- endpoint.flags |= CA_SECURE;
- endpoint.adapter = CA_ADAPTER_IP;
- int type = 0;
+ CASecureEndpoint_t sep =
+ { .endpoint =
+ { .adapter = CA_ADAPTER_IP, .flags =
+ ((addrInfo->addr.st.ss_family == AF_INET) ? CA_IPV4 : CA_IPV6) | CA_SECURE, .port = 0 },
+ .identity =
+ { 0 } };
+ CAConvertAddrToName(&(addrInfo->addr.st), sep.endpoint.addr, &sep.endpoint.port);
if (NULL == g_caDtlsContext)
{
return 0;
}
+ int type = 0;
if ((0 <= type) && (MAX_SUPPORTED_ADAPTERS > type) &&
(NULL != g_caDtlsContext->adapterCallbacks[type].recvCallback))
{
// Get identity of the source of packet
- CAEndpoint_t *peerInfo = GetPeerInfo(&endpoint);
+ CASecureEndpoint_t *peerInfo = GetPeerInfo(&sep.endpoint);
if (peerInfo)
{
- endpoint.identity = peerInfo->identity;
+ sep.identity = peerInfo->identity;
}
- g_caDtlsContext->adapterCallbacks[type].recvCallback(&endpoint, buf, bufLen);
+ g_caDtlsContext->adapterCallbacks[type].recvCallback(&sep, buf, bufLen);
}
else
{
OIC_LOG(INFO, NET_DTLS_TAG, "Peer closing connection");
stCADtlsAddrInfo_t *addrInfo = (stCADtlsAddrInfo_t *)session;
- char peerAddr[MAX_ADDR_STR_SIZE_CA] = {0};
+ char peerAddr[MAX_ADDR_STR_SIZE_CA] = { 0 };
uint16_t port = 0;
CAConvertAddrToName(&(addrInfo->addr.st), peerAddr, &port);
CARemovePeerFromPeerInfoList(peerAddr, port);
// data structure when handshake completes. Therefore, currently this is a
// workaround to cache remote end-point identity when tinyDTLS asks for PSK.
stCADtlsAddrInfo_t *addrInfo = (stCADtlsAddrInfo_t *)session;
- char peerAddress[MAX_ADDR_STR_SIZE_CA] = {0};
+ char peerAddr[MAX_ADDR_STR_SIZE_CA] = { 0 };
uint16_t port = 0;
- CAConvertAddrToName(&(addrInfo->addr.st), peerAddress, &port);
+ CAConvertAddrToName(&(addrInfo->addr.st), peerAddr, &port);
- CATransportFlags_t flag =
- addrInfo->addr.st.ss_family == AF_INET ? CA_IPV4 : CA_IPV6;
-
- CAResult_t result = CAAddIdToPeerInfoList(peerAddress,
- port, desc, descLen, flag);
+ CAResult_t result = CAAddIdToPeerInfoList(peerAddr, port, desc, descLen);
if(CA_STATUS_OK != result )
{
OIC_LOG(ERROR, NET_DTLS_TAG, "Fail to add peer id to gDtlsPeerInfoList");
return CA_STATUS_OK;
}
-CAResult_t CAAdapterNetDtlsDecrypt(const CAEndpoint_t *endpoint,
+CAResult_t CAAdapterNetDtlsDecrypt(const CASecureEndpoint_t *sep,
uint8_t *data, uint32_t dataLen)
{
OIC_LOG(DEBUG, NET_DTLS_TAG, "IN");
- VERIFY_NON_NULL_RET(endpoint, NET_DTLS_TAG, "endpoint is NULL" , CA_STATUS_INVALID_PARAM);
+ VERIFY_NON_NULL_RET(sep, NET_DTLS_TAG, "endpoint is NULL" , CA_STATUS_INVALID_PARAM);
stCADtlsAddrInfo_t addrInfo = { 0 };
- CAConvertNameToAddr(endpoint->addr, endpoint->port, &(addrInfo.addr.st));
+ CAConvertNameToAddr(sep->endpoint.addr, sep->endpoint.port, &(addrInfo.addr.st));
addrInfo.ifIndex = 0;
addrInfo.size = CASizeOfAddrInfo(&addrInfo);
}
#endif
-static void CAReceivedPacketCallback(const CAEndpoint_t *endpoint, const void *data, uint32_t dataLen)
+static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
+ const void *data, uint32_t dataLen)
{
OIC_LOG(DEBUG, TAG, "IN");
- // Call the callback.
if (g_networkPacketReceivedCallback != NULL)
{
- g_networkPacketReceivedCallback(endpoint, data, dataLen);
+ g_networkPacketReceivedCallback(sep, data, dataLen);
}
else
{
const void *data, uint32_t dataLen,
CAResult_t result);
-static CAData_t* CAGenerateHandlerData(const CAEndpoint_t *endpoint, const void *data,
- CADataType_t dataType);
+static CAData_t* CAGenerateHandlerData(const CAEndpoint_t *endpoint,
+ const CARemoteId_t *identity,
+ const void *data, CADataType_t dataType);
static void CASendErrorInfo(const CAEndpoint_t *endpoint, const CAInfo_t *info,
CAResult_t result);
return true;
}
-static CAData_t* CAGenerateHandlerData(const CAEndpoint_t *endpoint, const void *data, CADataType_t dataType)
+static CAData_t* CAGenerateHandlerData(const CAEndpoint_t *endpoint,
+ const CARemoteId_t *identity,
+ const void *data, CADataType_t dataType)
{
OIC_LOG(DEBUG, TAG, "CAGenerateHandlerData IN");
-
- CAResponseInfo_t* resInfo = NULL;
- CARequestInfo_t* reqInfo = NULL;
- CAErrorInfo_t *errorInfo = NULL;
-
- CAData_t *cadata = (CAData_t *) OICCalloc(1, sizeof (CAData_t));
+ CAInfo_t *info = NULL;
+ CAData_t *cadata = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
if (!cadata)
{
OIC_LOG(ERROR, TAG, "memory allocation failed");
if (!ep)
{
OIC_LOG(ERROR, TAG, "endpoint clone failed");
- goto errorexit;
+ OICFree(cadata);
+ return NULL;
}
OIC_LOG_V(DEBUG, TAG, "address : %s", ep->addr);
if(CA_RESPONSE_DATA == dataType)
{
- resInfo = (CAResponseInfo_t*)OICCalloc(1, sizeof (CAResponseInfo_t));
+ CAResponseInfo_t* resInfo = (CAResponseInfo_t*)OICCalloc(1, sizeof(CAResponseInfo_t));
if (!resInfo)
{
OIC_LOG(ERROR, TAG, "memory allocation failed");
- goto errorexit;
+ OICFree(cadata);
+ CAFreeEndpoint(ep);
+ return NULL;
}
result = CAGetResponseInfoFromPDU(data, resInfo);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, TAG, "CAGetResponseInfoFromPDU Failed");
- goto errorexit;
+ CAFreeEndpoint(ep);
+ CADestroyResponseInfoInternal(resInfo);
+ OICFree(cadata);
+ return NULL;
}
-
- if (CADropSecondMessage(&caglobals.ca.responseHistory, endpoint, resInfo->info.messageId))
+ cadata->responseInfo = resInfo;
+ info = &resInfo->info;
+ if (identity)
{
- OIC_LOG(ERROR, TAG, "Second Response with same messageID, Drop it");
- goto errorexit;
+ info->identity = *identity;
}
-
- cadata->responseInfo = resInfo;
OIC_LOG(DEBUG, TAG, "Response Info :");
- CALogPayloadInfo(&resInfo->info);
+ CALogPayloadInfo(info);
}
else if (CA_REQUEST_DATA == dataType)
{
- reqInfo = (CARequestInfo_t*)OICCalloc(1, sizeof (CARequestInfo_t));
+ CARequestInfo_t* reqInfo = (CARequestInfo_t*)OICCalloc(1, sizeof(CARequestInfo_t));
if (!reqInfo)
{
OIC_LOG(ERROR, TAG, "memory allocation failed");
- goto errorexit;
+ OICFree(cadata);
+ CAFreeEndpoint(ep);
+ return NULL;
}
result = CAGetRequestInfoFromPDU(data, reqInfo);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, TAG, "CAGetRequestInfoFromPDU failed");
- goto errorexit;
+ CAFreeEndpoint(ep);
+ CADestroyRequestInfoInternal(reqInfo);
+ OICFree(cadata);
+ return NULL;
}
if (CADropSecondMessage(&caglobals.ca.requestHistory, endpoint, reqInfo->info.messageId))
{
- OIC_LOG(ERROR, TAG, "Second Request with same messageID, Drop it");
- goto errorexit;
+ OIC_LOG(ERROR, TAG, "Second Request with same Token, Drop it");
+ CAFreeEndpoint(ep);
+ CADestroyRequestInfoInternal(reqInfo);
+ OICFree(cadata);
+ return NULL;
}
cadata->requestInfo = reqInfo;
+ info = &reqInfo->info;
+ if (identity)
+ {
+ info->identity = *identity;
+ }
OIC_LOG(DEBUG, TAG, "Request Info :");
- CALogPayloadInfo(&reqInfo->info);
- }
+ CALogPayloadInfo(info);
+ }
else if (CA_ERROR_DATA == dataType)
{
- errorInfo = (CAErrorInfo_t *)OICCalloc(1, sizeof (CAErrorInfo_t));
+ CAErrorInfo_t *errorInfo = (CAErrorInfo_t *)OICCalloc(1, sizeof (CAErrorInfo_t));
if (!errorInfo)
{
OIC_LOG(ERROR, TAG, "Memory allocation failed!");
- goto errorexit;
+ OICFree(cadata);
+ CAFreeEndpoint(ep);
+ return NULL;
}
- result = CAGetErrorInfoFromPDU(data, errorInfo);
+ CAResult_t result = CAGetErrorInfoFromPDU(data, errorInfo);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, TAG, "CAGetErrorInfoFromPDU failed");
- goto errorexit;
+ CAFreeEndpoint(ep);
+ OICFree(errorInfo);
+ OICFree(cadata);
+ return NULL;
}
cadata->errorInfo = errorInfo;
+ info = &errorInfo->info;
+ if (identity)
+ {
+ info->identity = *identity;
+ }
OIC_LOG(DEBUG, TAG, "error Info :");
- CALogPayloadInfo(&errorInfo->info);
- }
- else
- {
- OIC_LOG_V(ERROR, TAG, "bad dataType: %d", dataType);
- goto errorexit;
+ CALogPayloadInfo(info);
}
cadata->remoteEndpoint = ep;
cadata->dataType = dataType;
- OIC_LOG(DEBUG, TAG, "CAGenerateHandlerData OUT");
-
return cadata;
-errorexit:
- CAFreeEndpoint(ep);
- OICFree(cadata);
- OICFree(resInfo);
- OICFree(reqInfo);
- OICFree(errorInfo);
- return NULL;
+ OIC_LOG(DEBUG, TAG, "CAGenerateHandlerData OUT");
}
static void CATimeoutCallback(const CAEndpoint_t *endpoint, const void *pdu, uint32_t size)
return ret;
}
-static void CAReceivedPacketCallback(const CAEndpoint_t *remoteEndpoint, const void *data,
- uint32_t dataLen)
+static void CAReceivedPacketCallback(const CASecureEndpoint_t *sep,
+ const void *data, uint32_t dataLen)
{
OIC_LOG(DEBUG, TAG, "IN");
- VERIFY_NON_NULL_VOID(remoteEndpoint, TAG, "remoteEndpoint");
+ VERIFY_NON_NULL_VOID(sep, TAG, "remoteEndpoint");
VERIFY_NON_NULL_VOID(data, TAG, "data");
uint32_t code = CA_NOT_FOUND;
OIC_LOG_V(DEBUG, TAG, "code = %d", code);
if (CA_GET == code || CA_POST == code || CA_PUT == code || CA_DELETE == code)
{
- cadata = CAGenerateHandlerData(remoteEndpoint, pdu, CA_REQUEST_DATA);
+ cadata = CAGenerateHandlerData(&(sep->endpoint), &(sep->identity), pdu, CA_REQUEST_DATA);
if (!cadata)
{
OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, CAGenerateHandlerData failed!");
}
else
{
- cadata = CAGenerateHandlerData(remoteEndpoint, pdu, CA_RESPONSE_DATA);
+ cadata = CAGenerateHandlerData(&(sep->endpoint), &(sep->identity), pdu, CA_RESPONSE_DATA);
if (!cadata)
{
OIC_LOG(ERROR, TAG, "CAReceivedPacketCallback, CAGenerateHandlerData failed!");
CAProcessReceivedData(cadata);
#else
#ifdef WITH_BWT
- if (CA_ADAPTER_GATT_BTLE != remoteEndpoint->adapter)
+ if (CA_ADAPTER_GATT_BTLE != sep->endpoint.adapter)
+ {
+ CAResult_t res = CAReceiveBlockWiseData(pdu, &(sep->endpoint), cadata, dataLen);
+ if (CA_NOT_SUPPORTED == res)
{
- CAResult_t res = CAReceiveBlockWiseData(pdu, remoteEndpoint, cadata, dataLen);
- if (CA_NOT_SUPPORTED == res)
- {
- OIC_LOG(ERROR, TAG, "this message does not have block option");
- CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
- }
- else
- {
- CADestroyData(cadata, sizeof(CAData_t));
- }
+ OIC_LOG(ERROR, TAG, "this message does not have block option");
+ CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
}
else
-#endif
{
- CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
+ CADestroyData(cadata, sizeof(CAData_t));
}
+ }
+ else
+#endif
+ {
+ CAQueueingThreadAddData(&g_receiveThread, cadata, sizeof(CAData_t));
+ }
#endif
coap_delete_pdu(pdu);
return;
}
- CAData_t *cadata = CAGenerateHandlerData(endpoint, pdu, CA_ERROR_DATA);
+ CAData_t *cadata = CAGenerateHandlerData(endpoint, NULL, pdu, CA_ERROR_DATA);
if(!cadata)
{
OIC_LOG(ERROR, TAG, "CAErrorHandler, CAGenerateHandlerData failed!");
OIC_LOG(DEBUG, TAG, "IN");
if (g_packetReceivedCallback)
{
- CAEndpoint_t ep;
- strncpy(ep.addr, ipAddress, MAX_ADDR_STR_SIZE_CA);
- ep.port = port;
- ep.flags = CA_IPV4;
- ep.adapter = CA_ADAPTER_IP;
- g_packetReceivedCallback(&ep, data, dataLength);
+ CASecureEndpoint_t sep =
+ {.endpoint = {.adapter = CA_ADAPTER_IP, .flags = CA_IPV4, .port = port}};
+ OICStrcpy(sep.endpoint.addr, sizeof(sep.endpoint.addr), ipAddress);
+ g_packetReceivedCallback(&sep, data, dataLength);
}
OIC_LOG(DEBUG, TAG, "OUT");
}
OIC_LOG(DEBUG, TAG, "IN");
if (gPacketReceivedCallback)
{
- CAEndpoint_t ep;
- strncpy(ep.addr, ipAddress, MAX_ADDR_STR_SIZE_CA);
- ep.port = port;
- ep.flags = CA_IPV4;
- ep.adapter = CA_ADAPTER_IP;
- gPacketReceivedCallback(&ep, data, dataLength);
+ CASecureEndpoint_t sep =
+ {.endpoint = {.adapter = CA_ADAPTER_IP, .flags = CA_IPV4, .port = port}};
+
+ OICStrcpy(sep.endpoint.addr, sizeof(sep.endpoint.addr), ipAddress);
+ gPacketReceivedCallback(&sep, data, dataLength);
OIC_LOG(DEBUG, TAG, "Notified network packet");
}
OIC_LOG(DEBUG, TAG, "OUT");
*/
static CAErrorHandleCallback g_errorCallback = NULL;
-static void CAIPPacketReceivedCB(const CAEndpoint_t *endpoint,
+static void CAIPPacketReceivedCB(const CASecureEndpoint_t *endpoint,
const void *data, uint32_t dataLength);
#ifdef __WITH_DTLS__
static void CAIPPacketSendCB(CAEndpoint_t *endpoint,
}
#endif
-void CAIPPacketReceivedCB(const CAEndpoint_t *endpoint, const void *data,
+
+void CAIPPacketReceivedCB(const CASecureEndpoint_t *sep, const void *data,
uint32_t dataLength)
{
OIC_LOG(DEBUG, TAG, "IN");
- VERIFY_NON_NULL_VOID(endpoint, TAG, "ipAddress is NULL");
+ VERIFY_NON_NULL_VOID(sep, TAG, "sep is NULL");
VERIFY_NON_NULL_VOID(data, TAG, "data is NULL");
- OIC_LOG_V(DEBUG, TAG, "Address: %s, port:%d", endpoint->addr, endpoint->port);
+ OIC_LOG_V(DEBUG, TAG, "Address: %s, port:%d", sep->endpoint.addr, sep->endpoint.port);
if (g_networkPacketCallback)
{
- g_networkPacketCallback(endpoint, data, dataLength);
+ g_networkPacketCallback(sep, data, dataLength);
}
OIC_LOG(DEBUG, TAG, "OUT");
}
return CA_STATUS_FAILED;
}
- CAEndpoint_t ep = { .adapter = CA_ADAPTER_IP,
- .flags = flags };
+ CASecureEndpoint_t sep =
+ {.endpoint = {.adapter = CA_ADAPTER_IP, .flags = flags}};
if (flags & CA_IPV6)
{
- ep.interface = ((struct sockaddr_in6 *)&srcAddr)->sin6_scope_id;
+ sep.endpoint.interface = ((struct sockaddr_in6 *)&srcAddr)->sin6_scope_id;
((struct sockaddr_in6 *)&srcAddr)->sin6_scope_id = 0;
}
- CAConvertAddrToName(&srcAddr, ep.addr, &ep.port);
+ CAConvertAddrToName(&srcAddr, sep.endpoint.addr, &sep.endpoint.port);
if (flags & CA_SECURE)
{
#ifdef __WITH_DTLS__
- int ret = CAAdapterNetDtlsDecrypt(&ep, (uint8_t *)recvBuffer, recvLen);
+ int ret = CAAdapterNetDtlsDecrypt(&sep, (uint8_t *)recvBuffer, recvLen);
OIC_LOG_V(DEBUG, TAG, "CAAdapterNetDtlsDecrypt returns [%d]", ret);
#else
OIC_LOG(ERROR, TAG, "Encrypted message but no DTLS");
{
if (g_packetReceivedCallback)
{
- g_packetReceivedCallback(&ep, recvBuffer, recvLen);
+ g_packetReceivedCallback(&sep, recvBuffer, recvLen);
}
}
void CAIPSetPacketReceiveCallback(CAIPPacketReceivedCallback callback)
{
-OIC_LOG(DEBUG, TAG, "IN");
+ OIC_LOG(DEBUG, TAG, "IN");
-g_packetReceivedCallback = callback;
+ g_packetReceivedCallback = callback;
-OIC_LOG(DEBUG, TAG, "OUT");
+ OIC_LOG(DEBUG, TAG, "OUT");
}
void CAIPSetExceptionCallback(CAIPExceptionCallback callback)
{
-OIC_LOG(DEBUG, TAG, "IN");
+ OIC_LOG(DEBUG, TAG, "IN");
g_exceptionCallback = callback;
// Copy the subjectID
OicUuid_t subjectId = {.id = {0}};
- memcpy(subjectId.id, endPoint->identity.id, sizeof(subjectId.id));
+ memcpy(subjectId.id, requestInfo->info.identity.id, sizeof(subjectId.id));
//Check the URI has the query and skip it before checking the permission
char *uri = strstr(requestInfo->info.resourceUri, "?");
/** transport modifiers.*/
OCTransportFlags flags;
+ /** for IP.*/
+ uint16_t port;
+
/** address for all adapters.*/
char addr[MAX_ADDR_STR_SIZE];
/** usually zero for default interface.*/
uint32_t interface;
- /** for IP.*/
- uint16_t port;
-
- /** secure node identity.*/
- OCIdentity identity;
} OCDevAddr;
/**
/** backward compatibility.*/
OCConnectivityType connType;
+ /** the security identity of the remote server.*/
+ OCIdentity identity;
+
/** the is the result of our stack, OCStackResult should contain coap/other error codes.*/
OCStackResult result;
cbNode->presence->TTL = maxAgeSeconds;
- for(int index = 0; index < PresenceTimeOutSize; index++)
+ for (int index = 0; index < PresenceTimeOutSize; index++)
{
// Guard against overflow
if (cbNode->presence->TTL < (UINT32_MAX/(MILLISECONDS_PER_SECOND*PresenceTimeOut[index]))
// check for unicast presence
uriLen = FormCanonicalPresenceUri(endpoint, OC_RSRVD_PRESENCE_URI, presenceUri);
- if (uriLen < 0 || uriLen >= sizeof (presenceUri))
+ if (uriLen < 0 || (size_t)uriLen >= sizeof (presenceUri))
{
return OC_STACK_INVALID_URI;
}
CopyEndpointToDevAddr(endPoint, &response.devAddr);
FixUpClientResponse(&response);
response.resourceUri = responseInfo->info.resourceUri;
+ memcpy(response.identity.id, responseInfo->info.identity.id,
+ sizeof (response.identity.id));
+ response.identity.id_length = responseInfo->info.identity.id_length;
response.result = CAToOCStackResult(responseInfo->result);
cbNode->callBack(cbNode->context,
CopyEndpointToDevAddr(endPoint, &response.devAddr);
FixUpClientResponse(&response);
response.resourceUri = responseInfo->info.resourceUri;
+ memcpy(response.identity.id, responseInfo->info.identity.id,
+ sizeof (response.identity.id));
+ response.identity.id_length = responseInfo->info.identity.id_length;
response.result = CAToOCStackResult(responseInfo->result);
if(responseInfo->info.payload &&
VERIFY_SUCCESS(result, OC_STACK_OK);
#ifdef WITH_PRESENCE
- PresenceTimeOutSize = sizeof(PresenceTimeOut)/sizeof(PresenceTimeOut[0]) - 1;
+ PresenceTimeOutSize = sizeof (PresenceTimeOut) / sizeof (PresenceTimeOut[0]) - 1;
#endif // WITH_PRESENCE
//Update Stack state to initialized
cbNode->presence->TTLlevel);
OC_LOG_V(DEBUG, TAG, "current ticks %d", now);
- if(cbNode->presence->TTLlevel >= (PresenceTimeOutSize + 1))
+ if (cbNode->presence->TTLlevel > PresenceTimeOutSize)
{
goto exit;
}
OC_LOG_V(DEBUG, TAG, "timeout ticks %d",
cbNode->presence->timeOut[cbNode->presence->TTLlevel]);
}
-
if (cbNode->presence->TTLlevel >= PresenceTimeOutSize)
{
OC_LOG(DEBUG, TAG, PCF("No more timeout ticks"));
char *pointerToDelimiter = strstr(uri, "?");
- uriWithoutQueryLen = pointerToDelimiter == NULL ? uriLen : pointerToDelimiter - uri;
+ uriWithoutQueryLen = pointerToDelimiter == NULL ? uriLen : (size_t)(pointerToDelimiter - uri);
queryLen = pointerToDelimiter == NULL ? 0 : uriLen - uriWithoutQueryLen - 1;
if (uriWithoutQueryLen)