Issues when connecting to cellular

In my app i am using le_data_request to connect to the cellular network, in the logs i am getting the following messages but i have no data connection in the said app:

Does it work when using “cm data connect &”?

No it fails and says le_duplicate when doing that

what did you see on “cm data”?

Just the basic stuff honestly,

Index: 1
APN: mtm.tag.com
PDP Type: IPV4
Connected: no

APN is definetly the right one, and fyi the output of cm data connect &
root@swi-mdm9x28-wp:~# Setting up profile 1
Connecting … failed
Sun Jan 6 00:49:54 UTC 1980 - Connection Failure: LE_DUPLICATE

I suspect the problem lies somewhere in my Code, i wrote a “setAPN” function that sets the needed APN for the connection, when i remove the setAPN part and manually set the APN and reset it works fine…

Here is my Code:

static void initDataConnection(void)

{

setAPN();

// register handler for data connection state change

if (!_hDataConnectionState)

{

    LE_INFO("Add handler for data connection status");

    _hDataConnectionState = le_data_AddConnectionStateHandler(DcsStateHandler, NULL);

}

//Request Data Connection

if (!_RequestRef)

{

    le_data_SetTechnologyRank(1, LE_DATA_CELLULAR);

    _RequestRef = le_data_Request();

    LE_INFO("Requesting the data connection: %p.", _RequestRef);

}

}

//Reads Sim Data and Sets APN accordingly

void setAPN()

{

char myICCID[22] = {0};

int apnsCount = sizeof(apns)/sizeof(apns[0]);

le_mdc_ProfileRef_t profileRefPtr = NULL;

profileRefPtr = le_mdc_GetProfile(1);

LE_ASSERT(NULL != profileRefPtr);

// Check the current state of the cid

le_mdc_ConState_t state = LE_MDC_DISCONNECTED;

// Check the state

LE_ASSERT(LE_OK == le_mdc_GetSessionState(profileRefPtr, &state));

// If already connected, disconnect the session

if (LE_MDC_CONNECTED == state)

{

    LE_ASSERT(le_mdc_StopSession(profileRefPtr) == LE_OK);

}

if(LE_OK == le_sim_GetICCID(LE_SIM_EXTERNAL_SLOT_1, myICCID, sizeof(myICCID)))

{

    const APNHelperAPN *apn = NULL;

    for(int i = 0; i < apnsCount; i++)

    {

        if (strncmp(apns[i].prefix, myICCID, strlen(apns[i].prefix)) == 0)

        {

            // Found

            apn = &apns[i];

            break;

        }

    }

    if(apn)

    {

        //set pdp

        LE_ASSERT(LE_OK == le_mdc_SetPDP(profileRefPtr, LE_MDC_PDP_IPV4));

        // Set APN

        LE_ASSERT(LE_OK == le_mdc_SetAPN(profileRefPtr, apn->apn));

    }

}

else

{

    LE_INFO("Unable to set APN, is SIM inserted?");

}

}

Ok, seems you narrow down the root cause

Do you have a suspision what could be the problem in my code?

You can see the code of cm tool on how to set apn