static void CARemoveNetworkMonitorList(int ifiindex) { VERIFY_NON_NULL_VOID(g_netInterfaceList, TAG, "g_netInterfaceList is NULL"); ca_mutex_lock(g_networkMonitorContextMutex); uint32_t list_length = u_arraylist_length(g_netInterfaceList); for (uint32_t list_index = 0; list_index < list_length; list_index++) { CAInterface_t *removedifitem = (CAInterface_t *) u_arraylist_get( g_netInterfaceList, list_index); if (removedifitem && removedifitem->index == ifiindex) { if (u_arraylist_remove(g_netInterfaceList, list_index)) { OICFree(removedifitem); ca_mutex_unlock(g_networkMonitorContextMutex); return; } continue; } } ca_mutex_unlock(g_networkMonitorContextMutex); return; }
OCStackResult RemoveKeepAliveEntry(const CAEndpoint_t *endpoint) { VERIFY_NON_NULL(endpoint, FATAL, OC_STACK_INVALID_PARAM); uint32_t index = 0; KeepAliveEntry_t *entry = GetEntryFromEndpoint(endpoint, &index); if (!entry) { OIC_LOG(ERROR, TAG, "There is no entry in keepalive table."); return OC_STACK_ERROR; } KeepAliveEntry_t *removedEntry = (KeepAliveEntry_t *) u_arraylist_remove(g_keepAliveConnectionTable, index); if (NULL == removedEntry) { OIC_LOG(ERROR, TAG, "Removed Entry is NULL"); return OC_STACK_ERROR; } OIC_LOG_V(DEBUG, TAG, "Remove Connection Info from KeepAlive table, " "remote addr=%s port:%d", removedEntry->remoteAddr.addr, removedEntry->remoteAddr.port); OICFree(entry->intervalInfo); OICFree(removedEntry); return OC_STACK_OK; }
static void CARemovePeerFromPeerInfoList(const char * addr, uint16_t port) { if (NULL == addr || 0 >= port) { OIC_LOG(ERROR, NET_DTLS_TAG, "CADTLSGetPeerPSKId invalid parameters"); return; } uint32_t list_length = u_arraylist_length(g_caDtlsContext->peerInfoList); for (uint32_t list_index = 0; list_index < list_length; list_index++) { CAEndpoint_t *peerInfo = (CAEndpoint_t *)u_arraylist_get( g_caDtlsContext->peerInfoList,list_index); if (NULL == peerInfo) { continue; } if((0 == strncmp(addr, peerInfo->addr, MAX_ADDR_STR_SIZE_CA)) && (port == peerInfo->port)) { OICFree(u_arraylist_remove(g_caDtlsContext->peerInfoList, list_index)); return; } } }
void CAEDRNativeRemoveDeviceSocket(JNIEnv *env, jobject deviceSocket) { OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceSocket"); if (!g_deviceObjectList) { OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceObjectList is null"); return; } jint index; jint length = u_arraylist_length(g_deviceStateList); for (index = 0; index < length; index++) { jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index); if (!jarrayObj) { OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null"); continue; } jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj); if (!jni_setAddress) { OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_setAddress is null"); continue; } jstring jni_remoteAddress = CAEDRNativeGetAddressFromDeviceSocket(env, deviceSocket); if (!jni_remoteAddress) { OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_remoteAddress is null"); continue; } const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL); const char* remoteAddress = (*env)->GetStringUTFChars(env, jni_remoteAddress, NULL); if (!strcmp(setAddress, remoteAddress)) { OIC_LOG_V(DEBUG, TAG, "[EDR][Native] remove object : %s", remoteAddress); (*env)->DeleteGlobalRef(env, jarrayObj); (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress); (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress); u_arraylist_remove(g_deviceObjectList, index); break; } (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress); (*env)->ReleaseStringUTFChars(env, jni_remoteAddress, remoteAddress); } OIC_LOG(DEBUG, TAG, "[EDR][Native] there are no target object"); return; }
static void CASendCachedMsg(const stCADtlsAddrInfo_t *dstSession) { OIC_LOG(DEBUG, NET_DTLS_TAG, "IN"); VERIFY_NON_NULL_VOID(dstSession, NET_DTLS_TAG, "Param dstSession is NULL"); uint32_t list_index = 0; uint32_t list_length = 0; list_length = u_arraylist_length(g_caDtlsContext->cacheList); for (list_index = 0; list_index < list_length;) { stCACacheMessage_t *msg = (stCACacheMessage_t *)u_arraylist_get(g_caDtlsContext->cacheList, list_index); if ((NULL != msg) && (true == CAIsAddressMatching(&(msg->destSession), dstSession))) { eDtlsRet_t ret = CAAdapterNetDtlsEncryptInternal(&(msg->destSession), msg->data, msg->dataLen); if (ret == DTLS_OK) { OIC_LOG(DEBUG, NET_DTLS_TAG, "CAAdapterNetDtlsEncryptInternal success"); } else { OIC_LOG(ERROR, NET_DTLS_TAG, "CAAdapterNetDtlsEncryptInternal failed."); } if (u_arraylist_remove(g_caDtlsContext->cacheList, list_index)) { CAFreeCacheMsg(msg); // Reduce list length by 1 as we removed one element. list_length--; } else { OIC_LOG(ERROR, NET_DTLS_TAG, "u_arraylist_remove failed."); break; } } else { // Move to the next element ++list_index; } } OIC_LOG(DEBUG, NET_DTLS_TAG, "OUT"); }
void CAEDRNativeRemoveDevice(const char *remoteAddress) { OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceforStateList"); if (!g_deviceStateList) { OIC_LOG(ERROR, TAG, "gdeviceStateList is null"); return; } if (!remoteAddress) { OIC_LOG(ERROR, TAG, "remoteAddress is null"); return; } jint length = u_arraylist_length(g_deviceStateList); for (jint index = 0; index < length; index++) { CAConnectedDeviceInfo_t* deviceInfo = (CAConnectedDeviceInfo_t*) u_arraylist_get(g_deviceStateList, index); if (!deviceInfo) { OIC_LOG(DEBUG, TAG, "deviceInfo object is null"); continue; } if (!strcmp((const char*) deviceInfo->address, remoteAddress)) { OIC_LOG_V(DEBUG, TAG, "remove state : %s", remoteAddress); OICFree(deviceInfo); u_arraylist_remove(g_deviceStateList, index); break; } } return; }
void CAEDRNativeRemoveDevice(const char *remoteAddress) { OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveDeviceforStateList"); if (!g_deviceStateList) { OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null"); return; } if (!remoteAddress) { OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null"); return; } jint index; jint length = u_arraylist_length(g_deviceStateList); for (index = 0; index < length; index++) { state_t* state = (state_t*) u_arraylist_get(g_deviceStateList, index); if (!state) { OIC_LOG(DEBUG, TAG, "[EDR][Native] state_t object is null"); continue; } if (!strcmp((const char*) state->address, remoteAddress)) { OIC_LOG_V(DEBUG, TAG, "[EDR][Native] remove state : %s", remoteAddress); OICFree(state); u_arraylist_remove(g_deviceStateList, index); break; } } return; }
CAResult_t CAManagerRemoveAllData(JNIEnv *env) { OIC_LOG(DEBUG, TAG, "IN-CAManagerRemoveAllData"); VERIFY_NON_NULL(env, TAG, "env"); ca_mutex_lock(g_deviceACDataListMutex); size_t length = u_arraylist_length(g_deviceACDataList); for (size_t idx = 0; idx < length; idx++) { CAManagerACData_t *curData = (CAManagerACData_t *) u_arraylist_get(g_deviceACDataList, idx); if (!curData) { OIC_LOG(ERROR, TAG, "curData is null"); ca_mutex_unlock(g_deviceACDataListMutex); return CA_STATUS_FAILED; } if (NULL == u_arraylist_remove(g_deviceACDataList, idx)) { OIC_LOG(ERROR, TAG, "removal has failed."); ca_mutex_unlock(g_deviceACDataListMutex); return CA_STATUS_FAILED; } if (curData->address) { (*env)->DeleteGlobalRef(env, curData->address); } OICFree(curData); } ca_mutex_unlock(g_deviceACDataListMutex); OIC_LOG(DEBUG, TAG, "OUT-CAManagerRemoveAllData"); return CA_STATUS_OK; }
CAResult_t CARemoveNetworkType(CATransportAdapter_t transportType) { OIC_LOG(DEBUG, TAG, "IN"); if (NULL == g_selectedNetworkList) { OIC_LOG(ERROR, TAG, "SelectedNetwork list is NULL"); return CA_STATUS_FAILED; } uint32_t selectedNetworkLength = u_arraylist_length(g_selectedNetworkList); for (uint32_t index = 0; index < selectedNetworkLength; index++) { void* ptrType = u_arraylist_get(g_selectedNetworkList, index); if (NULL == ptrType) { continue; } CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType; if (transportType == connType) { switch (transportType) { case CA_ADAPTER_IP: #ifndef IP_ADAPTER OIC_LOG(DEBUG, TAG, "Remove network type(IP) - Not Supported"); return CA_NOT_SUPPORTED; #else OIC_LOG(DEBUG, TAG, "Remove network type(IP)"); u_arraylist_remove(g_selectedNetworkList, index); #endif /* IP_ADAPTER */ break; case CA_ADAPTER_RFCOMM_BTEDR: #ifndef EDR_ADAPTER OIC_LOG(DEBUG, TAG, "Remove network type(EDR) - Not Supported"); return CA_NOT_SUPPORTED; #else OIC_LOG(DEBUG, TAG, "Remove network type(EDR)"); u_arraylist_remove(g_selectedNetworkList, index); #endif /* EDR_ADAPTER */ break; case CA_ADAPTER_GATT_BTLE: #ifndef LE_ADAPTER OIC_LOG(DEBUG, TAG, "Remove network type(LE) - Not Supported"); return CA_NOT_SUPPORTED; #else OIC_LOG(DEBUG, TAG, "Remove network type(LE)"); u_arraylist_remove(g_selectedNetworkList, index); #endif /* LE_ADAPTER */ break; default: break; } // stop selected interface adapter CAStopAdapter(connType); return CA_STATUS_OK; } } return CA_STATUS_FAILED; }
void CAIPSendNetworkChangeCallback(CANetworkStatus_t currNetworkStatus) { OIC_LOG(DEBUG, IP_MONITOR_TAG, "IN"); ca_mutex_lock(g_stopNetworkMonitorMutex); if (g_stopNetworkMonitor) { OIC_LOG(DEBUG, IP_MONITOR_TAG, "Stop Network Monitor Thread is called"); ca_mutex_unlock(g_stopNetworkMonitorMutex); return; } ca_mutex_unlock(g_stopNetworkMonitorMutex); ca_mutex_lock(g_networkMonitorContextMutex); if (!g_networkMonitorContext) { OIC_LOG(ERROR, IP_MONITOR_TAG, "g_networkMonitorContext is NULL"); ca_mutex_unlock(g_networkMonitorContextMutex); return; } if (!g_networkMonitorContext->networkChangeCb) { OIC_LOG(ERROR, IP_MONITOR_TAG, "g_networkMonitorContext->networkChangeCb is NULL"); ca_mutex_unlock(g_networkMonitorContextMutex); return; } ca_mutex_unlock(g_networkMonitorContextMutex); u_arraylist_t *netInterfaceList = u_arraylist_create(); VERIFY_NON_NULL_VOID(netInterfaceList, IP_MONITOR_TAG, "memory allocation failed for netInterfaceList"); // if network status is changed CAResult_t ret = CAIPUpdateInterfaceInformation(&netInterfaceList); if (CA_STATUS_OK != ret) { OIC_LOG(ERROR, IP_MONITOR_TAG, "could not update interface information"); } ca_mutex_lock(g_networkMonitorContextMutex); if (!g_networkMonitorContext->netInterfaceList) { OIC_LOG(ERROR, IP_MONITOR_TAG, "u_arraylist_create failed. Network Monitor thread stopped"); CAClearNetInterfaceInfoList(netInterfaceList); ca_mutex_unlock(g_networkMonitorContextMutex); return; } uint32_t listLength = u_arraylist_length(g_networkMonitorContext->netInterfaceList); for (uint32_t listIndex = 0; listIndex < listLength;) { CANetInfo_t *info = (CANetInfo_t *) u_arraylist_get( g_networkMonitorContext->netInterfaceList, listIndex); if (!info) { listIndex++; continue; } bool ret = CACheckIsAnyInterfaceDown(netInterfaceList, info); if (ret) { OIC_LOG(DEBUG, IP_MONITOR_TAG, "Interface is down"); if (u_arraylist_remove(g_networkMonitorContext->netInterfaceList, listIndex)) { OIC_LOG(DEBUG, IP_MONITOR_TAG, "u_arraylist_remove success"); if (g_networkMonitorContext->networkChangeCb) { g_networkMonitorContext->networkChangeCb(info->ipAddress, CA_INTERFACE_DOWN); } OICFree(info); listLength--; } else { OIC_LOG(ERROR, IP_MONITOR_TAG, "u_arraylist_remove failed"); break; } } else { listIndex++; } } ca_mutex_unlock(g_networkMonitorContextMutex); listLength = u_arraylist_length(netInterfaceList); for (uint32_t listIndex = 0; listIndex < listLength; listIndex++) { CANetInfo_t *info = (CANetInfo_t *) u_arraylist_get(netInterfaceList, listIndex); if (!info) { continue; } bool ret = CACheckIsInterfaceInfoChanged(info); if (ret) { OIC_LOG(DEBUG, IP_MONITOR_TAG, "CACheckIsInterfaceInfoChanged true"); } } CAClearNetInterfaceInfoList(netInterfaceList); OIC_LOG(DEBUG, IP_MONITOR_TAG, "OUT"); }
static bool CACheckIsInterfaceInfoChanged(const CANetInfo_t *info) { VERIFY_NON_NULL_RET(info, IP_MONITOR_TAG, "info is null", false); ca_mutex_lock(g_networkMonitorContextMutex); uint32_t list_length = u_arraylist_length(g_networkMonitorContext->netInterfaceList); for (uint32_t list_index = 0; list_index < list_length; list_index++) { CANetInfo_t *netInfo = (CANetInfo_t *) u_arraylist_get( g_networkMonitorContext->netInterfaceList, list_index); if (!netInfo) { continue; } if (strncmp(netInfo->interfaceName, info->interfaceName, strlen(info->interfaceName)) == 0) { if (strncmp(netInfo->ipAddress, info->ipAddress, strlen(info->ipAddress)) == 0) { ca_mutex_unlock(g_networkMonitorContextMutex); return false; } else { OIC_LOG(DEBUG, IP_MONITOR_TAG, "Network interface info changed"); if (u_arraylist_remove(g_networkMonitorContext->netInterfaceList, list_index)) { if (g_networkMonitorContext->networkChangeCb) { g_networkMonitorContext->networkChangeCb(netInfo->ipAddress, CA_INTERFACE_DOWN); } OICFree(netInfo); } else { OIC_LOG(ERROR, IP_MONITOR_TAG, "u_arraylist_remove failed"); } break; } } } CANetInfo_t *newNetInfo = (CANetInfo_t *) OICMalloc(sizeof(CANetInfo_t)); if (!newNetInfo) { OIC_LOG(ERROR, IP_MONITOR_TAG, "newNetInfo malloc failed"); ca_mutex_unlock(g_networkMonitorContextMutex); return false; } *newNetInfo = *info; OIC_LOG(DEBUG, IP_MONITOR_TAG, "New Interface found"); CAResult_t result = u_arraylist_add(g_networkMonitorContext->netInterfaceList, (void *) newNetInfo); if (CA_STATUS_OK != result) { OIC_LOG(ERROR, IP_MONITOR_TAG, "u_arraylist_add failed!"); OICFree(newNetInfo); ca_mutex_unlock(g_networkMonitorContextMutex); return false; } ca_mutex_unlock(g_networkMonitorContextMutex); /*Callback will be unset only at the time of termination. By that time, all the threads will be stopped gracefully. This callback is properly protected*/ if (g_networkMonitorContext->networkChangeCb) { g_networkMonitorContext->networkChangeCb(newNetInfo->ipAddress, CA_INTERFACE_UP); } return true; }
CAResult_t CARemoveNetworkType(CAConnectivityType_t connectivityType) { OIC_LOG(DEBUG, TAG, "IN"); if (g_selectedNetworkList == NULL) { OIC_LOG(DEBUG, TAG, "Selected network not found"); return CA_STATUS_FAILED; } uint8_t index; for (index = 0; index < u_arraylist_length(g_selectedNetworkList); index++) { void* ptrType = u_arraylist_get(g_selectedNetworkList, index); if (NULL == ptrType) { continue; } CAConnectivityType_t connType = *(CAConnectivityType_t *) ptrType; if (connectivityType == connType) { switch (connectivityType) { case CA_ETHERNET: #ifndef ETHERNET_ADAPTER OIC_LOG(DEBUG, TAG, "Remove network type(ETHERNET) - Not Supported"); return CA_NOT_SUPPORTED; #else OIC_LOG(DEBUG, TAG, "Remove network type(ETHERNET)"); u_arraylist_remove(g_selectedNetworkList, index); #endif /* ETHERNET_ADAPTER */ break; case CA_WIFI: #ifndef WIFI_ADAPTER OIC_LOG(DEBUG, TAG, "Remove network type(WIFI) - Not Supported"); return CA_NOT_SUPPORTED; #else OIC_LOG(DEBUG, TAG, "Remove network type(WIFI)"); u_arraylist_remove(g_selectedNetworkList, index); #endif /* WIFI_ADAPTER */ break; case CA_EDR: #ifndef EDR_ADAPTER OIC_LOG(DEBUG, TAG, "Remove network type(EDR) - Not Supported"); return CA_NOT_SUPPORTED; #else OIC_LOG(DEBUG, TAG, "Remove network type(EDR)"); u_arraylist_remove(g_selectedNetworkList, index); #endif /* EDR_ADAPTER */ break; case CA_LE: #ifndef LE_ADAPTER OIC_LOG(DEBUG, TAG, "Remove network type(LE) - Not Supported"); return CA_NOT_SUPPORTED; #else OIC_LOG(DEBUG, TAG, "Remove network type(LE)"); u_arraylist_remove(g_selectedNetworkList, index); #endif /* LE_ADAPTER */ break; } // stop selected interface adapter CAStopAdapter(connType); } } return CA_STATUS_OK; }
CAResult_t CAManagerRemoveData(JNIEnv *env, jstring jaddress) { OIC_LOG(DEBUG, TAG, "IN-CAManagerRemoveData"); VERIFY_NON_NULL(env, TAG, "env"); VERIFY_NON_NULL(jaddress, TAG, "jaddress"); ca_mutex_lock(g_deviceACDataListMutex); const char* address = (*env)->GetStringUTFChars(env, jaddress, NULL); if (!address) { OIC_LOG(ERROR, TAG, "address is null"); ca_mutex_unlock(g_deviceACDataListMutex); return CA_STATUS_FAILED; } OIC_LOG_V(DEBUG, TAG, "(%s) will be removed", address); size_t length = u_arraylist_length(g_deviceACDataList); for (size_t idx = 0; idx < length; idx++) { CAManagerACData_t *curData = (CAManagerACData_t *) u_arraylist_get(g_deviceACDataList, idx); if (!curData) { OIC_LOG(ERROR, TAG, "curData is null"); (*env)->ReleaseStringUTFChars(env, jaddress, address); ca_mutex_unlock(g_deviceACDataListMutex); return CA_STATUS_FAILED; } const char* setAddress = (*env)->GetStringUTFChars(env, curData->address, NULL); if (!setAddress) { OIC_LOG(ERROR, TAG, "address is null"); (*env)->ReleaseStringUTFChars(env, jaddress, address); ca_mutex_unlock(g_deviceACDataListMutex); return CA_STATUS_FAILED; } if (!strcmp(setAddress, address)) { if (NULL == u_arraylist_remove(g_deviceACDataList, idx)) { OIC_LOG(ERROR, TAG, "removal has failed."); (*env)->ReleaseStringUTFChars(env, jaddress, address); (*env)->ReleaseStringUTFChars(env, curData->address, setAddress); ca_mutex_unlock(g_deviceACDataListMutex); return CA_STATUS_FAILED; } (*env)->ReleaseStringUTFChars(env, curData->address, setAddress); if (curData->address) { (*env)->DeleteGlobalRef(env, curData->address); } OICFree(curData); (*env)->ReleaseStringUTFChars(env, jaddress, address); ca_mutex_unlock(g_deviceACDataListMutex); OIC_LOG(DEBUG, TAG, "remove done"); return CA_STATUS_OK; } (*env)->ReleaseStringUTFChars(env, curData->address, setAddress); } (*env)->ReleaseStringUTFChars(env, jaddress, address); ca_mutex_unlock(g_deviceACDataListMutex); OIC_LOG(DEBUG, TAG, "OUT-CAManagerRemoveData"); return CA_STATUS_OK; }