Пример #1
0
CAResult_t CAIPGetInterfaceInfo(u_arraylist_t **netInterfaceList)
{
    OIC_LOG(DEBUG, IP_MONITOR_TAG, "IN");

    VERIFY_NON_NULL(netInterfaceList, IP_MONITOR_TAG, "u_array_list is null");
    VERIFY_NON_NULL(g_networkMonitorContext, IP_MONITOR_TAG, "g_networkMonitorContext is null");
    VERIFY_NON_NULL(g_networkMonitorContextMutex, IP_MONITOR_TAG,
                    "g_networkMonitorContextMutex is null");

    // Get the interface and ipaddress information from cache
    ca_mutex_lock(g_networkMonitorContextMutex);
    if (!g_networkMonitorContext->netInterfaceList
        || !(u_arraylist_length(g_networkMonitorContext->netInterfaceList)))
    {
        OIC_LOG(ERROR, IP_MONITOR_TAG, "Network not enabled");
        ca_mutex_unlock(g_networkMonitorContextMutex);
        return CA_ADAPTER_NOT_ENABLED;
    }

    uint32_t list_length = u_arraylist_length(g_networkMonitorContext->netInterfaceList);
    OIC_LOG_V(DEBUG, IP_MONITOR_TAG, "CAIPGetInterfaceInfo list length [%d]",
            list_length);
    for (uint32_t list_index = 0; list_index < list_length; list_index++)
    {
        CANetInfo_t *info = (CANetInfo_t *) u_arraylist_get(
                g_networkMonitorContext->netInterfaceList, list_index);
        if (!info)
        {
            continue;
        }
        OIC_LOG_V(DEBUG, IP_MONITOR_TAG, "CAIPGetInterfaceInfo ip [%s]",
                  info->ipAddress);
        CANetInfo_t *newNetinfo = (CANetInfo_t *) OICMalloc(sizeof(CANetInfo_t));
        if (!newNetinfo)
        {
            OIC_LOG(ERROR, IP_MONITOR_TAG, "Malloc failed!");
            ca_mutex_unlock(g_networkMonitorContextMutex);
            return CA_MEMORY_ALLOC_FAILED;
        }

        *newNetinfo = *info;

        CAResult_t result = u_arraylist_add(*netInterfaceList, (void *) newNetinfo);
        if (CA_STATUS_OK != result)
        {
            OIC_LOG(ERROR, IP_MONITOR_TAG, "u_arraylist_add failed!");
            ca_mutex_unlock(g_networkMonitorContextMutex);
            return CA_STATUS_FAILED;
        }
    }

    ca_mutex_unlock(g_networkMonitorContextMutex);

    OIC_LOG(DEBUG, IP_MONITOR_TAG, "OUT");
    return CA_STATUS_OK;
}
Пример #2
0
CAResult_t CAIPGetInterfaceSubnetMask(const char *ipAddress, char **subnetMask)
{
    OIC_LOG(DEBUG, IP_MONITOR_TAG, "IN");

    VERIFY_NON_NULL(subnetMask, IP_MONITOR_TAG, "subnet mask");
    VERIFY_NON_NULL(ipAddress, IP_MONITOR_TAG, "ipAddress is null");
    VERIFY_NON_NULL(g_networkMonitorContext, IP_MONITOR_TAG, "g_networkMonitorContext is null");
    VERIFY_NON_NULL(g_networkMonitorContextMutex, IP_MONITOR_TAG,
                    "g_networkMonitorContextMutex is null");

    // Get the interface and ipaddress information from cache
    ca_mutex_lock(g_networkMonitorContextMutex);
    if (!g_networkMonitorContext->netInterfaceList
        || (0 == u_arraylist_length(g_networkMonitorContext->netInterfaceList)))
    {
        OIC_LOG(DEBUG, IP_MONITOR_TAG, "Network not enabled");
        ca_mutex_unlock(g_networkMonitorContextMutex);
        return CA_ADAPTER_NOT_ENABLED;
    }

    uint32_t list_length = u_arraylist_length(g_networkMonitorContext->netInterfaceList);
    OIC_LOG_V(DEBUG, IP_MONITOR_TAG, "list lenght [%d]", list_length);
    for (uint32_t list_index = 0; list_index < list_length; list_index++)
    {
        CANetInfo_t *info = (CANetInfo_t *) u_arraylist_get(
                g_networkMonitorContext->netInterfaceList, list_index);
        if (!info)
        {
            continue;
        }

        if (strncmp(info->ipAddress, ipAddress, strlen(ipAddress)) == 0)
        {
            if (!info->subnetMask)
            {
                OIC_LOG(ERROR, IP_MONITOR_TAG,
                        "CAIPGetInterfaceSubnetMask subnetmask is null");
            }
            OIC_LOG_V(DEBUG, IP_MONITOR_TAG,
                      "CAIPGetInterfaceSubnetMask subnetmask is %s", info->subnetMask);
            *subnetMask = info->subnetMask ? OICStrdup(info->subnetMask) : NULL;
            break;
        }
    }
    ca_mutex_unlock(g_networkMonitorContextMutex);

    OIC_LOG(DEBUG, IP_MONITOR_TAG, "OUT");
    return CA_STATUS_OK;
}
Пример #3
0
void CAEDRNativeRemoveAllDeviceState()
{
    OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveAllDevices");

    if (!g_deviceStateList)
    {
        OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList 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] jarrayObj is null");
            continue;
        }
        OICFree(state);
    }

    OICFree(g_deviceStateList);
    g_deviceStateList = NULL;
    return;
}
Пример #4
0
bool CAEDRNativeIsDeviceInList(const char* remoteAddress)
{

    if (!remoteAddress)
    {
        OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
        return false;
    }
    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(ERROR, TAG, "[EDR][Native] state_t object is null");
            return false;
        }

        if (!strcmp(remoteAddress, (const char*) state->address))
        {
            OIC_LOG(DEBUG, TAG, "the device is already set");
            return true;
        }
        else
        {
            continue;
        }
    }

    OIC_LOG(DEBUG, TAG, "there are no the device in list.");
    return false;
}
CAResult_t CADetachRequestMessage(const CAEndpoint_t *object, const CARequestInfo_t *request)
{
    OIC_LOG(DEBUG, TAG, "IN");

    VERIFY_NON_NULL(object, TAG, "object");
    VERIFY_NON_NULL(request, TAG, "request");

    // If max retransmission queue is reached, then don't handle new request
    if (CA_MAX_RT_ARRAY_SIZE == u_arraylist_length(g_retransmissionContext.dataList))
    {
        OIC_LOG(ERROR, TAG, "max RT queue size reached!");
        return CA_SEND_FAILED;
    }

    // allocate & initialize
    CAData_t *data = (CAData_t *) OICCalloc(1, sizeof(CAData_t));
    CA_MEMORY_ALLOC_CHECK(data);

    // save data
    data->type = request->isMulticast ? SEND_TYPE_MULTICAST : SEND_TYPE_UNICAST;
    data->remoteEndpoint = object;
    data->requestInfo = request;
    data->responseInfo = NULL;

    CAProcessData(data);
    OICFree(data);
    OIC_LOG(DEBUG, TAG, "OUT");
    return CA_STATUS_OK;

// memory error label.
memory_error_exit:
    OICFree(data);
    OIC_LOG(DEBUG, TAG, "OUT");
    return CA_MEMORY_ALLOC_FAILED;
}
jstring CAManagerGetLEAddressFromACData(JNIEnv *env, size_t idx)
{
    OIC_LOG(DEBUG, TAG, "CAManagerGetLEAddressFromACData");
    OIC_LOG_V(DEBUG, TAG, "idx : %d", idx);
    if (idx <= u_arraylist_length(g_deviceACDataList))
    {
        CAManagerACData_t *curData = (CAManagerACData_t *) u_arraylist_get(
                g_deviceACDataList, idx);
        if (!curData)
        {
            OIC_LOG(ERROR, TAG, "curData is null");
            return NULL;
        }

        const char* address = (*env)->GetStringUTFChars(env, curData->address, NULL);
        if (!address)
        {
            OIC_LOG(ERROR, TAG, "address is null");
            return NULL;
        }
        OIC_LOG_V(INFO, TAG, "found out target address : %s", address);
        (*env)->ReleaseStringUTFChars(env, curData->address, address);

        return curData->address;
    }
    return NULL;
}
Пример #7
0
CAConnectedState_t CAEDRIsConnectedDevice(const char *remoteAddress)
{
    OIC_LOG(DEBUG, TAG, "CAEDRIsConnectedDevice");

    if (!remoteAddress)
    {
        OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
        return STATE_DISCONNECTED;
    }

    if (!g_deviceStateList)
    {
        OIC_LOG(ERROR, TAG, "[EDR][Native] gdeviceStateList is null");
        return STATE_DISCONNECTED;
    }

    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))
        {
            return state->state;
        }
    }
    return STATE_DISCONNECTED;
}
Пример #8
0
void CAEDRNativeRemoveAllDeviceSocket(JNIEnv *env)
{
    OIC_LOG(DEBUG, TAG, "CANativeRemoveAllDeviceObjsList");

    if (!g_deviceObjectList)
    {
        OIC_LOG(ERROR, TAG, "gdeviceObjectList is null");
        return;
    }

    jint length = u_arraylist_length(g_deviceStateList);
    for (jint index = 0; index < length; index++)
    {
        jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
        if (!jarrayObj)
        {
            OIC_LOG(ERROR, TAG, "jarrayObj is null");
            return;
        }
        (*env)->DeleteGlobalRef(env, jarrayObj);
    }

    OICFree(g_deviceObjectList);
    g_deviceObjectList = NULL;
    return;
}
Пример #9
0
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;
    for (index = 0; index < u_arraylist_length(g_deviceStateList); 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(state->address, remoteAddress))
        {
            OIC_LOG_V(DEBUG, TAG, "[EDR][Native] remove state : %s", remoteAddress);
            OICFree(state);

            CAEDRReorderingDeviceList(index);
            break;
        }
    }
    return;
}
Пример #10
0
KeepAliveEntry_t *GetEntryFromEndpoint(const CAEndpoint_t *endpoint, uint32_t *index)
{
    if (!g_keepAliveConnectionTable)
    {
        OIC_LOG(ERROR, TAG, "KeepAlive Table was not Created.");
        return NULL;
    }

    uint32_t len = u_arraylist_length(g_keepAliveConnectionTable);

    for (uint32_t i = 0; i < len; i++)
    {
        KeepAliveEntry_t *entry = (KeepAliveEntry_t *)u_arraylist_get(g_keepAliveConnectionTable,
                                                                      i);
        if (NULL == entry)
        {
            continue;
        }

        if (!strncmp(entry->remoteAddr.addr, endpoint->addr, sizeof(entry->remoteAddr.addr))
                && (entry->remoteAddr.port == endpoint->port))
        {
            OIC_LOG(DEBUG, TAG, "Connection Info found in KeepAlive table");
            *index = i;
            return entry;
        }
    }

    return NULL;
}
Пример #11
0
CAResult_t CASendMulticastData(const CAEndpoint_t *endpoint, const void *data, uint32_t length)
{
    u_arraylist_t *list = CAGetSelectedNetworkList();
    if (!list)
    {
        OIC_LOG(DEBUG, TAG, "No selected network");
        return CA_SEND_FAILED;
    }

    CATransportFlags_t requestedAdapter = endpoint->adapter ? endpoint->adapter : CA_ALL_ADAPTERS;
    size_t selectedLength = u_arraylist_length(list);
    for (size_t i = 0; i < selectedLength; i++)
    {
        void* ptrType = u_arraylist_get(list, i);

        if(ptrType == NULL)
        {
            continue;
        }

        CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;
        if ((connType & requestedAdapter) == 0)
        {
            continue;
        }

        int index = CAGetAdapterIndex(connType);
        if (0 > index)
        {
            OIC_LOG(DEBUG, TAG, "unknown connectivity type!");
            continue;
        }

        uint32_t sentDataLen = 0;

        if (g_adapterHandler[index].sendDataToAll != NULL)
        {
            void *payload = (void *) OICMalloc(length);
            if (!payload)
            {
                OIC_LOG(ERROR, TAG, "Out of memory!");
                return CA_MEMORY_ALLOC_FAILED;
            }
            memcpy(payload, data, length);
            sentDataLen = g_adapterHandler[index].sendDataToAll(endpoint, payload, length);
            OICFree(payload);
        }

        if (sentDataLen != length)
        {
            OIC_LOG(ERROR, TAG, "sendDataToAll failed! Error will be reported from adapter");
#ifdef SINGLE_THREAD
            //in case of single thread, no error handler. Report error immediately
            return CA_SEND_FAILED;
#endif
        }
    }

    return CA_STATUS_OK;
}
Пример #12
0
CAConnectedDeviceInfo_t *CAEDRGetDeviceInfoFromAddress(const char *remoteAddress)
{
    OIC_LOG(DEBUG, TAG, "CAEDRGetDeviceInfoFromAddress");

    if (!g_deviceStateList)
    {
        OIC_LOG(ERROR, TAG, "gdeviceStateList is null");
        return NULL;
    }
    if (!remoteAddress)
    {
        OIC_LOG(ERROR, TAG, "remoteAddress is null");
        return NULL;
    }

    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))
        {
            return deviceInfo;
        }
    }
    return NULL;
}
Пример #13
0
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;
        }
    }
}
Пример #14
0
CAResult_t CAStopListeningServerAdapters()
{
    u_arraylist_t *list = CAGetSelectedNetworkList();
    if (!list)
    {
        OIC_LOG(ERROR, TAG, "No selected network");
        return CA_STATUS_FAILED;
    }

    size_t length = u_arraylist_length(list);
    for (size_t i = 0; i < length; i++)
    {
        void* ptrType = u_arraylist_get(list, i);
        if(ptrType == NULL)
        {
            continue;
        }

        CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;

        int index = CAGetAdapterIndex(connType);
        if (0 > index)
        {
            OIC_LOG(ERROR, TAG, "unknown connectivity type!");
            continue;
        }

        if (g_adapterHandler[index].stopListenServer != NULL)
        {
            g_adapterHandler[index].stopListenServer();
        }
    }

    return CA_STATUS_OK;
}
Пример #15
0
CAConnectedState_t CAEDRIsConnectedDevice(const char *remoteAddress)
{
    OIC_LOG(DEBUG, TAG, "CAEDRIsConnectedDevice");

    if (!remoteAddress)
    {
        OIC_LOG(ERROR, TAG, "remoteAddress is null");
        return STATE_DISCONNECTED;
    }

    if (!g_deviceStateList)
    {
        OIC_LOG(ERROR, TAG, "gdeviceStateList is null");
        return STATE_DISCONNECTED;
    }

    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))
        {
            return deviceInfo->state;
        }
    }
    return STATE_DISCONNECTED;
}
Пример #16
0
void CAEDRNativeRemoveAllDeviceState()
{
    OIC_LOG(DEBUG, TAG, "CAEDRNativeRemoveAllDevices");

    if (!g_deviceStateList)
    {
        OIC_LOG(ERROR, TAG, "gdeviceStateList is null");
        return;
    }

    jint index;
    jint length = u_arraylist_length(g_deviceStateList);
    for (index = 0; index < length; index++)
    {
        CAConnectedDeviceInfo_t* deviceInfo =
                (CAConnectedDeviceInfo_t*) u_arraylist_get(g_deviceStateList, index);
        if (!deviceInfo)
        {
            OIC_LOG(DEBUG, TAG, "jarrayObj is null");
            continue;
        }
        OICFree(deviceInfo);
    }

    OICFree(g_deviceStateList);
    g_deviceStateList = NULL;
    return;
}
Пример #17
0
bool CAEDRNativeIsDeviceInList(const char* remoteAddress)
{
    if (!remoteAddress)
    {
        OIC_LOG(ERROR, TAG, "remoteAddress is null");
        return false;
    }

    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(ERROR, TAG, "deviceInfo object is null");
            return false;
        }

        if (!strcmp(remoteAddress, (const char*) deviceInfo->address))
        {
            OIC_LOG(DEBUG, TAG, "the device is already set");
            return true;
        }
    }

    OIC_LOG(DEBUG, TAG, "there are no the device in list.");
    return false;
}
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;
}
Пример #19
0
static CASecureEndpoint_t *GetPeerInfo(const CAEndpoint_t *peer)
{
    uint32_t list_index = 0;
    uint32_t list_length = 0;

    if(NULL == peer)
    {
        OIC_LOG(ERROR, NET_DTLS_TAG, "CAPeerInfoListContains invalid parameters");
        return NULL;
    }

    CASecureEndpoint_t *peerInfo = NULL;
    list_length = u_arraylist_length(g_caDtlsContext->peerInfoList);
    for (list_index = 0; list_index < list_length; list_index++)
    {
        peerInfo = (CASecureEndpoint_t *)u_arraylist_get(g_caDtlsContext->peerInfoList, list_index);
        if (NULL == peerInfo)
        {
            continue;
        }

        if((0 == strncmp(peer->addr, peerInfo->endpoint.addr, MAX_ADDR_STR_SIZE_CA)) &&
                (peer->port == peerInfo->endpoint.port))
        {
            return peerInfo;
        }
    }
    return NULL;
}
Пример #20
0
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;
}
Пример #21
0
static void CAHandleNetlink()
{
#ifdef __linux__
    char buf[4096];
    struct nlmsghdr *nh;
    struct sockaddr_nl sa;
    struct iovec iov = { buf, sizeof (buf) };
    struct msghdr msg = { (void *)&sa, sizeof (sa), &iov, 1, NULL, 0, 0 };

    size_t len = recvmsg(caglobals.ip.netlinkFd, &msg, 0);

    for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len); nh = NLMSG_NEXT(nh, len))
    {
        if (nh->nlmsg_type != RTM_NEWLINK)
        {
            continue;
        }

        struct ifinfomsg *ifi = (struct ifinfomsg *)NLMSG_DATA(nh);
        if (!ifi || (ifi->ifi_flags & IFF_LOOPBACK) || !(ifi->ifi_flags & IFF_RUNNING))
        {
            continue;
        }

        int newIndex = ifi->ifi_index;

        u_arraylist_t *iflist = CAIPGetInterfaceInformation(newIndex);
        if (!iflist)
        {
            OIC_LOG_V(ERROR, TAG, "get interface info failed: %s", strerror(errno));
            return;
        }

        uint32_t listLength = u_arraylist_length(iflist);
        for (uint32_t i = 0; i < listLength; i++)
        {
            CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
            if (!ifitem)
            {
                continue;
            }

            if ((int)ifitem->index != newIndex)
            {
                continue;
            }

            CAProcessNewInterface(ifitem);
            break; // we found the one we were looking for
        }
        u_arraylist_destroy(iflist);
    }
#endif // __linux__
}
Пример #22
0
void CAManagerSetAutoConnectionFlag(JNIEnv *env, jstring jaddress, bool flag)
{
    OIC_LOG(DEBUG, TAG, "IN-CAManagerSetAutoConnectionFlag");
    VERIFY_NON_NULL_VOID(env, TAG, "env");
    VERIFY_NON_NULL_VOID(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;
    }

    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;
        }

        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;
        }

        if (!strcmp(setAddress, address))
        {
            OIC_LOG_V(DEBUG, TAG, "flag is set to %d", flag);
            curData->isAutoConnect = flag;
            (*env)->ReleaseStringUTFChars(env, curData->address, setAddress);
            (*env)->ReleaseStringUTFChars(env, jaddress, address);
            ca_mutex_unlock(g_deviceACDataListMutex);
            return;
        }
        (*env)->ReleaseStringUTFChars(env, curData->address, setAddress);
    }
    (*env)->ReleaseStringUTFChars(env, jaddress, address);
    ca_mutex_unlock(g_deviceACDataListMutex);

    OIC_LOG(DEBUG, TAG, "OUT-CAManagerSetAutoConnectionFlag");
}
Пример #23
0
static bool CAIsSelectedNetworkAvailable()
{
    u_arraylist_t *list = CAGetSelectedNetworkList();
    if (!list || u_arraylist_length(list) == 0)
    {
        OIC_LOG(ERROR, TAG, "No selected network");
        return false;
    }

    return true;
}
Пример #24
0
static void CAFreePeerInfoList()
{
    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);
        OICFree(peerInfo);
    }
    u_arraylist_free(&(g_caDtlsContext->peerInfoList));
    g_caDtlsContext->peerInfoList = NULL;
}
Пример #25
0
uint32_t CAEDRGetSocketListLength()
{
    if (!g_deviceObjectList)
    {
        OIC_LOG(ERROR, TAG, "gdeviceObjectList is null");
        return 0;
    }

    uint32_t length = u_arraylist_length(g_deviceObjectList);

    return length;
}
Пример #26
0
bool CAEDRNativeIsDeviceSocketInList(JNIEnv *env, const char* remoteAddress)
{
    OIC_LOG(DEBUG, TAG, "CANativeIsDeviceObjInList");

    if (!remoteAddress)
    {
        OIC_LOG(ERROR, TAG, "remoteAddress is null");
        return false;
    }

    jint length = u_arraylist_length(g_deviceStateList);
    for (jint index = 0; index < length; index++)
    {

        jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
        if (!jarrayObj)
        {
            OIC_LOG(DEBUG, TAG, "jarrayObj is null");
            return false;
        }

        jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
        if (!jni_setAddress)
        {
            OIC_LOG(DEBUG, TAG, "jni_setAddress is null");
            return false;
        }

        const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
        if (!setAddress)
        {
            OIC_LOG(DEBUG, TAG, "setAddress is null");
            return false;
        }

        if (!strcmp(remoteAddress, setAddress))
        {
            OIC_LOG(DEBUG, TAG, "the device is already set");
            (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
            return true;
        }
        else
        {
            (*env)->ReleaseStringUTFChars(env, jni_setAddress, setAddress);
            continue;
        }
    }

    OIC_LOG(DEBUG, TAG, "there are no the Device obejct in list. we can add");
    return false;
}
Пример #27
0
CAResult_t CAStartDiscoveryServerAdapters()
{
    OIC_LOG(DEBUG, TAG, "IN");

    CAResult_t result = CA_STATUS_FAILED;

    u_arraylist_t *list = CAGetSelectedNetworkList();

    if (!list)
    {
        OIC_LOG(ERROR, TAG, "No selected network");
        return result;
    }

    size_t length = u_arraylist_length(list);
    for (size_t i = 0; i < length; i++)
    {
        void* ptrType = u_arraylist_get(list, i);

        if(ptrType == NULL)
        {
            continue;
        }

        CATransportAdapter_t connType = *(CATransportAdapter_t *)ptrType;

        int index = CAGetAdapterIndex(connType);
        if (0 > index)
        {
            OIC_LOG(DEBUG, TAG, "unknown connectivity type!");
            continue;
        }

        if (g_adapterHandler[index].startDiscoveryServer != NULL)
        {
            const CAResult_t tmp =
                g_adapterHandler[index].startDiscoveryServer();

            // Successful discovery if at least one adapter started.
            if (CA_STATUS_OK == tmp)
            {
                result = tmp;
            }
        }
    }

    OIC_LOG(DEBUG, TAG, "OUT");
    return result;
}
CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
{
    OIC_LOG(DEBUG, TAG, "IN");

    VERIFY_NON_NULL(info, TAG, "info is NULL");
    VERIFY_NON_NULL(size, TAG, "size is NULL");

    u_arraylist_t *iflist = CAIPGetInterfaceInformation(0);
    if (!iflist)
    {
        OIC_LOG(ERROR, TAG, "get interface info failed");
        return CA_STATUS_FAILED;
    }

    uint32_t len = u_arraylist_length(iflist);

    CAEndpoint_t *eps = (CAEndpoint_t *)OICCalloc(len, sizeof (CAEndpoint_t));
    if (!eps)
    {
        OIC_LOG(ERROR, TAG, "Malloc Failed");
        u_arraylist_destroy(iflist);
        return CA_MEMORY_ALLOC_FAILED;
    }

    for (uint32_t i = 0, j = 0; i < len; i++)
    {
        CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
        if(!ifitem)
        {
            continue;
        }
        unsigned char *addr=  (unsigned char *) &(ifitem->ipv4addr);
        snprintf(eps[j].addr, MAX_ADDR_STR_SIZE_CA, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);

        eps[j].flags = CA_IPV4;
        eps[j].adapter = CA_ADAPTER_IP;
        eps[j].interface = 0;
        eps[j].port = caglobals.ip.u4.port;
        j++;
    }

    *info = eps;
    *size = len;

    u_arraylist_destroy(iflist);

    OIC_LOG(DEBUG, TAG, "OUT");
    return CA_STATUS_OK;
}
Пример #29
0
CAResult_t CAGetIPInterfaceInformation(CAEndpoint_t **info, uint32_t *size)
{
    OIC_LOG(DEBUG, TAG, "IN");

    VERIFY_NON_NULL(info, TAG, "info is NULL");
    VERIFY_NON_NULL(size, TAG, "size is NULL");

    u_arraylist_t *iflist = CAIPGetInterfaceInformation(0);
    if (!iflist)
    {
        OIC_LOG_V(ERROR, TAG, "get interface info failed: %s", strerror(errno));
        return CA_STATUS_FAILED;
    }

    uint32_t len = u_arraylist_length(iflist);

    CAEndpoint_t *eps = (CAEndpoint_t *)OICCalloc(len, sizeof (CAEndpoint_t));
    if (!eps)
    {
        OIC_LOG(ERROR, TAG, "Malloc Failed");
        u_arraylist_destroy(iflist);
        return CA_MEMORY_ALLOC_FAILED;
    }

    for (uint32_t i = 0, j = 0; i < len; i++)
    {
        CAInterface_t *ifitem = (CAInterface_t *)u_arraylist_get(iflist, i);
        if(!ifitem)
        {
            continue;
        }

        OICStrcpy(eps[j].addr, CA_INTERFACE_NAME_SIZE, ifitem->name);
        eps[j].flags = ifitem->family == AF_INET6 ? CA_IPV6 : CA_IPV4;
        eps[j].adapter = CA_ADAPTER_IP;
        eps[j].interface = 0;
        eps[j].port = 0;
        j++;
    }

    *info = eps;
    *size = len;

    u_arraylist_destroy(iflist);

    OIC_LOG(DEBUG, TAG, "OUT");
    return CA_STATUS_OK;
}
Пример #30
0
jboolean CAEDRNativeIsDeviceSocketInList(JNIEnv *env, const char* remoteAddress)
{
    OIC_LOG(DEBUG, TAG, "[EDR][Native] CANativeIsDeviceObjInList");

    jint index;

    if (!remoteAddress) {
        OIC_LOG(ERROR, TAG, "[EDR][Native] remoteAddress is null");
        return JNI_TRUE;
    }
    for (index = 0; index < u_arraylist_length(g_deviceObjectList); index++)
    {

        jobject jarrayObj = (jobject) u_arraylist_get(g_deviceObjectList, index);
        if(!jarrayObj)
        {
            OIC_LOG(DEBUG, TAG, "[EDR][Native] jarrayObj is null");
            return JNI_TRUE;
        }

        jstring jni_setAddress = CAEDRNativeGetAddressFromDeviceSocket(env, jarrayObj);
        if(!jni_setAddress)
        {
            OIC_LOG(DEBUG, TAG, "[EDR][Native] jni_setAddress is null");
            return JNI_TRUE;
        }

        const char* setAddress = (*env)->GetStringUTFChars(env, jni_setAddress, NULL);
        if(!setAddress)
        {
            OIC_LOG(DEBUG, TAG, "[EDR][Native] setAddress is null");
            return JNI_TRUE;
        }

        if(!strcmp(remoteAddress, setAddress))
        {
            OIC_LOG(DEBUG, TAG, "the device is already set");
            return JNI_TRUE;
        }
        else
        {
            continue;
        }
    }

    OIC_LOG(DEBUG, TAG, "there are no the Device obejct in list. we can add");
    return JNI_FALSE;
}