#include <stdint.h>
#include <stdbool.h>
+#include "octypes.h"
#include "ocrandom.h"
#include "cainterface.h"
#include "caremotehandler.h"
extern void CAsetPkixInfoCallback(CAgetPkixInfoHandler infCallback);
extern void CAsetPskCredentialsCallback(CAgetPskCredentialsHandler credCallback);
extern void CAsetCredentialTypesCallback(CAgetCredentialTypesHandler credCallback);
+extern void CAsetSetupPkContextCallback(CAsetupPkContextHandler setupPkCtxCallback);
#endif // __WITH_DTLS__ or __WITH_TLS__
-CAResult_t CAInitialize()
+CAResult_t CAInitialize(CATransportAdapter_t transportType)
{
OIC_LOG_V(DEBUG, TAG, "IoTivity version is v%s", IOTIVITY_VERSION);
- OIC_LOG(DEBUG, TAG, "CAInitialize");
+ OIC_LOG_V(DEBUG, TAG, "CAInitialize type : %d", transportType);
if (!g_isInitialized)
{
OIC_LOG(ERROR, TAG, "Seed Random Failed");
}
- CAResult_t res = CAInitializeMessageHandler();
+ CAResult_t res = CAInitializeMessageHandler(transportType);
if (res != CA_STATUS_OK)
{
OIC_LOG(ERROR, TAG, "CAInitialize has failed");
+ CATerminateMessageHandler();
return res;
}
g_isInitialized = true;
}
#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
-#ifdef _ENABLE_MULTIPLE_OWNER_
+#ifdef MULTIPLE_OWNER
const CASecureEndpoint_t *CAGetSecureEndpointData(const CAEndpoint_t *peer)
{
OIC_LOG(DEBUG, TAG, "IN CAGetSecurePeerInfo");
OIC_LOG(DEBUG, TAG, "OUT CAGetSecurePeerInfo");
return GetCASecureEndpointData(peer);
}
-#endif //_ENABLE_MULTIPLE_OWNER_
+#endif //MULTIPLE_OWNER
CAResult_t CAregisterSslHandshakeCallback(CAErrorCallback tlsHandshakeCallback)
{
OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
return CA_STATUS_OK;
}
+
+CAResult_t CAregisterSetupPkContextHandler(CAsetupPkContextHandler setupPkContextCallback)
+{
+ OIC_LOG_V(DEBUG, TAG, "In %s", __func__);
+
+ if (!g_isInitialized)
+ {
+ return CA_STATUS_NOT_INITIALIZED;
+ }
+ CAsetSetupPkContextCallback(setupPkContextCallback);
+ OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
+ return CA_STATUS_OK;
+}
#endif // __WITH_DTLS__ or __WITH_TLS__
CAResult_t CACreateEndpoint(CATransportFlags_t flags,
{
return CASendMessageMultiAdapter(object, requestInfo, CA_REQUEST_DATA);
}
+ else if (requestInfo && requestInfo->info.event == CA_REQ_DISCONNECT &&
+ (object->adapter == CA_ADAPTER_TCP || object->adapter == CA_ALL_ADAPTERS))
+ {
+ return CADetachSendNetworkReqMessage(object, requestInfo->info.event, CA_NETWORK_COMMAND);
+ }
else
{
return CADetachSendMessage(object, requestInfo, CA_REQUEST_DATA);
CAResult_t CASelectNetwork(CATransportAdapter_t interestedNetwork)
{
- OIC_LOG_V(DEBUG, TAG, "Selected network : %d", interestedNetwork);
-
if (!g_isInitialized)
{
return CA_STATUS_NOT_INITIALIZED;
return CA_STATUS_OK;
}
-#if defined (__WITH_DTLS__) || defined(__WITH_TLS__)
CAResult_t CASelectCipherSuite(const uint16_t cipher, CATransportAdapter_t adapter)
{
OIC_LOG_V(DEBUG, TAG, "IN %s", __func__);
OIC_LOG_V(DEBUG, TAG, "cipher : %d , CATransportAdapter : %d", cipher, adapter);
- if (CA_STATUS_OK != CAsetTlsCipherSuite(cipher))
+ CAResult_t res = CA_STATUS_FAILED;
+#if defined (__WITH_DTLS__) || defined(__WITH_TLS__)
+ res = CAsetTlsCipherSuite(cipher);
+ if (CA_STATUS_OK != res)
{
- OIC_LOG_V(ERROR, TAG, "Out %s", __func__);
- return CA_STATUS_FAILED;
+ OIC_LOG_V(ERROR, TAG, "Failed to CAsetTlsCipherSuite : %d", res);
}
+#else
+ OIC_LOG(ERROR, TAG, "Method not supported");
+#endif
OIC_LOG_V(DEBUG, TAG, "Out %s", __func__);
- return CA_STATUS_OK;
+ return res;
}
CAResult_t CAEnableAnonECDHCipherSuite(const bool enable)
{
OIC_LOG_V(DEBUG, TAG, "CAEnableAnonECDHCipherSuite");
-
+ CAResult_t res = CA_STATUS_FAILED;
#if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
// TLS_ECDH_ANON_WITH_AES_128_CBC_SHA256 0xFF00 replaces 0xC018
- // TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 0xC037
- if (CA_STATUS_OK != CAsetTlsCipherSuite(enable ? 0xFF00 : 0xC037))
+ res = CAsetTlsCipherSuite(enable ? 0xFF00 : 0x00);
+ if (CA_STATUS_OK != res)
{
- return CA_STATUS_FAILED;
+ OIC_LOG_V(ERROR, TAG, "Failed to CAsetTlsCipherSuite : %d", res);
}
+#else
+ OIC_LOG(ERROR, TAG, "Method not supported");
#endif
- return CA_STATUS_OK;
+ OIC_LOG_V(ERROR, TAG, "Out %s", __func__);
+ return res;
}
CAResult_t CAGenerateOwnerPSK(const CAEndpoint_t* endpoint,
uint8_t* ownerPSK, const size_t ownerPskSize)
{
OIC_LOG_V(DEBUG, TAG, "IN : CAGenerateOwnerPSK");
-
- CAResult_t res = CA_STATUS_OK;
-
+ CAResult_t res = CA_STATUS_FAILED;
+#if defined (__WITH_DTLS__) || defined(__WITH_TLS__)
//newOwnerLabel and prevOwnerLabe can be NULL
if (!endpoint || !label || 0 == labelLen || !ownerPSK || 0 == ownerPskSize)
{
rsrcServerDeviceID, rsrcServerDeviceIDLen,
provServerDeviceID, provServerDeviceIDLen,
ownerPSK, ownerPskSize);
-
if (CA_STATUS_OK != res)
{
OIC_LOG_V(ERROR, TAG, "Failed to CAGenerateOwnerPSK : %d", res);
}
-
+#else
+ OIC_LOG(ERROR, TAG, "Method not supported");
+#endif
OIC_LOG_V(DEBUG, TAG, "OUT : CAGenerateOwnerPSK");
-
return res;
}
CAResult_t CAInitiateHandshake(const CAEndpoint_t *endpoint)
{
OIC_LOG_V(DEBUG, TAG, "IN : CAInitiateHandshake");
- CAResult_t res = CA_STATUS_OK;
-
+ CAResult_t res = CA_STATUS_FAILED;
+#if defined (__WITH_DTLS__) || defined(__WITH_TLS__)
if (!endpoint)
{
return CA_STATUS_INVALID_PARAM;
{
OIC_LOG_V(ERROR, TAG, "Failed to CAinitiateSslHandshake : %d", res);
}
-
+#else
+ OIC_LOG(ERROR, TAG, "Method not supported");
+#endif
OIC_LOG_V(DEBUG, TAG, "OUT : CAInitiateHandshake");
-
return res;
}
CAResult_t CAcloseSslSession(const CAEndpoint_t *endpoint)
{
OIC_LOG_V(DEBUG, TAG, "IN : CAcloseSslSession");
- CAResult_t res = CA_STATUS_OK;
-
+ CAResult_t res = CA_STATUS_FAILED;
+#if defined (__WITH_DTLS__) || defined(__WITH_TLS__)
if (!endpoint)
{
return CA_STATUS_INVALID_PARAM;
{
OIC_LOG_V(ERROR, TAG, "Failed to CAsslClose : %d", res);
}
-
+#else
+ OIC_LOG(ERROR, TAG, "Method not supported");
+#endif
OIC_LOG_V(DEBUG, TAG, "OUT : CAcloseSslSession");
-
return res;
}
-#endif /* __WITH_DTLS__ */
-
#ifdef TCP_ADAPTER
void CARegisterKeepAliveHandler(CAKeepAliveConnectionCallback ConnHandler)
{