Skip to content

Commit

Permalink
lte/alt1250: Don't allow to call any LTE API when resuming phase
Browse files Browse the repository at this point in the history
In resuming phase from LTE hibernation mode, any LTE API cannot
be work except resume related APIs.
  • Loading branch information
SPRESENSE committed Jan 26, 2023
1 parent b75642f commit 6547fcf
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions lte/alt1250/alt1250_daemon.h
Expand Up @@ -126,6 +126,7 @@ struct alt1250_s
int64_t lwm2m_apply_xid;
bool api_enable;
context_save_cb_t context_cb;
bool is_resuming;
};

struct alt1250_save_ctx
Expand Down
19 changes: 19 additions & 0 deletions lte/alt1250/alt1250_main.c
Expand Up @@ -140,11 +140,30 @@ static void finalize_daemon(FAR struct alt1250_s *dev)
static int alt1250_loop(FAR struct alt1250_s *dev)
{
int ret;
int pw_stat;
struct pollfd fds[2];
nfds_t nfds;
bool is_running = true;

initialize_daemon(dev);

/* Get modem power status. If modem is turned on, it means resuming from
* hibernation mode.
*/

pw_stat = altdevice_powercontrol(dev->altfd, LTE_CMDID_GET_POWER_STAT);

dbg_alt1250("Modem power status = %d\n", pw_stat);

if (pw_stat)
{
dev->is_resuming = true;
}
else
{
dev->is_resuming = false;
}

notify_to_lapi_caller(dev->syncsem);

/* Main loop of this daemon */
Expand Down
12 changes: 12 additions & 0 deletions lte/alt1250/usock_handlers/alt1250_ioctl_ltecmd.c
Expand Up @@ -68,6 +68,18 @@ int usockreq_ioctl_ltecmd(FAR struct alt1250_s *dev,
*usock_result = -EINVAL;
*usock_xid = request->head.xid;

#ifdef CONFIG_LTE_ALT1250_ENABLE_HIBERNATION_MODE
if (dev->is_resuming &&
!IS_LTE_REPORT_EVENT(ltecmd->cmdid) &&
ltecmd->cmdid != LTE_CMDID_SETEVTCTX &&
ltecmd->cmdid != LTE_CMDID_RESUME)
{
dbg_alt1250("Don't allow to call any API in resuming phase.(cmdid=%lx)\n",
ltecmd->cmdid);
return ret;
}
#endif

if (LTE_ISCMDGRP_NORMAL(ltecmd->cmdid))
{
ioctl_subhdlr = usockreq_ioctl_normal;
Expand Down
15 changes: 15 additions & 0 deletions lte/alt1250/usock_handlers/alt1250_ioctl_normal.c
Expand Up @@ -205,6 +205,13 @@ static int lte_context_resume(FAR struct alt1250_s *dev,
int ret = OK;
int power = 0;

if (!dev->is_resuming)
{
dbg_alt1250("Modem is not in a resuming mode.\n");
*usock_result = -EPERM;
goto error;
}

if (len != sizeof(struct alt1250_save_ctx))
{
dbg_alt1250("Context data size is invalid(%d!=%d).\n",
Expand Down Expand Up @@ -240,11 +247,19 @@ static int lte_context_resume(FAR struct alt1250_s *dev,
* report-based Callbacks registered in advance with lte_set_report*().
*/

/* Resume phase is over */

dev->is_resuming = false;

return OK;

error:
altdevice_powercontrol(dev->altfd, LTE_CMDID_POWEROFF);

/* Resume phase is over */

dev->is_resuming = false;

return ret;
}
#endif
Expand Down

0 comments on commit 6547fcf

Please sign in to comment.