Example #1
0
//--------------------------------------------------------------------------------------------------
static void DisconnectedProfile
(
    le_mdc_ProfileRef_t profileRef
)
{
    char ipAddrStr[IP_STR_SIZE];
    char dns1AddrStr[IP_STR_SIZE];
    char dns2AddrStr[IP_STR_SIZE];
    char gatewayAddrStr[IP_STR_SIZE];
    char interfaceName[10];

    /* Expected value: LE_FAULT as the frofile is supposed to be disconnected */

    LE_ASSERT(le_mdc_GetInterfaceName(profileRef, interfaceName, sizeof(interfaceName))
                                                                                    == LE_FAULT);
    LE_ASSERT(le_mdc_GetIPv4Address(profileRef, ipAddrStr, IP_STR_SIZE) == LE_FAULT);
    LE_ASSERT(le_mdc_GetIPv6Address(profileRef, ipAddrStr, IP_STR_SIZE) == LE_FAULT);
    LE_ASSERT(le_mdc_GetIPv4DNSAddresses(   profileRef,
                                            dns1AddrStr,
                                            IP_STR_SIZE,
                                            dns2AddrStr,
                                            IP_STR_SIZE) == LE_FAULT);
    LE_ASSERT(le_mdc_GetIPv6DNSAddresses(   profileRef,
                                            dns1AddrStr,
                                            IP_STR_SIZE,
                                            dns2AddrStr,
                                            IP_STR_SIZE) == LE_OVERFLOW);
    LE_ASSERT(le_mdc_GetIPv4GatewayAddress( profileRef, gatewayAddrStr, IP_STR_SIZE )
                                                                                    == LE_FAULT);
    LE_ASSERT(le_mdc_GetIPv6GatewayAddress( profileRef, gatewayAddrStr, IP_STR_SIZE )
                                                                                    == LE_FAULT);

}
Example #2
0
//--------------------------------------------------------------------------------------------------
static void TestMdc_Connection ( void )
{
    int i;
    le_result_t res;
    le_mdc_Pdp_t pdp = LE_MDC_PDP_IPV4;
    char ipAddrStrIpv4[]="192.168.1.100";
    char dns1AddrStrIpv4[]="10.40.50.1";
    char dns2AddrStrIpv4[]="10.40.50.2";
    char gatewayAddrStrIpv4[]="192.168.100.123";
    char ipAddrStrIpv6[]="2001:0000:3238:DFE1:63::FEFB";
    char dns1AddrStrIpv6[]="2001:4860:4860::8888";
    char dns2AddrStrIpv6[]="2001:4860:4860::8844";
    char gatewayAddrStrIpv6[]="2001:CDBA:0:0:0:0:3257:9652";
    char interfaceName[]="rmnet0";
    char addr[LE_MDC_IPV6_ADDR_MAX_BYTES]="";
    char addr2[LE_MDC_IPV6_ADDR_MAX_BYTES]="";

    /* All profile are disconnected: check connectivities API returns LE_FAULT */
    for (i=0; i < NB_PROFILE; i++)
    {
        DisconnectedProfile(ProfileRef[i]);
    }

    /* Test for all IP type: IPv4, IPv6, IPv4v6 */
    while(pdp <= LE_MDC_PDP_IPV4V6)
    {
        /* check connection status: supposed to be disconnected */
        le_mdc_ConState_t state;
        res = le_mdc_GetSessionState(ProfileRef[0], &state);
        LE_ASSERT(res == LE_OK);
        LE_ASSERT(state == LE_MDC_DISCONNECTED);

        /* Set the new pdp type */
        res = le_mdc_SetPDP(ProfileRef[0], pdp);
        LE_ASSERT(res == LE_OK);

        /* start a session*/
        res = le_mdc_StartSession(ProfileRef[0]);
        LE_ASSERT(res == LE_OK);

        /* Check connection status: supposed to be connected */
        res = le_mdc_GetSessionState(ProfileRef[0], &state);
        LE_ASSERT(res == LE_OK);
        LE_ASSERT(state == LE_MDC_CONNECTED);

        /* check connection status for other profile (supposed to be disconnected) */
        for (i = 1; i < NB_PROFILE; i++)
        {
            res = le_mdc_GetSessionState(ProfileRef[i], &state);
            LE_ASSERT(res == LE_OK);
            LE_ASSERT(state == LE_MDC_DISCONNECTED);

            /* check connectivty parameters */
            DisconnectedProfile(ProfileRef[i]);
        }

        /* configure an interfacen ame in the pa_mdcSimu, and test the API */
        char interfaceNameTmp[20];
        pa_mdcSimu_SetInterfaceName(1, interfaceName);
        LE_ASSERT(le_mdc_GetInterfaceName(ProfileRef[0],interfaceNameTmp,sizeof(interfaceNameTmp))
                                                                                        == LE_OK);
        LE_ASSERT( strcmp(interfaceNameTmp, interfaceName) == 0);

        /* Check IP type */
        switch (pdp)
        {
            case LE_MDC_PDP_IPV4:
                /* configure the pa_mdcSimu with IPv4 addresses */
                pa_mdcSimu_SetIPAddress(1, LE_MDMDEFS_IPV4, ipAddrStrIpv4);
                pa_mdcSimu_SetDNSAddresses(1, LE_MDMDEFS_IPV4, dns1AddrStrIpv4, dns2AddrStrIpv4);
                pa_mdcSimu_SetGatewayAddress(1, LE_MDMDEFS_IPV4, gatewayAddrStrIpv4);

                /* Check IPv4 and IPv6 connectivities:
                 * all IPv6 APIs return an error
                 * IPv4 APIs return expected value
                 */
                LE_ASSERT(le_mdc_IsIPv4(ProfileRef[0]) == true);
                LE_ASSERT(le_mdc_IsIPv6(ProfileRef[0]) == false);

                LE_ASSERT(le_mdc_GetIPv4Address(ProfileRef[0], addr, sizeof(addr) ) == LE_OK);
                LE_ASSERT( strcmp(addr,ipAddrStrIpv4)==0 );
                LE_ASSERT(le_mdc_GetIPv6Address(ProfileRef[0], addr, sizeof(addr) ) == LE_FAULT);
                LE_ASSERT(le_mdc_GetIPv4DNSAddresses(ProfileRef[0], addr,
                                                                    sizeof(addr),
                                                                    addr2,
                                                                    sizeof(addr) ) == LE_OK);
                LE_ASSERT(le_mdc_GetIPv4DNSAddresses(ProfileRef[0], addr,
                                                                    3,
                                                                    addr2,
                                                                    sizeof(addr) ) == LE_OVERFLOW);
                LE_ASSERT(le_mdc_GetIPv4DNSAddresses(ProfileRef[0], addr,
                                                                    sizeof(addr),
                                                                    addr2,
                                                                    3 ) == LE_OVERFLOW);

                LE_ASSERT( strcmp(addr,dns1AddrStrIpv4)==0 );
                LE_ASSERT( strcmp(addr2,dns2AddrStrIpv4)==0 );
                LE_ASSERT(le_mdc_GetIPv6DNSAddresses(ProfileRef[0], addr,
                                                                    sizeof(addr),
                                                                    addr2,
                                                                    sizeof(addr2) ) == LE_FAULT);

                LE_ASSERT(le_mdc_GetIPv6DNSAddresses(ProfileRef[0], addr,
                                                                    5,
                                                                    addr2,
                                                                    sizeof(addr2) ) == LE_OVERFLOW);

                LE_ASSERT(le_mdc_GetIPv6DNSAddresses(ProfileRef[0], addr,
                                                                    sizeof(addr),
                                                                    addr2,
                                                                    5 ) == LE_OVERFLOW);

                LE_ASSERT(le_mdc_GetIPv4GatewayAddress(ProfileRef[0], addr, sizeof(addr)) == LE_OK);
                LE_ASSERT( strcmp(addr,gatewayAddrStrIpv4)==0 );
                LE_ASSERT(le_mdc_GetIPv6GatewayAddress(ProfileRef[0], addr, sizeof(addr)) ==
                                                                                        LE_FAULT);
            break;
            case LE_MDC_PDP_IPV6:
                /* configure the pa_mdcSimu with IPv6 addresses */
                pa_mdcSimu_SetIPAddress(1, LE_MDMDEFS_IPV6, ipAddrStrIpv6);
                pa_mdcSimu_SetDNSAddresses(1, LE_MDMDEFS_IPV6, dns1AddrStrIpv6, dns2AddrStrIpv6);
                pa_mdcSimu_SetGatewayAddress(1, LE_MDMDEFS_IPV6, gatewayAddrStrIpv6);

                /* Check IPv4 and IPv6 connectivities:
                 * all IPv4 APIs return an error
                 * IPv6 APIs return expected value
                 */
                LE_ASSERT(le_mdc_IsIPv4(ProfileRef[0]) == false);
                LE_ASSERT(le_mdc_IsIPv6(ProfileRef[0]) == true);

                LE_ASSERT(le_mdc_GetIPv6Address(ProfileRef[0], addr, sizeof(addr) ) == LE_OK);
                LE_ASSERT( strcmp(addr,ipAddrStrIpv6)==0 );
                LE_ASSERT(le_mdc_GetIPv4Address(ProfileRef[0], addr, sizeof(addr) ) == LE_FAULT);
                LE_ASSERT(le_mdc_GetIPv6DNSAddresses(ProfileRef[0], addr,
                                                                    sizeof(addr),
                                                                    addr2,
                                                                    sizeof(addr2) ) == LE_OK);
                LE_ASSERT( strcmp(addr,dns1AddrStrIpv6)==0 );
                LE_ASSERT( strcmp(addr2,dns2AddrStrIpv6)==0 );
                LE_ASSERT(le_mdc_GetIPv4DNSAddresses(ProfileRef[0], addr,
                                                                    sizeof(addr),
                                                                    addr2,
                                                                    sizeof(addr2) ) == LE_FAULT);
                LE_ASSERT(le_mdc_GetIPv6GatewayAddress(ProfileRef[0], addr, sizeof(addr)) == LE_OK);
                LE_ASSERT( strcmp(addr,gatewayAddrStrIpv6)==0 );
                LE_ASSERT(le_mdc_GetIPv4GatewayAddress(ProfileRef[0], addr, sizeof(addr)) ==
                                                                                        LE_FAULT);
            break;
            case LE_MDC_PDP_IPV4V6:
                /* Check IPv4 and IPv6 connectivities:
                 * IPv4 and IPv6 APIs return expected value
                 */
                LE_ASSERT(le_mdc_IsIPv4(ProfileRef[0]) == true);
                LE_ASSERT(le_mdc_IsIPv6(ProfileRef[0]) == true);

                LE_ASSERT(le_mdc_GetIPv6Address(ProfileRef[0], addr, sizeof(addr) ) == LE_OK);
                LE_ASSERT( strcmp(addr,ipAddrStrIpv6) == 0 );
                LE_ASSERT(le_mdc_GetIPv4Address(ProfileRef[0], addr, sizeof(addr) ) == LE_OK);
                LE_ASSERT( strcmp(addr,ipAddrStrIpv4) == 0 );
                LE_ASSERT(le_mdc_GetIPv6DNSAddresses(ProfileRef[0], addr,
                                                                    sizeof(addr),
                                                                    addr2,
                                                                    sizeof(addr2) ) == LE_OK);
                LE_ASSERT( strcmp(addr,dns1AddrStrIpv6) == 0 );
                LE_ASSERT( strcmp(addr2,dns2AddrStrIpv6) == 0 );
                LE_ASSERT(le_mdc_GetIPv4DNSAddresses(ProfileRef[0], addr,
                                                                    sizeof(addr),
                                                                    addr2,
                                                                    sizeof(addr2) ) == LE_OK);
                LE_ASSERT( strcmp(addr,dns1AddrStrIpv4) == 0 );
                LE_ASSERT( strcmp(addr2,dns2AddrStrIpv4) == 0 );
                LE_ASSERT(le_mdc_GetIPv6GatewayAddress(ProfileRef[0], addr, sizeof(addr)) == LE_OK);
                LE_ASSERT( strcmp(addr,gatewayAddrStrIpv6) == 0 );
                LE_ASSERT(le_mdc_GetIPv4GatewayAddress(ProfileRef[0], addr, sizeof(addr)) ==
                                                                                        LE_OK);
                LE_ASSERT( strcmp(addr,gatewayAddrStrIpv4) == 0 );
            break;
            default:
                LE_ASSERT(0);
            break;
        }

        /* stop the session */
        res = le_mdc_StopSession(ProfileRef[0]);
        LE_ASSERT(res == LE_OK);

        /* next pdp type */
        pdp++;
    }
}
Example #3
0
// -------------------------------------------------------------------------------------------------
static void Netinfo
(
    char* buffer   ///< [OUT] On success or failure, a message is written to this buffer.
)
{
    uint32_t bufferIndex = 0;
    // hard coded, first profile.
    le_mdc_ProfileRef_t profileRef = le_mdc_GetProfile(1);

    if (profileRef == NULL)
    {
        bufferIndex += sprintf(&buffer[bufferIndex], "Failed to open profile.");
        return;
    }

    char interfaceName[100];
    char gatewayAddr[100];
    char dns1Addr[100];
    char dns2Addr[100];

    if (le_mdc_GetInterfaceName(profileRef, interfaceName, sizeof(interfaceName)) != LE_OK)
    {
        bufferIndex += sprintf(&buffer[bufferIndex], "Failed to get interface name.");
        interfaceName[0] = '\0';
        return;
    }

    if ( le_mdc_IsIPv4(profileRef) )
    {
        if (le_mdc_GetIPv4GatewayAddress(profileRef, gatewayAddr, sizeof(gatewayAddr)) != LE_OK)
        {
            bufferIndex += sprintf(&buffer[bufferIndex], "Failed to get gateway address.");
            gatewayAddr[0] = '\0';
            return;
        }

        if (le_mdc_GetIPv4DNSAddresses(profileRef,
                                   dns1Addr, sizeof(dns1Addr),
                                   dns2Addr, sizeof(dns2Addr)) != LE_OK)
        {
            bufferIndex += sprintf(&buffer[bufferIndex], "Failed to read DNS addresses.");
            dns1Addr[0] = '\0';
            dns2Addr[0] = '\0';
            return;
        }

        bufferIndex += sprintf(&buffer[bufferIndex],
                               "\nIPV4 GW: %s, DNS1: %s, DNS2: %s on %s",
                               gatewayAddr, dns1Addr, dns2Addr, interfaceName);
    }

    if ( le_mdc_IsIPv6(profileRef) )
    {
        if (le_mdc_GetIPv6GatewayAddress(profileRef, gatewayAddr, sizeof(gatewayAddr)) != LE_OK)
        {
            bufferIndex += sprintf(&buffer[bufferIndex], "Failed to get gateway address.");
            gatewayAddr[0] = '\0';
            return;
        }

        if (le_mdc_GetIPv6DNSAddresses(profileRef,
                                   dns1Addr, sizeof(dns1Addr),
                                   dns2Addr, sizeof(dns2Addr)) != LE_OK)
        {
            bufferIndex += sprintf(&buffer[bufferIndex], "Failed to read DNS addresses.");
            dns1Addr[0] = '\0';
            dns2Addr[0] = '\0';
            return;
        }

        bufferIndex += sprintf(&buffer[bufferIndex],
                               "\nIPV6 GW: %s, DNS1: %s, DNS2: %s on %s",
                               gatewayAddr, dns1Addr, dns2Addr, interfaceName);
    }

}