Sample code for Data Profiles

static const char DefaultCid[] = "default";
static const char automaticApn[] = "auto";
static const char PdpIpv4[] = "ipv4";
static const char PdpIpv6[] = "ipv6";
static const char PdpIpv4v6[] = "ipv4v6";
static const char AuthPap[] = "pap";
static const char AuthChap[] = "chap";
static const char AuthPapChap[] = "pap-chap";
 
// Structure used to set the configuration
typedef struct
{
char cid[10]; // profile identifier
char pdp[10]; // packet data protocol
char apn[LE_MDC_APN_NAME_MAX_LEN]; // access point network
char auth[10]; // authentification level
char userName[LE_MDC_USER_NAME_MAX_LEN]; // username for authentification
char password[LE_MDC_PASSWORD_NAME_MAX_LEN]; // password for authentification
}
Configuration_t;
 
// Tests cases
typedef enum
{
TEST_SYNC,
TEST_ASYNC,
TEST_MAX
} Testcase_t;
 
// Tests definition
struct
{
char testName[20];
Testcase_t testCase;
} testsDef[] = {
TEST_DEF(TEST_SYNC),
TEST_DEF(TEST_ASYNC),
TEST_DEF(TEST_MAX)
};
 
 
//--------------------------------------------------------------------------------------------------
/**
* Session handler response for connection and disconnection.
*/
//--------------------------------------------------------------------------------------------------
static void SessionHandlerFunc
(
le_mdc_ProfileRef_t profileRef,
le_result_t result,
void* contextPtr
)
{
le_result_t* activationPtr = contextPtr;
*activationPtr = result;
 
LE_INFO("Session result %d for profile %d", result, le_mdc_GetProfileIndex(profileRef));
 
le_sem_Post(AsyncTestSemaphore);
}
 
//--------------------------------------------------------------------------------------------------
/**
* Start asynchronous session.
*/
//--------------------------------------------------------------------------------------------------
static void SessionStartAsync
(
void* param1Ptr,
void* param2Ptr
)
{
le_mdc_ProfileRef_t profileRef = param1Ptr;
 
le_mdc_StartSessionAsync(profileRef, SessionHandlerFunc, param2Ptr);
}
 
//--------------------------------------------------------------------------------------------------
/**
* Stop asynchronous session.
*/
//--------------------------------------------------------------------------------------------------
static void SessionStopAsync
(
void* param1Ptr,
void* param2Ptr
)
{
le_mdc_ProfileRef_t profileRef = param1Ptr;
 
le_mdc_StopSessionAsync(profileRef, SessionHandlerFunc, param2Ptr);
}
 
//--------------------------------------------------------------------------------------------------
/**
* Set the configuration.
*
*/
//--------------------------------------------------------------------------------------------------
static void SetConfiguration
(
le_mdc_ProfileRef_t* profileRefPtr
)
{
// Check the configuration file
FILE* configFilePtr = fopen("/tmp/config.txt","r");
Configuration_t configuration;
 
memset(&configuration, 0, sizeof(Configuration_t));
 
// if configuration file absent, use default settings
if (configFilePtr == NULL)
{
strncpy(configuration.cid, DefaultCid, sizeof(DefaultCid));
strncpy(configuration.pdp, PdpIpv4, sizeof(PdpIpv4));
strncpy(configuration.apn, automaticApn, sizeof(automaticApn));
}
else
{
// Get the configuration from the file
fseek(configFilePtr, 0, SEEK_END);
uint32_t len = ftell(configFilePtr);
char cmdLine[ len + 1 ];
memset(cmdLine,0,len+1);
fseek(configFilePtr, 0, SEEK_SET);
fread(cmdLine, 1, len, configFilePtr);
fclose(configFilePtr);
 
// Replace last character
if (( cmdLine[len-1] == '\n' ) || ( cmdLine[len-1] == '\r' ))
{
cmdLine[len-1]=' ';
}
 
// Get profile number
char* cidPtr = strtok(cmdLine, " ");
LE_ASSERT(cidPtr != NULL);
strncpy(configuration.cid, cidPtr, strlen(cidPtr));
 
// Get pdp type
char* pdpPtr = strtok(NULL, " ");
LE_ASSERT(pdpPtr != NULL);
strncpy(configuration.pdp, pdpPtr, strlen(pdpPtr));
 
// Get apn
char* apnPtr = strtok(NULL, " ");
LE_ASSERT(apnPtr != NULL);
strncpy(configuration.apn, apnPtr, strlen(apnPtr));
 
// Get authentification
char* authPtr = strtok(NULL, " ");
if (authPtr != NULL)
{
strncpy(configuration.auth, authPtr, strlen(authPtr));
}
 
// Get username
char* userNamePtr = strtok(NULL, " ");
if (userNamePtr != NULL)
{
strncpy(configuration.userName, userNamePtr, strlen(userNamePtr));
}
 
// Get password
char* passwordPtr = strtok(NULL, " ");
if(passwordPtr != NULL)
{
strncpy(configuration.password, passwordPtr, strlen(passwordPtr));
}
}
 
uint32_t profile;
 
if ( strncmp(configuration.cid, DefaultCid, sizeof(DefaultCid)) == 0 )
{
}
else
{
profile = atoi(configuration.cid);
}
 
// Get the profile reference
*profileRefPtr = le_mdc_GetProfile(profile);
LE_ASSERT( *profileRefPtr != NULL );
 
// Check the current state of the cid
 
// Check the state
LE_ASSERT( le_mdc_GetSessionState(*profileRefPtr, &state) == LE_OK );
 
// If already connected, disconnect the session
if ( state == LE_MDC_CONNECTED )
{
LE_ASSERT(le_mdc_StopSession(*profileRefPtr) == LE_OK);
}
 
// Set pdp type
 
if ( strncmp(configuration.pdp, PdpIpv4, sizeof(PdpIpv4)) == 0 )
{
}
else if ( strncmp(configuration.pdp, PdpIpv6, sizeof(PdpIpv6)) == 0 )
{
}
else if ( strncmp(configuration.pdp, PdpIpv4v6, sizeof(PdpIpv4v6)) == 0 )
{
}
 
LE_ASSERT( le_mdc_SetPDP(*profileRefPtr, pdp) == LE_OK );
 
// Set APN
if ( strncmp(configuration.apn, automaticApn, sizeof(automaticApn)) == 0 )
{
// Set default APN
LE_ASSERT( le_mdc_SetDefaultAPN(*profileRefPtr) == LE_OK );
}
else
{
LE_ASSERT( le_mdc_SetAPN(*profileRefPtr, configuration.apn) == LE_OK );
}
 
if ( configuration.auth[0] != '\0' )
{
// Set the authentification, username and password
if ( strncmp(configuration.auth, AuthPapChap, sizeof(AuthPapChap)) == 0 )
{
}
// Set the authentification, username and password
else if ( strncmp(configuration.auth, AuthPap, sizeof(AuthPap)) == 0 )
{
}
else if ( strncmp(configuration.auth, AuthChap, sizeof(AuthChap)) == 0 )
{
}
 
if (auth != LE_MDC_AUTH_NONE)
{
auth,
configuration.userName,
configuration.password ) == LE_OK );
}
}
 
LE_INFO("cid: %d pdp: %d apn: %s auth: %d username: %s password: %s", profile, pdp,
configuration.apn, auth, configuration.userName, configuration.password);
}