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";
typedef struct
{
char cid[10];
char pdp[10];
char auth[10];
}
Configuration_t;
static void SetConfiguration
(
)
{
FILE* configFilePtr = fopen("/tmp/config.txt","r");
Configuration_t configuration;
memset(&configuration, 0, sizeof(Configuration_t));
if (configFilePtr == NULL)
{
strncpy(configuration.cid, DefaultCid, sizeof(DefaultCid));
strncpy(configuration.pdp, PdpIpv4, sizeof(PdpIpv4));
strncpy(configuration.apn, automaticApn, sizeof(automaticApn));
}
else
{
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);
if (( cmdLine[len-1] == '\n' ) || ( cmdLine[len-1] == '\r' ))
{
cmdLine[len-1]=' ';
}
char* cidPtr = strtok(cmdLine, " ");
strncpy(configuration.cid, cidPtr, strlen(cidPtr));
char* pdpPtr = strtok(NULL, " ");
strncpy(configuration.pdp, pdpPtr, strlen(pdpPtr));
char* apnPtr = strtok(NULL, " ");
strncpy(configuration.apn, apnPtr, strlen(apnPtr));
char* authPtr = strtok(NULL, " ");
if (authPtr != NULL)
{
strncpy(configuration.auth, authPtr, strlen(authPtr));
}
char* userNamePtr = strtok(NULL, " ");
if (userNamePtr != NULL)
{
strncpy(configuration.userName, userNamePtr, strlen(userNamePtr));
}
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);
}
{
}
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 )
{
}
if ( strncmp(configuration.apn, automaticApn, sizeof(automaticApn)) == 0 )
{
}
else
{
}
if ( configuration.auth[0] != '\0' )
{
if ( strncmp(configuration.auth, AuthPap, sizeof(AuthPap)) == 0 )
{
}
else if ( strncmp(configuration.auth, AuthChap, sizeof(AuthChap)) == 0 )
{
}
{
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);
}