pkarashchenko commented on code in PR #7248:
URL: https://github.com/apache/incubator-nuttx/pull/7248#discussion_r994871442


##########
drivers/modem/alt1250/altcom_lwm2m_hdlr.c:
##########
@@ -0,0 +1,412 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_lwm2m_hdlr.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <nuttx/wireless/lte/lte_ioctl.h>
+
+#include "altcom_lwm2m_hdlr.h"
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int32_t read_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t write_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t exec_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t start_ov_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t stop_ov_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t fwupdate_notice_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t server_op_notice_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct urc_hdltbl_s
+{
+  const char *head;
+  uint32_t lcmdid;
+  lwm2mstub_hndl_t hdlr;
+};
+
+struct lwm2mstub_instance_s
+{
+  int object_id;
+  int object_inst;
+  int res_id;
+  int res_inst;
+};
+
+struct lwm2mstub_ovcondition_s
+{
+    uint8_t valid_mask;
+    unsigned int min_period;
+    unsigned int max_period;
+    double gt_cond;
+    double lt_cond;
+    double step_val;
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct urc_hdltbl_s urc_idhandles[] =
+{
+  { "%LWM2MOBJCMDU: \"READ\",",
+    LTE_CMDID_LWM2M_READ_EVT, read_request_hndl },
+
+  { "%LWM2MOBJCMDU: \"WRITE\",",
+    LTE_CMDID_LWM2M_WRITE_EVT, write_request_hndl },
+
+  { "%LWM2MOBJCMDU: \"EXE\",",
+    LTE_CMDID_LWM2M_EXEC_EVT, exec_request_hndl },
+
+  { "%LWM2MOBJCMDU: \"OBSERVE_START\",",
+    LTE_CMDID_LWM2M_OVSTART_EVT, start_ov_request_hndl },
+
+  { "%LWM2MOBJCMDU: \"OBSERVE_STOP\",",
+    LTE_CMDID_LWM2M_OVSTOP_EVT, stop_ov_request_hndl },
+
+  { "%LWM2MOPEV: ",
+    LTE_CMDID_LWM2M_SERVEROP_EVT, server_op_notice_hndl },
+
+  { "%LWM2MEV: ",
+    LTE_CMDID_LWM2M_FWUP_EVT, fwupdate_notice_hndl },
+
+  {
+    NULL, 0, NULL
+  },
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * name: skip_until
+ ****************************************************************************/
+
+static uint8_t *skip_until(FAR uint8_t *stream, FAR char *delim)

Review Comment:
   ```suggestion
   static FAR uint8_t *skip_until(FAR uint8_t *stream, FAR char *delim)
   ```
   



##########
drivers/modem/alt1250/altcom_lwm2m_hdlr.c:
##########
@@ -0,0 +1,412 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_lwm2m_hdlr.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <nuttx/wireless/lte/lte_ioctl.h>
+
+#include "altcom_lwm2m_hdlr.h"
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int32_t read_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t write_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t exec_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t start_ov_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t stop_ov_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t fwupdate_notice_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t server_op_notice_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct urc_hdltbl_s
+{
+  const char *head;
+  uint32_t lcmdid;
+  lwm2mstub_hndl_t hdlr;
+};
+
+struct lwm2mstub_instance_s
+{
+  int object_id;
+  int object_inst;
+  int res_id;
+  int res_inst;
+};
+
+struct lwm2mstub_ovcondition_s
+{
+    uint8_t valid_mask;
+    unsigned int min_period;
+    unsigned int max_period;
+    double gt_cond;
+    double lt_cond;
+    double step_val;
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct urc_hdltbl_s urc_idhandles[] =
+{
+  { "%LWM2MOBJCMDU: \"READ\",",
+    LTE_CMDID_LWM2M_READ_EVT, read_request_hndl },
+
+  { "%LWM2MOBJCMDU: \"WRITE\",",
+    LTE_CMDID_LWM2M_WRITE_EVT, write_request_hndl },
+
+  { "%LWM2MOBJCMDU: \"EXE\",",
+    LTE_CMDID_LWM2M_EXEC_EVT, exec_request_hndl },
+
+  { "%LWM2MOBJCMDU: \"OBSERVE_START\",",
+    LTE_CMDID_LWM2M_OVSTART_EVT, start_ov_request_hndl },
+
+  { "%LWM2MOBJCMDU: \"OBSERVE_STOP\",",
+    LTE_CMDID_LWM2M_OVSTOP_EVT, stop_ov_request_hndl },
+
+  { "%LWM2MOPEV: ",
+    LTE_CMDID_LWM2M_SERVEROP_EVT, server_op_notice_hndl },
+
+  { "%LWM2MEV: ",
+    LTE_CMDID_LWM2M_FWUP_EVT, fwupdate_notice_hndl },
+
+  {
+    NULL, 0, NULL
+  },
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * name: skip_until
+ ****************************************************************************/
+
+static uint8_t *skip_until(FAR uint8_t *stream, FAR char *delim)
+{
+  for (; *stream && !strchr(delim, *stream); stream++);
+  for (; *stream && strchr(delim, *stream); stream++);
+
+  if (*stream == '\0')
+    {
+      stream = NULL;
+    }
+
+  return stream;
+}
+
+/****************************************************************************
+ * name: strcpy_until
+ ****************************************************************************/
+
+static char strcpy_until(char *dst, int n, char **src, char *delim)
+{
+  char *tmp = *src;
+
+  if (dst)
+    {
+      dst[n - 1] = '\0';
+      n--;
+    }
+
+  while (*tmp && !strchr(delim, *tmp))
+    {
+      if (dst && (n > 0))
+        {
+          *dst++ = *tmp;
+          n--;
+        }
+
+      tmp++;
+    }
+
+  if (dst && (n > 0))
+    {
+      *dst = '\0';
+    }
+
+  *src = tmp + 1;
+
+  return *tmp;
+}
+
+/****************************************************************************
+ * name: parse_instance
+ ****************************************************************************/
+
+static uint8_t *parse_instance(uint8_t *pktbuf, int *seq_no, int *srv_id,

Review Comment:
   Add FAR



##########
drivers/modem/alt1250/altcom_lwm2m_hdlr.h:
##########
@@ -18,54 +18,47 @@
  *
  ****************************************************************************/
 
-#ifndef __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_STATE_H
-#define __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_STATE_H
-
-#if defined(CONFIG_MODEM_ALTMDM)
+#ifndef __DRIVERS_MODEM_ALT1250_ALTCOM_LWM2M_HDLR_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_LWM2M_HDLR_H__
 
 /****************************************************************************
- * Pre-processor Definitions
+ * Included Files
  ****************************************************************************/
 
-#define MODEM_PM_INTERNAL_STATE_SLEEP          (0)
-#define MODEM_PM_INTERNAL_STATE_GOING_TO_WAKE  (1)
-#define MODEM_PM_INTERNAL_STATE_WAKE           (2)
-#define MODEM_PM_INTERNAL_STATE_GOING_TO_SLEEP (3)
-#define MODEM_PM_INTERNAL_STATE_MAX            (4)
+#include <nuttx/config.h>
 
-/****************************************************************************
- * Public Function Prototypes
- ****************************************************************************/
+#include <stdbool.h>
+#include <stdint.h>
 
 /****************************************************************************
- * Name: altmdm_pm_getstate
- *
- * Description:
- *   Get current modem state.
- *
+ * Public Types
  ****************************************************************************/
 
-uint32_t altmdm_pm_getstate(void);
+typedef int32_t (*lwm2mstub_hndl_t)(FAR uint8_t *, size_t,

Review Comment:
   Add CODE



##########
drivers/modem/alt1250/altcom_pkt.h:
##########
@@ -0,0 +1,414 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_pkt.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __DRIVERS_MODEM_ALT1250_ALTCOM_PKT_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_PKT_H__
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <arpa/inet.h>
+
+#include <nuttx/modem/alt1250.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ALTCOM_HDR_MAGICNUMBER (0xFEEDBAC5)
+
+#define ALTCOM_CMDOPT_CHECKSUM_EN  (1 << 0)
+
+#define ALTCOM_PAYLOAD_SIZE_MAX    (4112)
+#define ALTCOM_PAYLOAD_SIZE_MAX_V4 (3092)
+#define ALTCOM_PKT_SIZE_MAX        (ALTCOM_PAYLOAD_SIZE_MAX \
+                                    + sizeof(struct altcom_cmdhdr_s) \
+                                    + sizeof(struct altcom_cmdfooter_s))
+#define ALTCOM_RX_PKT_SIZE_MAX     (ALTCOM_PAYLOAD_SIZE_MAX_V4 \
+                                    + sizeof(struct altcom_cmdhdr_s))
+
+#define LTE_RESULT_OK     (0)      /**< Result code on success */
+#define LTE_RESULT_ERROR  (1)      /**< Result code on failure */
+#define LTE_RESULT_CANCEL (2)      /**< Result code on cancel */
+
+#define ALTCOM_CMD_POWER_ON_REPLY_SIZE  (1)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+begin_packed_struct struct altcom_cmdhdr_s
+{
+  uint32_t magic;
+  uint8_t  ver;
+  uint8_t  seqid;
+  uint16_t cmdid;
+  uint16_t transid;
+  uint16_t datalen;
+  union
+    {
+      uint16_t v1_options;
+      uint16_t v4_hdr_cksum;
+    };
+  union
+    {
+      uint16_t v1_checksum;
+      uint16_t v4_data_cksum;
+    };
+  uint8_t payload[0];

Review Comment:
   C89 incompatible



##########
drivers/modem/alt1250/altcom_pkt.h:
##########
@@ -0,0 +1,414 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_pkt.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __DRIVERS_MODEM_ALT1250_ALTCOM_PKT_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_PKT_H__
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <arpa/inet.h>
+
+#include <nuttx/modem/alt1250.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ALTCOM_HDR_MAGICNUMBER (0xFEEDBAC5)
+
+#define ALTCOM_CMDOPT_CHECKSUM_EN  (1 << 0)
+
+#define ALTCOM_PAYLOAD_SIZE_MAX    (4112)
+#define ALTCOM_PAYLOAD_SIZE_MAX_V4 (3092)
+#define ALTCOM_PKT_SIZE_MAX        (ALTCOM_PAYLOAD_SIZE_MAX \
+                                    + sizeof(struct altcom_cmdhdr_s) \
+                                    + sizeof(struct altcom_cmdfooter_s))
+#define ALTCOM_RX_PKT_SIZE_MAX     (ALTCOM_PAYLOAD_SIZE_MAX_V4 \
+                                    + sizeof(struct altcom_cmdhdr_s))
+
+#define LTE_RESULT_OK     (0)      /**< Result code on success */
+#define LTE_RESULT_ERROR  (1)      /**< Result code on failure */
+#define LTE_RESULT_CANCEL (2)      /**< Result code on cancel */
+
+#define ALTCOM_CMD_POWER_ON_REPLY_SIZE  (1)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+begin_packed_struct struct altcom_cmdhdr_s
+{
+  uint32_t magic;
+  uint8_t  ver;
+  uint8_t  seqid;
+  uint16_t cmdid;
+  uint16_t transid;
+  uint16_t datalen;
+  union
+    {
+      uint16_t v1_options;
+      uint16_t v4_hdr_cksum;
+    };
+  union
+    {
+      uint16_t v1_checksum;
+      uint16_t v4_data_cksum;
+    };
+  uint8_t payload[0];
+} end_packed_struct;
+
+begin_packed_struct struct altcom_cmdfooter_s
+{
+  uint16_t reserve;
+  uint16_t checksum;
+} end_packed_struct;
+
+begin_packed_struct struct altcom_errind_s
+{
+  uint8_t ver;
+  uint8_t seqid;
+  uint16_t cmdid;
+  uint16_t transid;
+  uint16_t dtlen;
+  union
+    {
+      uint16_t v1_options;
+      uint16_t v4_hdr_cksum;
+    };
+  union
+    {
+      uint16_t v1_checksum;
+      uint16_t v4_data_cksum;
+    };
+} end_packed_struct;
+
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+static inline int is_errind(uint16_t cmdid)
+{
+  return (cmdid == ALTCOM_CMDID_ERRIND);
+}
+
+static inline uint16_t parse_cid(FAR struct altcom_cmdhdr_s *hdr)
+{
+  return hdr->cmdid;
+}
+
+static inline uint16_t parse_tid(FAR struct altcom_cmdhdr_s *hdr)
+{
+  return hdr->transid;
+}
+
+static inline uint16_t parse_cid4errind(FAR struct altcom_cmdhdr_s *hdr)
+{
+  FAR struct altcom_errind_s *pkt =
+    (FAR struct altcom_errind_s *)&hdr->payload[0];
+
+  return ntohl(pkt->cmdid);
+}
+
+static inline uint16_t parse_tid4errind(FAR struct altcom_cmdhdr_s *hdr)
+{
+  FAR struct altcom_errind_s *pkt =
+    (FAR struct altcom_errind_s *)&hdr->payload[0];
+
+  return ntohl(pkt->transid);
+}
+
+static inline FAR uint8_t *get_payload(FAR struct altcom_cmdhdr_s *hdr)
+{
+  return &hdr->payload[0];
+}
+
+static inline uint16_t get_payload_len(FAR struct altcom_cmdhdr_s *hdr)
+{
+  return hdr->datalen;
+}
+
+static inline FAR uint8_t get_altver(FAR struct altcom_cmdhdr_s *hdr)
+{
+  return hdr->ver;
+}
+
+static inline uint16_t get_pktlen(uint8_t ver, uint16_t payloadlen)
+{
+  if (ver == ALTCOM_VER1)
+    {
+      payloadlen += sizeof(struct altcom_cmdhdr_s) +
+        sizeof(struct altcom_cmdfooter_s);
+    }
+  else if (ver == ALTCOM_VER4)
+    {
+      payloadlen += sizeof(struct altcom_cmdhdr_s);
+    }
+  else
+    {
+      DEBUGASSERT(0);
+    }
+
+  return payloadlen;
+}
+
+static inline uint16_t convert_cid2v1(uint16_t cid)
+{
+  if ((cid >= APICMDID_SOCK_ACCEPT) && (cid <= APICMDID_SOCK_SETSOCKOPT))
+    {
+      return cid;
+    }
+
+  if ((cid >= APICMDID_SMS_INIT) && (cid <= APICMDID_SMS_DELETE))
+    {
+      return cid;
+    }
+
+  if ((cid >= APICMDID_GET_VERSION_V4) && (cid <= APICMDID_SET_PSM_V4))
+    {
+      return (cid + 1);
+    }
+
+  if ((cid >= APICMDID_RADIO_ON_V4) && (cid <= APICMDID_ACTIVATE_PDN_V4))
+    {
+      return (cid - 0x2ec);
+    }
+
+  if ((cid >= APICMDID_DEACTIVATE_PDN_V4) &&
+      (cid <= APICMDID_REPORT_NETINFO_V4))
+    {
+      return (cid - 0x2ed);
+    }
+
+  if (cid == (APICMDID_ERRINFO_V4 & ~ALTCOM_CMDID_REPLY_BIT))
+    {
+      return APICMDID_ERRINFO;
+    }
+
+  if (cid == APICMDID_GET_SIMINFO_V4)
+    {
+      return APICMDID_GET_SIMINFO;
+    }
+
+  if (cid == APICMDID_GET_QUALITY_V4)
+    {
+      return APICMDID_GET_QUALITY;
+    }
+
+  if (cid == APICMDID_ACTIVATE_PDN_CANCEL_V4)
+    {
+      return APICMDID_ACTIVATE_PDN_CANCEL;
+    }
+
+  if (cid == APICMDID_GET_CELLINFO_V4)
+    {
+      return APICMDID_GET_CELLINFO;
+    }
+
+  if (cid == APICMDID_GET_RAT_V4)
+    {
+      return APICMDID_GET_RAT;
+    }
+
+  if (cid == APICMDID_SET_RAT_V4)
+    {
+      return APICMDID_SET_RAT;
+    }
+
+  if (cid == APICMDID_SEND_ATCMD_V4)
+    {
+      return APICMDID_SEND_ATCMD;
+    }
+
+  if (cid == APICMDID_URC_EVENT_V4)
+    {
+      return APICMDID_URC_EVENT;
+    }
+
+  if ((cid >= APICMDID_FW_INJECTDELTAIMG_V4) &&
+      (cid <= APICMDID_FW_GETUPDATERESULT_V4))
+    {
+      return (cid + 0xdd0);
+    }
+
+  if (cid == APICMDID_TLS_CONFIG_VERIFY_CALLBACK_V4)
+    {
+      return APICMDID_TLS_CONFIG_VERIFY_CALLBACK;
+    }
+
+  if (cid == APICMDID_CLOGS_V4)
+    {
+      return APICMDID_CLOGS;
+    }
+
+  if (cid == APICMDID_LOGLIST_V4)
+    {
+      return APICMDID_LOGLIST;
+    }
+
+#ifdef CONFIG_MODEM_ALT1250_LOG_ACCESS
+  if ((cid >= APICMDID_LOGOPEN_V4) && (cid <= APICMDID_LOGLSEEK_V4))
+    {
+      return cid + (APICMDID_LOGOPEN - APICMDID_LOGOPEN_V4);
+    }
+#endif /* CONFIG_MODEM_ALT1250_LOG_ACCESS */
+
+  return APICMDID_UNKNOWN;
+}
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: altcom_make_poweron_cmd_v1
+ *
+ * Description:
+ *   Create an ALTCOM command for POWER_ON_REQ of protocol version 1.
+ *
+ * Input Parameters:
+ *   sz         - Variable to put the length of the command created.
+ *
+ * Returned Value:
+ *   Returns the buffer pointer of the created command.
+ *
+ ****************************************************************************/
+
+FAR void *altcom_make_poweron_cmd_v1(int *sz);
+
+/****************************************************************************
+ * Name: altcom_make_poweron_cmd_v4
+ *
+ * Description:
+ *   Create an ALTCOM command for POWER_ON_REQ of protocol version 4.
+ *
+ * Input Parameters:
+ *   sz         - Variable to put the length of the command created.
+ *
+ * Returned Value:
+ *   Returns the buffer pointer of the created command.
+ *
+ ****************************************************************************/
+
+FAR void *altcom_make_poweron_cmd_v4(int *sz);
+
+/****************************************************************************
+ * Name: altcom_is_v1pkt_ok
+ *
+ * Description:
+ *   Check if the POWER_ON_RES command of protocol version 1 is OK.
+ *
+ * Input Parameters:
+ *   cmdhdr      - Pointer to the received packet.
+ *
+ * Returned Value:
+ *   Returns true if the POWER_ON_RES command of protocol version 1 is OK,
+ *   false otherwise.
+ *
+ ****************************************************************************/
+
+bool altcom_is_v1pkt_ok(struct altcom_cmdhdr_s *cmdhdr);
+
+/****************************************************************************
+ * Name: altcom_is_v4pkt_ok
+ *
+ * Description:
+ *   Check if the POWER_ON_RES command of protocol version 4 is OK.
+ *
+ * Input Parameters:
+ *   cmdhdr      - Pointer to the received packet.
+ *
+ * Returned Value:
+ *   Returns true if the POWER_ON_RES command of protocol version 4 is OK,
+ *   false otherwise.
+ *
+ ****************************************************************************/
+
+bool altcom_is_v4pkt_ok(struct altcom_cmdhdr_s *cmdhdr);

Review Comment:
   ```suggestion
   bool altcom_is_v4pkt_ok(FAR struct altcom_cmdhdr_s *cmdhdr);
   ```
   



##########
drivers/modem/alt1250/altcom_pkt.h:
##########
@@ -0,0 +1,414 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_pkt.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __DRIVERS_MODEM_ALT1250_ALTCOM_PKT_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_PKT_H__
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <arpa/inet.h>
+
+#include <nuttx/modem/alt1250.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ALTCOM_HDR_MAGICNUMBER (0xFEEDBAC5)
+
+#define ALTCOM_CMDOPT_CHECKSUM_EN  (1 << 0)
+
+#define ALTCOM_PAYLOAD_SIZE_MAX    (4112)
+#define ALTCOM_PAYLOAD_SIZE_MAX_V4 (3092)
+#define ALTCOM_PKT_SIZE_MAX        (ALTCOM_PAYLOAD_SIZE_MAX \
+                                    + sizeof(struct altcom_cmdhdr_s) \
+                                    + sizeof(struct altcom_cmdfooter_s))
+#define ALTCOM_RX_PKT_SIZE_MAX     (ALTCOM_PAYLOAD_SIZE_MAX_V4 \
+                                    + sizeof(struct altcom_cmdhdr_s))
+
+#define LTE_RESULT_OK     (0)      /**< Result code on success */
+#define LTE_RESULT_ERROR  (1)      /**< Result code on failure */
+#define LTE_RESULT_CANCEL (2)      /**< Result code on cancel */
+
+#define ALTCOM_CMD_POWER_ON_REPLY_SIZE  (1)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+begin_packed_struct struct altcom_cmdhdr_s
+{
+  uint32_t magic;
+  uint8_t  ver;
+  uint8_t  seqid;
+  uint16_t cmdid;
+  uint16_t transid;
+  uint16_t datalen;
+  union
+    {
+      uint16_t v1_options;
+      uint16_t v4_hdr_cksum;
+    };
+  union
+    {
+      uint16_t v1_checksum;
+      uint16_t v4_data_cksum;
+    };
+  uint8_t payload[0];
+} end_packed_struct;
+
+begin_packed_struct struct altcom_cmdfooter_s
+{
+  uint16_t reserve;
+  uint16_t checksum;
+} end_packed_struct;
+
+begin_packed_struct struct altcom_errind_s
+{
+  uint8_t ver;
+  uint8_t seqid;
+  uint16_t cmdid;
+  uint16_t transid;
+  uint16_t dtlen;
+  union
+    {
+      uint16_t v1_options;
+      uint16_t v4_hdr_cksum;
+    };
+  union
+    {
+      uint16_t v1_checksum;
+      uint16_t v4_data_cksum;
+    };
+} end_packed_struct;
+
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+static inline int is_errind(uint16_t cmdid)
+{
+  return (cmdid == ALTCOM_CMDID_ERRIND);
+}
+
+static inline uint16_t parse_cid(FAR struct altcom_cmdhdr_s *hdr)
+{
+  return hdr->cmdid;
+}
+
+static inline uint16_t parse_tid(FAR struct altcom_cmdhdr_s *hdr)
+{
+  return hdr->transid;
+}
+
+static inline uint16_t parse_cid4errind(FAR struct altcom_cmdhdr_s *hdr)
+{
+  FAR struct altcom_errind_s *pkt =
+    (FAR struct altcom_errind_s *)&hdr->payload[0];
+
+  return ntohl(pkt->cmdid);
+}
+
+static inline uint16_t parse_tid4errind(FAR struct altcom_cmdhdr_s *hdr)
+{
+  FAR struct altcom_errind_s *pkt =
+    (FAR struct altcom_errind_s *)&hdr->payload[0];
+
+  return ntohl(pkt->transid);
+}
+
+static inline FAR uint8_t *get_payload(FAR struct altcom_cmdhdr_s *hdr)
+{
+  return &hdr->payload[0];
+}
+
+static inline uint16_t get_payload_len(FAR struct altcom_cmdhdr_s *hdr)
+{
+  return hdr->datalen;
+}
+
+static inline FAR uint8_t get_altver(FAR struct altcom_cmdhdr_s *hdr)
+{
+  return hdr->ver;
+}
+
+static inline uint16_t get_pktlen(uint8_t ver, uint16_t payloadlen)
+{
+  if (ver == ALTCOM_VER1)
+    {
+      payloadlen += sizeof(struct altcom_cmdhdr_s) +
+        sizeof(struct altcom_cmdfooter_s);
+    }
+  else if (ver == ALTCOM_VER4)
+    {
+      payloadlen += sizeof(struct altcom_cmdhdr_s);
+    }
+  else
+    {
+      DEBUGASSERT(0);
+    }
+
+  return payloadlen;
+}
+
+static inline uint16_t convert_cid2v1(uint16_t cid)
+{
+  if ((cid >= APICMDID_SOCK_ACCEPT) && (cid <= APICMDID_SOCK_SETSOCKOPT))
+    {
+      return cid;
+    }
+
+  if ((cid >= APICMDID_SMS_INIT) && (cid <= APICMDID_SMS_DELETE))
+    {
+      return cid;
+    }
+
+  if ((cid >= APICMDID_GET_VERSION_V4) && (cid <= APICMDID_SET_PSM_V4))
+    {
+      return (cid + 1);
+    }
+
+  if ((cid >= APICMDID_RADIO_ON_V4) && (cid <= APICMDID_ACTIVATE_PDN_V4))
+    {
+      return (cid - 0x2ec);
+    }
+
+  if ((cid >= APICMDID_DEACTIVATE_PDN_V4) &&
+      (cid <= APICMDID_REPORT_NETINFO_V4))
+    {
+      return (cid - 0x2ed);
+    }
+
+  if (cid == (APICMDID_ERRINFO_V4 & ~ALTCOM_CMDID_REPLY_BIT))
+    {
+      return APICMDID_ERRINFO;
+    }
+
+  if (cid == APICMDID_GET_SIMINFO_V4)
+    {
+      return APICMDID_GET_SIMINFO;
+    }
+
+  if (cid == APICMDID_GET_QUALITY_V4)
+    {
+      return APICMDID_GET_QUALITY;
+    }
+
+  if (cid == APICMDID_ACTIVATE_PDN_CANCEL_V4)
+    {
+      return APICMDID_ACTIVATE_PDN_CANCEL;
+    }
+
+  if (cid == APICMDID_GET_CELLINFO_V4)
+    {
+      return APICMDID_GET_CELLINFO;
+    }
+
+  if (cid == APICMDID_GET_RAT_V4)
+    {
+      return APICMDID_GET_RAT;
+    }
+
+  if (cid == APICMDID_SET_RAT_V4)
+    {
+      return APICMDID_SET_RAT;
+    }
+
+  if (cid == APICMDID_SEND_ATCMD_V4)
+    {
+      return APICMDID_SEND_ATCMD;
+    }
+
+  if (cid == APICMDID_URC_EVENT_V4)
+    {
+      return APICMDID_URC_EVENT;
+    }
+
+  if ((cid >= APICMDID_FW_INJECTDELTAIMG_V4) &&
+      (cid <= APICMDID_FW_GETUPDATERESULT_V4))
+    {
+      return (cid + 0xdd0);
+    }
+
+  if (cid == APICMDID_TLS_CONFIG_VERIFY_CALLBACK_V4)
+    {
+      return APICMDID_TLS_CONFIG_VERIFY_CALLBACK;
+    }
+
+  if (cid == APICMDID_CLOGS_V4)
+    {
+      return APICMDID_CLOGS;
+    }
+
+  if (cid == APICMDID_LOGLIST_V4)
+    {
+      return APICMDID_LOGLIST;
+    }
+
+#ifdef CONFIG_MODEM_ALT1250_LOG_ACCESS
+  if ((cid >= APICMDID_LOGOPEN_V4) && (cid <= APICMDID_LOGLSEEK_V4))
+    {
+      return cid + (APICMDID_LOGOPEN - APICMDID_LOGOPEN_V4);
+    }
+#endif /* CONFIG_MODEM_ALT1250_LOG_ACCESS */
+
+  return APICMDID_UNKNOWN;
+}
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: altcom_make_poweron_cmd_v1
+ *
+ * Description:
+ *   Create an ALTCOM command for POWER_ON_REQ of protocol version 1.
+ *
+ * Input Parameters:
+ *   sz         - Variable to put the length of the command created.
+ *
+ * Returned Value:
+ *   Returns the buffer pointer of the created command.
+ *
+ ****************************************************************************/
+
+FAR void *altcom_make_poweron_cmd_v1(int *sz);
+
+/****************************************************************************
+ * Name: altcom_make_poweron_cmd_v4
+ *
+ * Description:
+ *   Create an ALTCOM command for POWER_ON_REQ of protocol version 4.
+ *
+ * Input Parameters:
+ *   sz         - Variable to put the length of the command created.
+ *
+ * Returned Value:
+ *   Returns the buffer pointer of the created command.
+ *
+ ****************************************************************************/
+
+FAR void *altcom_make_poweron_cmd_v4(int *sz);

Review Comment:
   ```suggestion
   FAR void *altcom_make_poweron_cmd_v4(FAR int *sz);
   ```
   



##########
drivers/modem/alt1250/altcom_lwm2m_hdlr.h:
##########
@@ -18,54 +18,47 @@
  *
  ****************************************************************************/
 
-#ifndef __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_STATE_H
-#define __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_STATE_H
-
-#if defined(CONFIG_MODEM_ALTMDM)
+#ifndef __DRIVERS_MODEM_ALT1250_ALTCOM_LWM2M_HDLR_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_LWM2M_HDLR_H__
 
 /****************************************************************************
- * Pre-processor Definitions
+ * Included Files
  ****************************************************************************/
 
-#define MODEM_PM_INTERNAL_STATE_SLEEP          (0)
-#define MODEM_PM_INTERNAL_STATE_GOING_TO_WAKE  (1)
-#define MODEM_PM_INTERNAL_STATE_WAKE           (2)
-#define MODEM_PM_INTERNAL_STATE_GOING_TO_SLEEP (3)
-#define MODEM_PM_INTERNAL_STATE_MAX            (4)
+#include <nuttx/config.h>
 
-/****************************************************************************
- * Public Function Prototypes
- ****************************************************************************/
+#include <stdbool.h>
+#include <stdint.h>
 
 /****************************************************************************
- * Name: altmdm_pm_getstate
- *
- * Description:
- *   Get current modem state.
- *
+ * Public Types
  ****************************************************************************/
 
-uint32_t altmdm_pm_getstate(void);
+typedef int32_t (*lwm2mstub_hndl_t)(FAR uint8_t *, size_t,
+                          FAR void **, size_t);
 
 /****************************************************************************
- * Name: altmdm_pm_getinternalstate
- *
- * Description:
- *   Get internal modem state.
- *
+ * Public Function Prototypes
  ****************************************************************************/
 
-uint32_t altmdm_pm_getinternalstate(void);
-
 /****************************************************************************
- * Name: altmdm_pm_setinternalstate
+ * Name: lwm2mstub_get_handler
  *
  * Description:
- *   Set internal modem state.
+ *   Get handler for lwm2m stub.
+ *
+ * Input Parameters:
+ *   pktbuf   - Pointer to the received packet.
+ *   pktsz    - Pointer to the data size after parsing the received packet.
+ *   lcmdid   - Pointer to a variable that stores the lwm2m LAPI command ID.
+ *
+ * Returned Value:
+ *   If a lwm2m handler associated with the received packet is found, the
+ *   function pointer of the handler is returned. If not found, returns NULL.
  *
  ****************************************************************************/
 
-void altmdm_pm_setinternalstate(uint32_t state);
+lwm2mstub_hndl_t lwm2mstub_get_handler(FAR uint8_t **pktbuf, size_t *pktsz,

Review Comment:
   ```suggestion
   lwm2mstub_hndl_t lwm2mstub_get_handler(FAR uint8_t **pktbuf, FAR size_t 
*pktsz,
   ```
   



##########
drivers/modem/alt1250/altcom_lwm2m_hdlr.h:
##########
@@ -18,54 +18,47 @@
  *
  ****************************************************************************/
 
-#ifndef __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_STATE_H
-#define __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_STATE_H
-
-#if defined(CONFIG_MODEM_ALTMDM)
+#ifndef __DRIVERS_MODEM_ALT1250_ALTCOM_LWM2M_HDLR_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_LWM2M_HDLR_H__

Review Comment:
   ```suggestion
   #ifndef __DRIVERS_MODEM_ALT1250_ALTCOM_LWM2M_HDLR_H
   #define __DRIVERS_MODEM_ALT1250_ALTCOM_LWM2M_HDLR_H
   ```
   



##########
drivers/modem/alt1250/altcom_lwm2m_hdlr.c:
##########
@@ -0,0 +1,412 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_lwm2m_hdlr.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <nuttx/wireless/lte/lte_ioctl.h>
+
+#include "altcom_lwm2m_hdlr.h"
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int32_t read_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t write_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t exec_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t start_ov_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t stop_ov_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t fwupdate_notice_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t server_op_notice_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct urc_hdltbl_s
+{
+  const char *head;

Review Comment:
   ```suggestion
     FAR const char *head;
   ```
   



##########
drivers/modem/alt1250/altcom_lwm2m_hdlr.h:
##########
@@ -18,54 +18,47 @@
  *
  ****************************************************************************/
 
-#ifndef __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_STATE_H
-#define __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_STATE_H
-
-#if defined(CONFIG_MODEM_ALTMDM)
+#ifndef __DRIVERS_MODEM_ALT1250_ALTCOM_LWM2M_HDLR_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_LWM2M_HDLR_H__
 
 /****************************************************************************
- * Pre-processor Definitions
+ * Included Files
  ****************************************************************************/
 
-#define MODEM_PM_INTERNAL_STATE_SLEEP          (0)
-#define MODEM_PM_INTERNAL_STATE_GOING_TO_WAKE  (1)
-#define MODEM_PM_INTERNAL_STATE_WAKE           (2)
-#define MODEM_PM_INTERNAL_STATE_GOING_TO_SLEEP (3)
-#define MODEM_PM_INTERNAL_STATE_MAX            (4)
+#include <nuttx/config.h>
 
-/****************************************************************************
- * Public Function Prototypes
- ****************************************************************************/
+#include <stdbool.h>
+#include <stdint.h>
 
 /****************************************************************************
- * Name: altmdm_pm_getstate
- *
- * Description:
- *   Get current modem state.
- *
+ * Public Types
  ****************************************************************************/
 
-uint32_t altmdm_pm_getstate(void);
+typedef int32_t (*lwm2mstub_hndl_t)(FAR uint8_t *, size_t,
+                          FAR void **, size_t);
 
 /****************************************************************************
- * Name: altmdm_pm_getinternalstate
- *
- * Description:
- *   Get internal modem state.
- *
+ * Public Function Prototypes
  ****************************************************************************/
 
-uint32_t altmdm_pm_getinternalstate(void);
-
 /****************************************************************************
- * Name: altmdm_pm_setinternalstate
+ * Name: lwm2mstub_get_handler
  *
  * Description:
- *   Set internal modem state.
+ *   Get handler for lwm2m stub.
+ *
+ * Input Parameters:
+ *   pktbuf   - Pointer to the received packet.
+ *   pktsz    - Pointer to the data size after parsing the received packet.
+ *   lcmdid   - Pointer to a variable that stores the lwm2m LAPI command ID.
+ *
+ * Returned Value:
+ *   If a lwm2m handler associated with the received packet is found, the
+ *   function pointer of the handler is returned. If not found, returns NULL.
  *
  ****************************************************************************/
 
-void altmdm_pm_setinternalstate(uint32_t state);
+lwm2mstub_hndl_t lwm2mstub_get_handler(FAR uint8_t **pktbuf, size_t *pktsz,
+                                      uint32_t *lcmdid);
 
-#endif
-#endif /* __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_STATE_H */
+#endif  /* __DRIVERS_MODEM_ALT1250_ALTCOM_LWM2M_HDLR_H__ */

Review Comment:
   ```suggestion
   #endif  /* __DRIVERS_MODEM_ALT1250_ALTCOM_LWM2M_HDLR_H */
   ```
   



##########
drivers/modem/alt1250/altcom_pkt.h:
##########
@@ -0,0 +1,414 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_pkt.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __DRIVERS_MODEM_ALT1250_ALTCOM_PKT_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_PKT_H__
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <arpa/inet.h>
+
+#include <nuttx/modem/alt1250.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ALTCOM_HDR_MAGICNUMBER (0xFEEDBAC5)
+
+#define ALTCOM_CMDOPT_CHECKSUM_EN  (1 << 0)
+
+#define ALTCOM_PAYLOAD_SIZE_MAX    (4112)
+#define ALTCOM_PAYLOAD_SIZE_MAX_V4 (3092)
+#define ALTCOM_PKT_SIZE_MAX        (ALTCOM_PAYLOAD_SIZE_MAX \
+                                    + sizeof(struct altcom_cmdhdr_s) \
+                                    + sizeof(struct altcom_cmdfooter_s))
+#define ALTCOM_RX_PKT_SIZE_MAX     (ALTCOM_PAYLOAD_SIZE_MAX_V4 \
+                                    + sizeof(struct altcom_cmdhdr_s))
+
+#define LTE_RESULT_OK     (0)      /**< Result code on success */
+#define LTE_RESULT_ERROR  (1)      /**< Result code on failure */
+#define LTE_RESULT_CANCEL (2)      /**< Result code on cancel */
+
+#define ALTCOM_CMD_POWER_ON_REPLY_SIZE  (1)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+begin_packed_struct struct altcom_cmdhdr_s
+{
+  uint32_t magic;
+  uint8_t  ver;
+  uint8_t  seqid;
+  uint16_t cmdid;
+  uint16_t transid;
+  uint16_t datalen;
+  union
+    {
+      uint16_t v1_options;
+      uint16_t v4_hdr_cksum;
+    };
+  union
+    {
+      uint16_t v1_checksum;
+      uint16_t v4_data_cksum;
+    };
+  uint8_t payload[0];
+} end_packed_struct;
+
+begin_packed_struct struct altcom_cmdfooter_s
+{
+  uint16_t reserve;
+  uint16_t checksum;
+} end_packed_struct;
+
+begin_packed_struct struct altcom_errind_s
+{
+  uint8_t ver;
+  uint8_t seqid;
+  uint16_t cmdid;
+  uint16_t transid;
+  uint16_t dtlen;
+  union
+    {
+      uint16_t v1_options;
+      uint16_t v4_hdr_cksum;
+    };
+  union
+    {
+      uint16_t v1_checksum;
+      uint16_t v4_data_cksum;
+    };
+} end_packed_struct;
+
+/****************************************************************************
+ * Inline Functions
+ ****************************************************************************/
+
+static inline int is_errind(uint16_t cmdid)
+{
+  return (cmdid == ALTCOM_CMDID_ERRIND);
+}
+
+static inline uint16_t parse_cid(FAR struct altcom_cmdhdr_s *hdr)
+{
+  return hdr->cmdid;
+}
+
+static inline uint16_t parse_tid(FAR struct altcom_cmdhdr_s *hdr)
+{
+  return hdr->transid;
+}
+
+static inline uint16_t parse_cid4errind(FAR struct altcom_cmdhdr_s *hdr)
+{
+  FAR struct altcom_errind_s *pkt =
+    (FAR struct altcom_errind_s *)&hdr->payload[0];
+
+  return ntohl(pkt->cmdid);
+}
+
+static inline uint16_t parse_tid4errind(FAR struct altcom_cmdhdr_s *hdr)
+{
+  FAR struct altcom_errind_s *pkt =
+    (FAR struct altcom_errind_s *)&hdr->payload[0];
+
+  return ntohl(pkt->transid);
+}
+
+static inline FAR uint8_t *get_payload(FAR struct altcom_cmdhdr_s *hdr)
+{
+  return &hdr->payload[0];
+}
+
+static inline uint16_t get_payload_len(FAR struct altcom_cmdhdr_s *hdr)
+{
+  return hdr->datalen;
+}
+
+static inline FAR uint8_t get_altver(FAR struct altcom_cmdhdr_s *hdr)
+{
+  return hdr->ver;
+}
+
+static inline uint16_t get_pktlen(uint8_t ver, uint16_t payloadlen)
+{
+  if (ver == ALTCOM_VER1)
+    {
+      payloadlen += sizeof(struct altcom_cmdhdr_s) +
+        sizeof(struct altcom_cmdfooter_s);
+    }
+  else if (ver == ALTCOM_VER4)
+    {
+      payloadlen += sizeof(struct altcom_cmdhdr_s);
+    }
+  else
+    {
+      DEBUGASSERT(0);
+    }
+
+  return payloadlen;
+}
+
+static inline uint16_t convert_cid2v1(uint16_t cid)
+{
+  if ((cid >= APICMDID_SOCK_ACCEPT) && (cid <= APICMDID_SOCK_SETSOCKOPT))
+    {
+      return cid;
+    }
+
+  if ((cid >= APICMDID_SMS_INIT) && (cid <= APICMDID_SMS_DELETE))
+    {
+      return cid;
+    }
+
+  if ((cid >= APICMDID_GET_VERSION_V4) && (cid <= APICMDID_SET_PSM_V4))
+    {
+      return (cid + 1);
+    }
+
+  if ((cid >= APICMDID_RADIO_ON_V4) && (cid <= APICMDID_ACTIVATE_PDN_V4))
+    {
+      return (cid - 0x2ec);
+    }
+
+  if ((cid >= APICMDID_DEACTIVATE_PDN_V4) &&
+      (cid <= APICMDID_REPORT_NETINFO_V4))
+    {
+      return (cid - 0x2ed);
+    }
+
+  if (cid == (APICMDID_ERRINFO_V4 & ~ALTCOM_CMDID_REPLY_BIT))
+    {
+      return APICMDID_ERRINFO;
+    }
+
+  if (cid == APICMDID_GET_SIMINFO_V4)
+    {
+      return APICMDID_GET_SIMINFO;
+    }
+
+  if (cid == APICMDID_GET_QUALITY_V4)
+    {
+      return APICMDID_GET_QUALITY;
+    }
+
+  if (cid == APICMDID_ACTIVATE_PDN_CANCEL_V4)
+    {
+      return APICMDID_ACTIVATE_PDN_CANCEL;
+    }
+
+  if (cid == APICMDID_GET_CELLINFO_V4)
+    {
+      return APICMDID_GET_CELLINFO;
+    }
+
+  if (cid == APICMDID_GET_RAT_V4)
+    {
+      return APICMDID_GET_RAT;
+    }
+
+  if (cid == APICMDID_SET_RAT_V4)
+    {
+      return APICMDID_SET_RAT;
+    }
+
+  if (cid == APICMDID_SEND_ATCMD_V4)
+    {
+      return APICMDID_SEND_ATCMD;
+    }
+
+  if (cid == APICMDID_URC_EVENT_V4)
+    {
+      return APICMDID_URC_EVENT;
+    }
+
+  if ((cid >= APICMDID_FW_INJECTDELTAIMG_V4) &&
+      (cid <= APICMDID_FW_GETUPDATERESULT_V4))
+    {
+      return (cid + 0xdd0);
+    }
+
+  if (cid == APICMDID_TLS_CONFIG_VERIFY_CALLBACK_V4)
+    {
+      return APICMDID_TLS_CONFIG_VERIFY_CALLBACK;
+    }
+
+  if (cid == APICMDID_CLOGS_V4)
+    {
+      return APICMDID_CLOGS;
+    }
+
+  if (cid == APICMDID_LOGLIST_V4)
+    {
+      return APICMDID_LOGLIST;
+    }
+
+#ifdef CONFIG_MODEM_ALT1250_LOG_ACCESS
+  if ((cid >= APICMDID_LOGOPEN_V4) && (cid <= APICMDID_LOGLSEEK_V4))
+    {
+      return cid + (APICMDID_LOGOPEN - APICMDID_LOGOPEN_V4);
+    }
+#endif /* CONFIG_MODEM_ALT1250_LOG_ACCESS */
+
+  return APICMDID_UNKNOWN;
+}
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: altcom_make_poweron_cmd_v1
+ *
+ * Description:
+ *   Create an ALTCOM command for POWER_ON_REQ of protocol version 1.
+ *
+ * Input Parameters:
+ *   sz         - Variable to put the length of the command created.
+ *
+ * Returned Value:
+ *   Returns the buffer pointer of the created command.
+ *
+ ****************************************************************************/
+
+FAR void *altcom_make_poweron_cmd_v1(int *sz);

Review Comment:
   ```suggestion
   FAR void *altcom_make_poweron_cmd_v1(FAR int *sz);
   ```
   



##########
drivers/modem/alt1250/altcom_lwm2m_hdlr.c:
##########
@@ -0,0 +1,412 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_lwm2m_hdlr.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+#include <nuttx/wireless/lte/lte_ioctl.h>
+
+#include "altcom_lwm2m_hdlr.h"
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static int32_t read_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t write_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t exec_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t start_ov_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t stop_ov_request_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t fwupdate_notice_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+static int32_t server_op_notice_hndl(FAR uint8_t *pktbuf, size_t pktsz,
+                          FAR void **cb_args, size_t arglen);
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct urc_hdltbl_s
+{
+  const char *head;
+  uint32_t lcmdid;
+  lwm2mstub_hndl_t hdlr;
+};
+
+struct lwm2mstub_instance_s
+{
+  int object_id;
+  int object_inst;
+  int res_id;
+  int res_inst;
+};
+
+struct lwm2mstub_ovcondition_s
+{
+    uint8_t valid_mask;
+    unsigned int min_period;
+    unsigned int max_period;
+    double gt_cond;
+    double lt_cond;
+    double step_val;
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static struct urc_hdltbl_s urc_idhandles[] =
+{
+  { "%LWM2MOBJCMDU: \"READ\",",
+    LTE_CMDID_LWM2M_READ_EVT, read_request_hndl },
+
+  { "%LWM2MOBJCMDU: \"WRITE\",",
+    LTE_CMDID_LWM2M_WRITE_EVT, write_request_hndl },
+
+  { "%LWM2MOBJCMDU: \"EXE\",",
+    LTE_CMDID_LWM2M_EXEC_EVT, exec_request_hndl },
+
+  { "%LWM2MOBJCMDU: \"OBSERVE_START\",",
+    LTE_CMDID_LWM2M_OVSTART_EVT, start_ov_request_hndl },
+
+  { "%LWM2MOBJCMDU: \"OBSERVE_STOP\",",
+    LTE_CMDID_LWM2M_OVSTOP_EVT, stop_ov_request_hndl },
+
+  { "%LWM2MOPEV: ",
+    LTE_CMDID_LWM2M_SERVEROP_EVT, server_op_notice_hndl },
+
+  { "%LWM2MEV: ",
+    LTE_CMDID_LWM2M_FWUP_EVT, fwupdate_notice_hndl },
+
+  {
+    NULL, 0, NULL
+  },
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * name: skip_until
+ ****************************************************************************/
+
+static uint8_t *skip_until(FAR uint8_t *stream, FAR char *delim)
+{
+  for (; *stream && !strchr(delim, *stream); stream++);
+  for (; *stream && strchr(delim, *stream); stream++);
+
+  if (*stream == '\0')
+    {
+      stream = NULL;
+    }
+
+  return stream;
+}
+
+/****************************************************************************
+ * name: strcpy_until
+ ****************************************************************************/
+
+static char strcpy_until(char *dst, int n, char **src, char *delim)

Review Comment:
   Add FAR



##########
drivers/modem/alt1250/altcom_pkt.h:
##########
@@ -0,0 +1,414 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_pkt.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __DRIVERS_MODEM_ALT1250_ALTCOM_PKT_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_PKT_H__

Review Comment:
   ```suggestion
   #ifndef __DRIVERS_MODEM_ALT1250_ALTCOM_PKT_H
   #define __DRIVERS_MODEM_ALT1250_ALTCOM_PKT_H
   ```
   



##########
drivers/modem/alt1250/altmdm.h:
##########
@@ -0,0 +1,240 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altmdm.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __DRIVERS_MODEM_ALT1250_ALTMDM_H__
+#define __DRIVERS_MODEM_ALT1250_ALTMDM_H__
+

Review Comment:
   ```suggestion
   #ifndef __DRIVERS_MODEM_ALT1250_ALTMDM_H
   #define __DRIVERS_MODEM_ALT1250_ALTMDM_H
   
   ```
   



##########
include/nuttx/modem/alt1250.h:
##########
@@ -0,0 +1,394 @@
+/****************************************************************************
+ * include/nuttx/modem/alt1250.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_MODEM_ALT1250_H
+#define __INCLUDE_NUTTX_MODEM_ALT1250_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/fs/ioctl.h>
+#include <nuttx/spi/spi.h>
+#include <nuttx/queue.h>
+#include <semaphore.h>
+#include <debug.h>
+#include <nuttx/irq.h>
+#include <pthread.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Debug ********************************************************************/
+
+/* Non-standard debug that may be enabled just for testing the modem driver */
+
+#ifdef CONFIG_MODEM_ALT1250_DEBUG
+#  define m_err     _err
+#  define m_warn    _warn
+#  define m_info    _info
+#else
+#  define m_err(x...)

Review Comment:
   Why do we need `x` here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to