X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fconnectivity%2Fsrc%2Fra_adapter%2Fcaraadapter.c;h=11f56cbccb125e183974ff262dc4770fd250611b;hb=7f00f942c39b7bc27c7eeecf213a239c3fe4173c;hp=7f86c3d89b19850926de25d72056d571d53d043c;hpb=bb93e3a07afd2126aa7665c4c56de50e2a1c9bfa;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/connectivity/src/ra_adapter/caraadapter.c b/resource/csdk/connectivity/src/ra_adapter/caraadapter.c index 7f86c3d..11f56cb 100644 --- a/resource/csdk/connectivity/src/ra_adapter/caraadapter.c +++ b/resource/csdk/connectivity/src/ra_adapter/caraadapter.c @@ -26,7 +26,7 @@ #include #include "caadapterutils.h" -#include "camutex.h" +#include "octhread.h" #include "uarraylist.h" #include "logger.h" #include "oic_malloc.h" @@ -59,7 +59,7 @@ static CANetworkPacketReceivedCallback g_networkPacketCallback = NULL; /** * Network Changed Callback to CA. */ -static CANetworkChangeCallback g_networkChangeCallback = NULL; +static CAAdapterChangeCallback g_networkChangeCallback = NULL; /** * Holds XMPP data information. @@ -77,7 +77,7 @@ typedef struct CAJidBoundCallback jidBoundCallback; } CARAXmppData_t; -static ca_mutex g_raadapterMutex = NULL; +static oc_mutex g_raadapterMutex = NULL; static CARAXmppData_t g_xmppData = {.xmpp = NULL, .port = 5222, .hostName = {0}, .password = {0}, .jid = {0}, .connectionStatus = CA_INTERFACE_DOWN, @@ -91,26 +91,16 @@ void CARANotifyNetworkChange(const char *address, CANetworkStatus_t status) g_xmppData.connectionStatus = status; - CAEndpoint_t *localEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, - CA_ADAPTER_REMOTE_ACCESS, - address, 0); - if (!localEndpoint) - { - OIC_LOG(ERROR, RA_ADAPTER_TAG, "localEndpoint creation failed!"); - return; - } - CANetworkChangeCallback networkChangeCallback = g_networkChangeCallback; + CAAdapterChangeCallback networkChangeCallback = g_networkChangeCallback; if (networkChangeCallback) { - networkChangeCallback(localEndpoint, status); + networkChangeCallback(CA_ADAPTER_REMOTE_ACCESS, status); } else { OIC_LOG(ERROR, RA_ADAPTER_TAG, "g_networkChangeCallback is NULL"); } - CAFreeEndpoint(localEndpoint); - OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CARANotifyNetworkChange OUT"); } @@ -241,16 +231,16 @@ static char *CARAGetSIDFromPDU(coap_pdu_t *pdu) VERIFY_NON_NULL_RET(pdu, RA_ADAPTER_TAG, "Invalid parameter!", NULL); - if (pdu->hdr->coap_hdr_udp_t.token_length * 2 > MAX_IBB_SESSION_ID_LENGTH) + if (pdu->hdr->token_length * 2 > MAX_IBB_SESSION_ID_LENGTH) { OIC_LOG(ERROR, RA_ADAPTER_TAG, "Token length more than expected!"); return NULL; } char hex[3] = {0}; - for (int i = 0; i < pdu->hdr->coap_hdr_udp_t.token_length; i++) + for (int i = 0; i < pdu->hdr->token_length; i++) { - snprintf(hex, 3, "%02x", pdu->hdr->coap_hdr_udp_t.token[i]); + snprintf(hex, 3, "%02x", pdu->hdr->token[i]); OICStrcat(s_sid, sizeof(s_sid), hex); } @@ -359,8 +349,8 @@ static int CARAConnHandler(xmpp_t *xmpp, xmppconn_info_t *conninfo, void *udata) } CAResult_t CAInitializeRA(CARegisterConnectivityCallback registerCallback, - CANetworkPacketReceivedCallback networkPacketCallback, - CANetworkChangeCallback netCallback, ca_thread_pool_t handle) + CANetworkPacketReceivedCallback networkPacketCallback, + CAAdapterChangeCallback netCallback, ca_thread_pool_t handle) { OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CAInitializeRA IN"); if (!registerCallback || !networkPacketCallback || !netCallback || !handle) @@ -374,15 +364,17 @@ CAResult_t CAInitializeRA(CARegisterConnectivityCallback registerCallback, CAConnectivityHandler_t raHandler = { .startAdapter = CAStartRA, + .stopAdapter = CAStopRA, .startListenServer = CAStartRAListeningServer, .startDiscoveryServer = CAStartRADiscoveryServer, .sendData = CASendRAUnicastData, .sendDataToAll = CASendRAMulticastData, .GetnetInfo = CAGetRAInterfaceInformation, .readData = CAReadRAData, - .stopAdapter = CAStopRA, - .terminate = CATerminateRA}; - registerCallback(raHandler, CA_ADAPTER_REMOTE_ACCESS); + .terminate = CATerminateRA, + .cType = CA_ADAPTER_REMOTE_ACCESS}; + + registerCallback(raHandler); #ifdef NDEBUG xmpp_log_t *log = xmpp_get_default_logger(XMPP_LEVEL_ERROR); #else @@ -459,14 +451,14 @@ CAResult_t CAStartRA() return CA_STATUS_FAILED; } - g_raadapterMutex = ca_mutex_new (); + g_raadapterMutex = oc_mutex_new (); if (!g_raadapterMutex) { OIC_LOG (ERROR, RA_ADAPTER_TAG, PCF("Memory allocation for mutex failed.")); return CA_MEMORY_ALLOC_FAILED; } - ca_mutex_lock (g_raadapterMutex); + oc_mutex_lock (g_raadapterMutex); xmpphelper_connect(g_xmppData.xmpp, g_xmppData.hostName, g_xmppData.port, g_xmppData.jid, g_xmppData.password); @@ -479,7 +471,7 @@ CAResult_t CAStartRA() xmpphelper_run(g_xmppData.xmpp); - ca_mutex_unlock (g_raadapterMutex); + oc_mutex_unlock (g_raadapterMutex); OIC_LOG(DEBUG, RA_ADAPTER_TAG, "RA adapter started succesfully"); return CA_STATUS_OK; @@ -493,7 +485,7 @@ CAResult_t CAStopRA() xmpp_ibb_unregister(xmpphelper_get_conn(g_xmppData.xmpp)); if (!g_raadapterMutex) { - ca_mutex_free (g_raadapterMutex); + oc_mutex_free (g_raadapterMutex); g_raadapterMutex = NULL; } OIC_LOG(DEBUG, RA_ADAPTER_TAG, PCF("Stopped RA adapter successfully")); @@ -501,8 +493,10 @@ CAResult_t CAStopRA() } int32_t CASendRAUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data, - uint32_t dataLength) + uint32_t dataLength, CADataType_t dataType) { + SET_BUT_NOT_USED(dataType); + if (!remoteEndpoint || !data) { OIC_LOG(ERROR, RA_ADAPTER_TAG, "Invalid parameter!"); @@ -522,11 +516,11 @@ int32_t CASendRAUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data int obsopt = CARAGetReqObsOption(pdu, remoteEndpoint); coap_delete_pdu(pdu); - ca_mutex_lock (g_raadapterMutex); + oc_mutex_lock (g_raadapterMutex); if (CA_INTERFACE_UP != g_xmppData.connectionStatus) { OIC_LOG(ERROR, RA_ADAPTER_TAG, "Unable to send XMPP message, RA not connected"); - ca_mutex_unlock (g_raadapterMutex); + oc_mutex_unlock (g_raadapterMutex); return -1; } @@ -537,7 +531,7 @@ int32_t CASendRAUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data if (sess == NULL) { OIC_LOG(ERROR, RA_ADAPTER_TAG, "IBB session establish failed!"); - ca_mutex_unlock (g_raadapterMutex); + oc_mutex_unlock (g_raadapterMutex); return -1; } } @@ -550,7 +544,7 @@ int32_t CASendRAUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data } xmppdata_t xdata = {.data = (char *) data, .size = dataLength}; int rc = xmpp_ibb_send_data(sess, &xdata); - ca_mutex_unlock (g_raadapterMutex); + oc_mutex_unlock (g_raadapterMutex); if (rc < 0) { OIC_LOG(ERROR, RA_ADAPTER_TAG, "IBB send data failed!"); @@ -571,12 +565,14 @@ CAResult_t CAGetRAInterfaceInformation(CAEndpoint_t **info, uint32_t *size) } int32_t CASendRAMulticastData(const CAEndpoint_t *endpoint, - const void *data, uint32_t dataLength) + const void *data, uint32_t dataLength, + CADataType_t dataType) { OIC_LOG(INFO, RA_ADAPTER_TAG, "RA adapter does not support sending multicast data"); SET_BUT_NOT_USED(endpoint); SET_BUT_NOT_USED(data); SET_BUT_NOT_USED(dataLength); + SET_BUT_NOT_USED(dataType); return 0; } @@ -613,7 +609,7 @@ static CANetworkPacketReceivedCallback g_networkPacketCallback = NULL; /** * Network Changed Callback to CA. */ -static CANetworkChangeCallback g_networkChangeCallback = NULL; +static CAAdapterChangeCallback g_networkChangeCallback = NULL; /** * Holds XMPP data information. @@ -632,7 +628,7 @@ typedef struct char jabberID[CA_RAJABBERID_SIZE]; } CARAXmppData_t; -static ca_mutex g_raadapterMutex = NULL; +static oc_mutex g_raadapterMutex = NULL; static CARAXmppData_t g_xmppData = {}; @@ -655,26 +651,16 @@ void CARANotifyNetworkChange(const char *address, CANetworkStatus_t status) { OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CARANotifyNetworkChange IN"); - CAEndpoint_t *localEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, - CA_ADAPTER_REMOTE_ACCESS, - address, 0); - if (!localEndpoint) - { - OIC_LOG(ERROR, RA_ADAPTER_TAG, "localEndpoint creation failed!"); - return; - } - CANetworkChangeCallback networkChangeCallback = g_networkChangeCallback; + CAAdapterChangeCallback networkChangeCallback = g_networkChangeCallback; if (networkChangeCallback) { - networkChangeCallback(localEndpoint, status); + networkChangeCallback(CA_ADAPTER_REMOTE_ACCESS, status); } else { OIC_LOG(ERROR, RA_ADAPTER_TAG, "g_networkChangeCallback is NULL"); } - CAFreeEndpoint(localEndpoint); - OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CARANotifyNetworkChange OUT"); } @@ -688,7 +674,7 @@ void CARAXmppConnectedCB(void * const param, xmpp_error_code_t result, { printf("\n\n\t\t===>your jid: %s\n\n", bound_jid); - ca_mutex_lock (g_raadapterMutex); + oc_mutex_lock (g_raadapterMutex); OICStrcpy (g_xmppData.jabberID, CA_RAJABBERID_SIZE, bound_jid); g_xmppData.connection_status = CA_INTERFACE_UP; @@ -706,7 +692,7 @@ void CARAXmppConnectedCB(void * const param, xmpp_error_code_t result, OIC_LOG_V(ERROR, RA_ADAPTER_TAG, "XMPP connected callback status: %d", result); } - ca_mutex_unlock (g_raadapterMutex); + oc_mutex_unlock (g_raadapterMutex); // Notify network change to CA CARANotifyNetworkChange(bound_jid, connection_status); @@ -718,13 +704,13 @@ void CARAXmppDisonnectedCB(void * const param, xmpp_error_code_t result, { OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CARAXmppDisonnectedCB IN"); char jabberID[CA_RAJABBERID_SIZE]; - ca_mutex_lock (g_raadapterMutex); + oc_mutex_lock (g_raadapterMutex); g_xmppData.connection_status = CA_INTERFACE_DOWN; xmpp_message_context_destroy(g_xmppData.message_context); OICStrcpy (jabberID, CA_RAJABBERID_SIZE, g_xmppData.jabberID); - ca_mutex_unlock (g_raadapterMutex); + oc_mutex_unlock (g_raadapterMutex); // Notify network change to CA CARANotifyNetworkChange(jabberID, CA_INTERFACE_DOWN); @@ -781,8 +767,8 @@ void CARAXmppMessageReceivedCB(void * const param, xmpp_error_code_t result, } CAResult_t CAInitializeRA(CARegisterConnectivityCallback registerCallback, - CANetworkPacketReceivedCallback networkPacketCallback, - CANetworkChangeCallback netCallback, ca_thread_pool_t handle) + CANetworkPacketReceivedCallback networkPacketCallback, + CAAdapterChangeCallback netCallback, ca_thread_pool_t handle) { OIC_LOG(DEBUG, RA_ADAPTER_TAG, "CAInitializeRA IN"); if (!registerCallback || !networkPacketCallback || !netCallback || !handle) @@ -793,18 +779,19 @@ CAResult_t CAInitializeRA(CARegisterConnectivityCallback registerCallback, g_networkChangeCallback = netCallback; g_networkPacketCallback = networkPacketCallback; - CAConnectivityHandler_t raHandler = {}; - raHandler.startAdapter = CAStartRA; - raHandler.startListenServer = CAStartRAListeningServer; - raHandler.stopListenServer = CAStopRAListeningServer; - raHandler.startDiscoveryServer = CAStartRADiscoveryServer; - raHandler.sendData = CASendRAUnicastData; - raHandler.sendDataToAll = CASendRAMulticastData; - raHandler.GetnetInfo = CAGetRAInterfaceInformation; - raHandler.readData = CAReadRAData; - raHandler.stopAdapter = CAStopRA; - raHandler.terminate = CATerminateRA; - registerCallback(raHandler, CA_ADAPTER_REMOTE_ACCESS); + CAConnectivityHandler_t raHandler = { + .startAdapter = CAStartRA, + .stopAdapter = CAStopRA, + .startListenServer = CAStartRAListeningServer, + .stopListenServer = CAStopRAListeningServer, + .startDiscoveryServer = CAStartRADiscoveryServer, + .sendData = CASendRAUnicastData, + .sendDataToAll = CASendRAMulticastData, + .GetnetInfo = CAGetRAInterfaceInformation, + .readData = CAReadRAData, + .terminate = CATerminateRA, + .cType = CA_ADAPTER_REMOTE_ACCESS}; + registerCallback(raHandler); return CA_STATUS_OK; } @@ -837,14 +824,14 @@ CAResult_t CAStartRA() OIC_LOG(DEBUG, RA_ADAPTER_TAG, PCF("Starting RA adapter")); - g_raadapterMutex = ca_mutex_new (); + g_raadapterMutex = oc_mutex_new (); if (!g_raadapterMutex) { OIC_LOG (ERROR, RA_ADAPTER_TAG, PCF("Memory allocation for mutex failed.")); return CA_MEMORY_ALLOC_FAILED; } - ca_mutex_lock (g_raadapterMutex); + oc_mutex_lock (g_raadapterMutex); xmpp_context_init(&g_xmppData.context); g_xmppData.handle = xmpp_startup(&g_xmppData.context); @@ -861,7 +848,7 @@ CAResult_t CAStartRA() xmpp_identity_destroy(&g_xmppData.g_identity); xmpp_host_destroy(&g_xmppData.g_host); - ca_mutex_unlock (g_raadapterMutex); + oc_mutex_unlock (g_raadapterMutex); if (XMPP_ERR_OK != ret) { @@ -888,7 +875,7 @@ CAResult_t CAStopRA() xmpp_shutdown_xmpp(g_xmppData.handle); xmpp_context_destroy(&g_xmppData.context); - ca_mutex_free (g_raadapterMutex); + oc_mutex_free (g_raadapterMutex); g_raadapterMutex = NULL; OIC_LOG(DEBUG, RA_ADAPTER_TAG, PCF("Stopped RA adapter successfully")); @@ -896,8 +883,9 @@ CAResult_t CAStopRA() } int32_t CASendRAUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data, - uint32_t dataLength) + uint32_t dataLength, CADataType_t dataType) { + (void)dataType; if (!remoteEndpoint || !data) { OIC_LOG(ERROR, RA_ADAPTER_TAG, "Invalid parameter!"); @@ -911,12 +899,12 @@ int32_t CASendRAUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data } OIC_LOG_V(ERROR, RA_ADAPTER_TAG, "Sending unicast data to %s", remoteEndpoint->addr); - ca_mutex_lock (g_raadapterMutex); + oc_mutex_lock (g_raadapterMutex); if (CA_INTERFACE_UP != g_xmppData.connection_status) { OIC_LOG(ERROR, RA_ADAPTER_TAG, "Unable to send XMPP message, RA not connected"); - ca_mutex_unlock (g_raadapterMutex); + oc_mutex_unlock (g_raadapterMutex); return -1; } @@ -926,10 +914,10 @@ int32_t CASendRAUnicastData(const CAEndpoint_t *remoteEndpoint, const void *data if (XMPP_ERR_OK != res) { OIC_LOG_V(ERROR, RA_ADAPTER_TAG, "Unable to send XMPP message, status: %d", res); - ca_mutex_unlock (g_raadapterMutex); + oc_mutex_unlock (g_raadapterMutex); return -1; } - ca_mutex_unlock (g_raadapterMutex); + oc_mutex_unlock (g_raadapterMutex); OIC_LOG_V(INFO, RA_ADAPTER_TAG, "Successfully dispatched bytes[%d] to addr[%s]", dataLength, remoteEndpoint->addr); @@ -942,16 +930,16 @@ CAResult_t CAGetRAInterfaceInformation(CAEndpoint_t **info, uint32_t *size) VERIFY_NON_NULL(info, RA_ADAPTER_TAG, "info is NULL"); VERIFY_NON_NULL(size, RA_ADAPTER_TAG, "size is NULL"); - ca_mutex_lock (g_raadapterMutex); + oc_mutex_lock (g_raadapterMutex); if (CA_INTERFACE_UP != g_xmppData.connection_status) { OIC_LOG(ERROR, RA_ADAPTER_TAG, "Failed to get interface info, RA not Connected"); - ca_mutex_unlock (g_raadapterMutex); + oc_mutex_unlock (g_raadapterMutex); return CA_ADAPTER_NOT_ENABLED; } - ca_mutex_unlock (g_raadapterMutex); + oc_mutex_unlock (g_raadapterMutex); CAEndpoint_t *localEndpoint = CACreateEndpointObject(CA_DEFAULT_FLAGS, CA_ADAPTER_REMOTE_ACCESS, @@ -964,7 +952,8 @@ CAResult_t CAGetRAInterfaceInformation(CAEndpoint_t **info, uint32_t *size) } int32_t CASendRAMulticastData(const CAEndpoint_t *endpoint, - const void *data, uint32_t dataLength) + const void *data, uint32_t dataLength, + CADataType_t dataType) { OIC_LOG(INFO, RA_ADAPTER_TAG, "RA adapter does not support sending multicast data"); return 0;