Skip to content

Commit

Permalink
driver/alt1250: Notice instance information
Browse files Browse the repository at this point in the history
Notice instance information of LwM2M server operation to application.
  • Loading branch information
SPRESENSE committed Jan 23, 2024
1 parent f8b0b06 commit 5a4b0c2
Showing 1 changed file with 75 additions and 9 deletions.
84 changes: 75 additions & 9 deletions drivers/modem/alt1250/altcom_lwm2m_hdlr.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>

#include <nuttx/wireless/lte/lte_ioctl.h>

Expand Down Expand Up @@ -328,17 +329,16 @@ static int32_t stop_ov_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
}

/****************************************************************************
* name: fwup_srvop_handle
* name: fwupdate_notice_hndl
****************************************************************************/

static int32_t fwup_srvop_handle(FAR uint8_t *pktbuf, size_t pktsz,
static int32_t fwupdate_notice_hndl(FAR uint8_t *pktbuf, size_t pktsz,
FAR void **cb_args, size_t arglen)
{
uint8_t *ep;
FAR int *event = (FAR int *)&cb_args[0];

/* Expected unsolicited event
* %LWM2MOPEV: <event>[,....
* %LWM2MEV: <event>[,....
*/

Expand All @@ -352,23 +352,89 @@ static int32_t fwup_srvop_handle(FAR uint8_t *pktbuf, size_t pktsz,
}

/****************************************************************************
* name: fwupdate_notice_hndl
* name: parse_inst_number
****************************************************************************/

static int32_t fwupdate_notice_hndl(FAR uint8_t *pktbuf, size_t pktsz,
FAR void **cb_args, size_t arglen)
static int parse_inst_number(FAR uint8_t **buf, FAR size_t *bufsz)
{
return fwup_srvop_handle(pktbuf, pktsz, cb_args, arglen);
int ret = 0;

if (!isdigit(**buf))
{
return -1;
}

while (*bufsz)
{
if (!isdigit(**buf))
{
break;
}

ret = ret * 10 + ((**buf) - '0');
(*bufsz)--;
(*buf)++;
}

return ret;
}

/****************************************************************************
* name: server_op_notice_hndl
****************************************************************************/

static int32_t server_op_notice_hndl(FAR uint8_t *pktbuf, size_t pktsz,
FAR void **cb_args, size_t arglen)
FAR void **cb_args, size_t arglen)
{
return fwup_srvop_handle(pktbuf, pktsz, cb_args, arglen);
int i;
FAR int *event = (FAR int *)&cb_args[0];
FAR int *srvid = (FAR int *)&cb_args[1];
FAR int *inst = (FAR int *)cb_args[2];

/* The valiable of "inst" is a type of struct lwm2mstub_instance_s in fact.
* But actually it is the same as int[4].
* To make simpler logic, inst is defined as int[4] (int pointer).
*/

/* Set invalid value as initialize */

*srvid = -1;
inst[0] = -1;
inst[1] = -1;
inst[2] = -1;
inst[3] = -1;

/* Expected unsolicited event
* %LWM2MOPEV: <event>[,[<serverShortId>],[<ObjectID>],
* [<ObjectInstanceID>],[<ResourceID>],
* [<ResourceInstanceID>],[<val>][,<MsgId>]]
*/

*event = parse_inst_number(&pktbuf, &pktsz);
if (*event < 0)
{
return -1;
}

if (pktsz > 0 && pktbuf[0] == ',')
{
pktsz--;
pktbuf++;

*srvid = parse_inst_number(&pktbuf, &pktsz);

for (i = 0; i < 4 && pktsz > 0 && pktbuf[0] == ','; i++)
{
/* Skip comma */

pktbuf++;
pktsz--;

inst[i] = parse_inst_number(&pktbuf, &pktsz);
}
}

return 1;
}

/****************************************************************************
Expand Down

0 comments on commit 5a4b0c2

Please sign in to comment.