javacommons/gcfprotocols/socket/socket/src.s60/apnsettings.cpp
author hgs
Fri, 29 Oct 2010 11:49:32 +0300
changeset 87 1627c337e51e
parent 67 63b81d807542
permissions -rw-r--r--
v2.2.21_1

/*
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  ApnSettings.app
*
*/



#include <string>
#include<stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include "logger.h"
#include "apnsettings.h"

using namespace java;

int ApnSettings::setDefaultApn(int aType, int aApn)
{
    struct ifreq  ifr;
    int def = 0;

#ifdef RD_JAVA_OPENC_BETA_PATCH
    if (aType == 2 || aType == 3)
    {
        if (aType == 3) // IAP ID
        {
            char * interfacename = new char[512];

            char * fret = if_indextoname(aApn,interfacename);
            strcpy(ifr.ifr_name, interfacename);
            ILOG1(ESOCKET, "interface name is %s",interfacename);
            delete[] interfacename;
        }
        else
        {
            if (aType == 2) // SNAP ID
            {
                memset(&ifr, 0, sizeof(struct ifreq));
                ifr.ifr_ifru.snap_id = aApn;
            }
        }
        def = setdefaultif(&ifr);
        ILOG(ESOCKET, "sedefaultif called");
    }
    ILOG1(ESOCKET, "sedefaultif returned %d",def);
    // if(def == -1)
    //{
    //      LOG(ESOCKET, "default access point interface is removed");
    //      setdefaultif(NULL);
    //}
#endif


    return def;
}

void ApnSettings::removeDefaultApn()
{ 
    #ifdef RD_JAVA_OPENC_BETA_PATCH
        setdefaultif(0);
        ILOG(ESOCKET, "sedefaultif called");
        ILOG1(ESOCKET, "remove default apn returned %d",setdefaultif(NULL));
    #endif  
}
int ApnSettings::retryConnection(int aErrCode, int aType, int aApn)
{
    if ( aErrCode > __EMAXERRNO )
    {
        // errno out of range, check for KErrNotReady
        int errCode = -(aErrCode - __EMAXERRNO);
        ELOG1(ESOCKET,"ApnSettings:: retryConnection symbian error : %d" , errCode);
        if( (errCode == KErrNotReady) && (aType == 2) )
        {
            // call reset and setDefaultif() again to make a new conn and use  
            ApnSettings::removeDefaultApn();
            int ret = ApnSettings::setDefaultApn(aType,aApn);
            return ret;
        }
     }     
     return -(aErrCode);
     
}