Commit 1243b4ab authored by Jussi Kivilinna's avatar Jussi Kivilinna Committed by Pekka Niemimaa
Browse files

system/ubmodem: fix setting up APN authentication when username/password are setup


Signed-off-by: default avatarJussi Kivilinna <jussi.kivilinna@haltian.com>
(cherry picked from commit 15d79af113c014bd53915052dcc8986aae16d0ec)
parent 03b3afb8
......@@ -140,11 +140,14 @@ static const struct at_cmd_def_s cmd_ATpUUPSDD_urc =
.resp_num = 1,
};
static int8_t apn_conf_type[4] = { 1, 2, 3, 7 };
static int8_t apn_conf_type[5] = { 1, 6, 2, 3, 7 };
static const char *apn_conf_type_name[4] =
static int8_t apn_conf_format[5] = { 's', 'i', 's', 's', 's' };
static const char *apn_conf_type_name[5] =
{
"modem.apn_name",
"modem.apn_authentication",
"modem.apn_user",
"modem.apn_password",
"modem.apn_ipaddr"
......@@ -433,8 +436,24 @@ static void send_next_apn_configuration(struct ubmodem_s *modem)
if (buf[0] == '\0')
continue;
snprintf(sub->apn_conf.value, sizeof(sub->apn_conf.value), "=0,%d,\"%s\"",
apn_conf_type[sub->apn_conf.pos], buf);
if (apn_conf_format[sub->apn_conf.pos] == 's')
{
/* Text string in buffer. */
snprintf(sub->apn_conf.value, sizeof(sub->apn_conf.value), "=0,%d,\"%s\"",
apn_conf_type[sub->apn_conf.pos], buf);
}
else if (apn_conf_format[sub->apn_conf.pos] == 'i')
{
/* Integer string in buffer. */
snprintf(sub->apn_conf.value, sizeof(sub->apn_conf.value), "=0,%d,%s",
apn_conf_type[sub->apn_conf.pos], buf);
}
else
{
MODEM_DEBUGASSERT(modem, false);
}
err = __ubmodem_send_cmd(modem, &cmd_ATpUPSD, ATpUPSD_handler, sub, "%s",
sub->apn_conf.value);
......
......@@ -61,6 +61,51 @@
* Private Data
****************************************************************************/
/****************************************************************************
* Private Function
****************************************************************************/
static bool check_apn_authentication(struct ubmodem_s *modem,
char *buf, size_t buflen)
{
bool use_auth = false;
char tmp[16];
/* APN authentication is needed if APN username/password are given. */
tmp[0] = '\0';
if (__ubmodem_config_get_value(modem, "modem.apn_user", tmp, sizeof(tmp)))
{
if (tmp[0] != '\0')
{
/* APN username configured. */
use_auth = true;
}
}
tmp[0] = '\0';
if (__ubmodem_config_get_value(modem, "modem.apn_password", tmp, sizeof(tmp)))
{
if (tmp[0] != '\0')
{
/* APN password configured. */
use_auth = true;
}
}
if (buf && buflen > 0)
{
/* Give authentication setting. Use 'PAP' if username/password have been
* set. Otherwise disable APN authentication.*/
snprintf(buf, buflen, "%o", use_auth);
}
return true;
}
/****************************************************************************
* Public Functions
****************************************************************************/
......@@ -107,19 +152,31 @@ void __ubmodem_common_failed_command(struct ubmodem_s *modem,
****************************************************************************/
bool __ubmodem_config_get_value(struct ubmodem_s *modem,
const char *variable, char *buf, size_t buflen)
const char *variable, char *buf,
size_t buflen)
{
bool ret = false;
DEBUGASSERT(modem);
if (modem->config.func)
{
/* Get configuration outside module. */
return modem->config.func(modem, variable, buf, buflen,
modem->config.priv);
ret = modem->config.func(modem, variable, buf, buflen,
modem->config.priv);
}
if (!(ret && buflen > 0 && buf[0] != '\0') &&
strcmp(variable, "modem.apn_authentication") == 0)
{
/* Manually check need for APN authentication by checking
* APN username/password. */
return check_apn_authentication(modem, buf, buflen);
}
return false;
return ret;
}
/****************************************************************************
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment