You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/10/06 20:28:23 UTC

[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #7248: drivers: modem: update altair modem

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


##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);

Review Comment:
   ```suggestion
   static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
                               size_t len);
   ```



##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int alt1250_poll(FAR struct file *filep, struct pollfd *fds,
+  bool setup);

Review Comment:
   ```suggestion
   static int alt1250_poll(FAR struct file *filep, FAR struct pollfd *fds,
                           bool setup);
   ```



##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int alt1250_poll(FAR struct file *filep, struct pollfd *fds,
+  bool setup);
+
+parse_handler_t alt1250_additional_parsehdlr(uint16_t, uint8_t);
+compose_handler_t alt1250_additional_composehdlr(uint32_t,
+    FAR uint8_t *, size_t);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* This the vtable that supports the character driver interface. */
+
+static const struct file_operations g_alt1250fops =
+{
+  alt1250_open,  /* open */
+  alt1250_close, /* close */
+  alt1250_read,  /* read */
+  0,             /* write */
+  0,             /* seek */
+  alt1250_ioctl, /* ioctl */
+  alt1250_poll,  /* poll */
+};
+static uint8_t g_recvbuff[ALTCOM_RX_PKT_SIZE_MAX];
+static uint8_t g_sendbuff[ALTCOM_PKT_SIZE_MAX];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: add_list
+ ****************************************************************************/
+
+static void add_list(FAR struct alt_queue_s *head,
+  FAR struct alt_container_s *list)
+{
+  FAR struct alt_container_s *next;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  while (list != NULL)
+    {
+      next = (FAR struct alt_container_s *)sq_next(&list->node);
+
+      sq_next(&list->node) = NULL;
+      sq_addlast(&list->node, &head->queue);
+
+      list = next;
+    }
+
+  nxsem_post(&head->lock);
+}
+
+/****************************************************************************
+ * Name: remove_list_all
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list_all(
+  FAR struct alt_queue_s *head)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  sq_init(&head->queue);
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: remove_list
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list(FAR struct alt_queue_s *head,
+  uint16_t cmdid, uint16_t transid)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  while (list != NULL)
+    {
+      if ((list->altcid == cmdid) && (list->alttid == transid))
+        {
+          sq_rem(&list->node, &head->queue);
+          sq_next(&list->node) = NULL;
+          break;
+        }
+
+      list = (FAR struct alt_container_s *)sq_next(&list->node);
+    }
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: set_senddisable
+ ****************************************************************************/
+
+static void set_senddisable(FAR struct alt1250_dev_s *dev, bool disable)
+{
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  dev->senddisable = disable;
+
+  nxsem_post(&dev->senddisablelock);
+}
+
+/****************************************************************************
+ * Name: is_senddisable
+ ****************************************************************************/
+
+static bool is_senddisable(FAR struct alt1250_dev_s *dev)
+{
+  bool disable;
+
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  disable = dev->senddisable;
+
+  nxsem_post(&dev->senddisablelock);
+
+  return disable;
+}
+
+/****************************************************************************
+ * Name: read_evtbitmap
+ ****************************************************************************/
+
+static ssize_t read_data(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_readdata_s *rdata)

Review Comment:
   ```suggestion
   static ssize_t read_data(FAR struct alt1250_dev_s *dev,
                            FAR struct alt_readdata_s *rdata)
   ```



##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int alt1250_poll(FAR struct file *filep, struct pollfd *fds,
+  bool setup);
+
+parse_handler_t alt1250_additional_parsehdlr(uint16_t, uint8_t);
+compose_handler_t alt1250_additional_composehdlr(uint32_t,
+    FAR uint8_t *, size_t);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* This the vtable that supports the character driver interface. */
+
+static const struct file_operations g_alt1250fops =
+{
+  alt1250_open,  /* open */
+  alt1250_close, /* close */
+  alt1250_read,  /* read */
+  0,             /* write */
+  0,             /* seek */
+  alt1250_ioctl, /* ioctl */
+  alt1250_poll,  /* poll */
+};
+static uint8_t g_recvbuff[ALTCOM_RX_PKT_SIZE_MAX];
+static uint8_t g_sendbuff[ALTCOM_PKT_SIZE_MAX];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: add_list
+ ****************************************************************************/
+
+static void add_list(FAR struct alt_queue_s *head,
+  FAR struct alt_container_s *list)
+{
+  FAR struct alt_container_s *next;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  while (list != NULL)
+    {
+      next = (FAR struct alt_container_s *)sq_next(&list->node);
+
+      sq_next(&list->node) = NULL;
+      sq_addlast(&list->node, &head->queue);
+
+      list = next;
+    }
+
+  nxsem_post(&head->lock);
+}
+
+/****************************************************************************
+ * Name: remove_list_all
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list_all(
+  FAR struct alt_queue_s *head)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  sq_init(&head->queue);
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: remove_list
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list(FAR struct alt_queue_s *head,
+  uint16_t cmdid, uint16_t transid)

Review Comment:
   ```suggestion
   static FAR struct alt_container_s *remove_list(FAR struct alt_queue_s *head,
                                                  uint16_t cmdid, uint16_t transid)
   ```



##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int alt1250_poll(FAR struct file *filep, struct pollfd *fds,
+  bool setup);
+
+parse_handler_t alt1250_additional_parsehdlr(uint16_t, uint8_t);
+compose_handler_t alt1250_additional_composehdlr(uint32_t,
+    FAR uint8_t *, size_t);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* This the vtable that supports the character driver interface. */
+
+static const struct file_operations g_alt1250fops =
+{
+  alt1250_open,  /* open */
+  alt1250_close, /* close */
+  alt1250_read,  /* read */
+  0,             /* write */
+  0,             /* seek */
+  alt1250_ioctl, /* ioctl */
+  alt1250_poll,  /* poll */
+};
+static uint8_t g_recvbuff[ALTCOM_RX_PKT_SIZE_MAX];
+static uint8_t g_sendbuff[ALTCOM_PKT_SIZE_MAX];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: add_list
+ ****************************************************************************/
+
+static void add_list(FAR struct alt_queue_s *head,
+  FAR struct alt_container_s *list)
+{
+  FAR struct alt_container_s *next;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  while (list != NULL)
+    {
+      next = (FAR struct alt_container_s *)sq_next(&list->node);
+
+      sq_next(&list->node) = NULL;
+      sq_addlast(&list->node, &head->queue);
+
+      list = next;
+    }
+
+  nxsem_post(&head->lock);
+}
+
+/****************************************************************************
+ * Name: remove_list_all
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list_all(
+  FAR struct alt_queue_s *head)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  sq_init(&head->queue);
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: remove_list
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list(FAR struct alt_queue_s *head,
+  uint16_t cmdid, uint16_t transid)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  while (list != NULL)
+    {
+      if ((list->altcid == cmdid) && (list->alttid == transid))
+        {
+          sq_rem(&list->node, &head->queue);
+          sq_next(&list->node) = NULL;
+          break;
+        }
+
+      list = (FAR struct alt_container_s *)sq_next(&list->node);
+    }
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: set_senddisable
+ ****************************************************************************/
+
+static void set_senddisable(FAR struct alt1250_dev_s *dev, bool disable)
+{
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  dev->senddisable = disable;
+
+  nxsem_post(&dev->senddisablelock);
+}
+
+/****************************************************************************
+ * Name: is_senddisable
+ ****************************************************************************/
+
+static bool is_senddisable(FAR struct alt1250_dev_s *dev)
+{
+  bool disable;
+
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  disable = dev->senddisable;
+
+  nxsem_post(&dev->senddisablelock);
+
+  return disable;
+}
+
+/****************************************************************************
+ * Name: read_evtbitmap
+ ****************************************************************************/
+
+static ssize_t read_data(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_readdata_s *rdata)
+{
+  int idx;
+
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  /* change status to NOT WRITABLE */
+
+  for (idx = 0; idx < (sizeof(uint64_t) * 8); idx++)
+    {
+      if (dev->evtbitmap & (1ULL << idx))
+        {
+          if (dev->evtbuff->ninst >= idx)
+            {
+              FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx];
+
+              nxsem_wait_uninterruptible(&inst->stat_lock);
+
+              inst->stat = ALTEVTBUF_ST_NOTWRITABLE;
+
+              nxsem_post(&inst->stat_lock);
+            }
+        }
+    }
+
+  rdata->evtbitmap = dev->evtbitmap;
+  rdata->head = remove_list_all(&dev->replylist);
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      /* Resume sending because daemon has been notified of the reset
+       * reliably.
+       */
+
+      set_senddisable(dev, false);
+    }
+
+  dev->evtbitmap = 0ULL;
+
+  nxsem_post(&dev->evtmaplock);
+
+  return sizeof(struct alt_readdata_s);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmap
+ ****************************************************************************/
+
+static void write_evtbitmap(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  m_info("write bitmap: 0x%llx\n", bitmap);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmapwithlist
+ ****************************************************************************/
+
+static void write_evtbitmapwithlist(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap, FAR struct alt_container_s *container)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  add_list(&dev->replylist, container);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: add_evtbuff
+ ****************************************************************************/
+
+static void add_evtbuff(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_evtbuffer_s *buff)

Review Comment:
   ```suggestion
   static void add_evtbuff(FAR struct alt1250_dev_s *dev,
                           FAR struct alt_evtbuffer_s *buff)
   ```



##########
drivers/modem/alt1250/alt1250.h:
##########
@@ -0,0 +1,59 @@
+/****************************************************************************
+ * drivers/modem/alt1250/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 __DRIVERS_MODEM_ALT1250_ALT1250_H__
+#define __DRIVERS_MODEM_ALT1250_ALT1250_H__

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



##########
drivers/modem/alt1250/alt1250.h:
##########
@@ -0,0 +1,59 @@
+/****************************************************************************
+ * drivers/modem/alt1250/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 __DRIVERS_MODEM_ALT1250_ALT1250_H__
+#define __DRIVERS_MODEM_ALT1250_ALT1250_H__
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+
+#include <stdbool.h>
+#include <stdint.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: get_event_lapibuffer
+ *
+ * Description:
+ *   Gets the buffer used in the LAPI event.
+ *
+ * Input Parameters:
+ *   dev         - An device instance of the ALT11250 driver.
+ *   lapicmdid   - ID of the LAPI command.
+ *   inst        - A pointer to an instance of the LAPI event buffer.
+ *
+ * Returned Value:
+ *   Returns a bitmap indicating the location of the LAPI event buffer.
+ *   If the buffer associated with the specified lapicmdid does not exist,
+ *   NULL is returned.
+ *
+ ****************************************************************************/
+
+uint64_t get_event_lapibuffer(FAR struct alt1250_dev_s *dev,
+  uint32_t lapicmdid, alt_evtbuf_inst_t **inst);
+
+#endif  /* __DRIVERS_MODEM_ALT1250_ALT1250_H__ */

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



##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int alt1250_poll(FAR struct file *filep, struct pollfd *fds,
+  bool setup);
+
+parse_handler_t alt1250_additional_parsehdlr(uint16_t, uint8_t);
+compose_handler_t alt1250_additional_composehdlr(uint32_t,
+    FAR uint8_t *, size_t);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* This the vtable that supports the character driver interface. */
+
+static const struct file_operations g_alt1250fops =
+{
+  alt1250_open,  /* open */
+  alt1250_close, /* close */
+  alt1250_read,  /* read */
+  0,             /* write */
+  0,             /* seek */
+  alt1250_ioctl, /* ioctl */
+  alt1250_poll,  /* poll */
+};
+static uint8_t g_recvbuff[ALTCOM_RX_PKT_SIZE_MAX];
+static uint8_t g_sendbuff[ALTCOM_PKT_SIZE_MAX];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: add_list
+ ****************************************************************************/
+
+static void add_list(FAR struct alt_queue_s *head,
+  FAR struct alt_container_s *list)
+{
+  FAR struct alt_container_s *next;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  while (list != NULL)
+    {
+      next = (FAR struct alt_container_s *)sq_next(&list->node);
+
+      sq_next(&list->node) = NULL;
+      sq_addlast(&list->node, &head->queue);
+
+      list = next;
+    }
+
+  nxsem_post(&head->lock);
+}
+
+/****************************************************************************
+ * Name: remove_list_all
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list_all(
+  FAR struct alt_queue_s *head)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  sq_init(&head->queue);
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: remove_list
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list(FAR struct alt_queue_s *head,
+  uint16_t cmdid, uint16_t transid)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  while (list != NULL)
+    {
+      if ((list->altcid == cmdid) && (list->alttid == transid))
+        {
+          sq_rem(&list->node, &head->queue);
+          sq_next(&list->node) = NULL;
+          break;
+        }
+
+      list = (FAR struct alt_container_s *)sq_next(&list->node);
+    }
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: set_senddisable
+ ****************************************************************************/
+
+static void set_senddisable(FAR struct alt1250_dev_s *dev, bool disable)
+{
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  dev->senddisable = disable;
+
+  nxsem_post(&dev->senddisablelock);
+}
+
+/****************************************************************************
+ * Name: is_senddisable
+ ****************************************************************************/
+
+static bool is_senddisable(FAR struct alt1250_dev_s *dev)
+{
+  bool disable;
+
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  disable = dev->senddisable;
+
+  nxsem_post(&dev->senddisablelock);
+
+  return disable;
+}
+
+/****************************************************************************
+ * Name: read_evtbitmap
+ ****************************************************************************/
+
+static ssize_t read_data(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_readdata_s *rdata)
+{
+  int idx;
+
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  /* change status to NOT WRITABLE */
+
+  for (idx = 0; idx < (sizeof(uint64_t) * 8); idx++)
+    {
+      if (dev->evtbitmap & (1ULL << idx))
+        {
+          if (dev->evtbuff->ninst >= idx)
+            {
+              FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx];
+
+              nxsem_wait_uninterruptible(&inst->stat_lock);
+
+              inst->stat = ALTEVTBUF_ST_NOTWRITABLE;
+
+              nxsem_post(&inst->stat_lock);
+            }
+        }
+    }
+
+  rdata->evtbitmap = dev->evtbitmap;
+  rdata->head = remove_list_all(&dev->replylist);
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      /* Resume sending because daemon has been notified of the reset
+       * reliably.
+       */
+
+      set_senddisable(dev, false);
+    }
+
+  dev->evtbitmap = 0ULL;
+
+  nxsem_post(&dev->evtmaplock);
+
+  return sizeof(struct alt_readdata_s);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmap
+ ****************************************************************************/
+
+static void write_evtbitmap(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  m_info("write bitmap: 0x%llx\n", bitmap);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmapwithlist
+ ****************************************************************************/
+
+static void write_evtbitmapwithlist(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap, FAR struct alt_container_s *container)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  add_list(&dev->replylist, container);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: add_evtbuff
+ ****************************************************************************/
+
+static void add_evtbuff(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_evtbuffer_s *buff)
+{
+  dev->evtbuff = buff;
+}
+
+/****************************************************************************
+ * Name: write_evtbuff_byidx
+ ****************************************************************************/
+
+static int write_evtbuff_byidx(FAR struct alt1250_dev_s *dev,
+  uint64_t idx, void(*write_func)(FAR void *outp[], FAR void *inp),
+  FAR void *inp)
+{
+  int ret = WRITE_NG;
+
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  if (dev->evtbuff)
+    {
+      if (dev->evtbuff->ninst >= idx)
+        {
+          FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx];
+
+          nxsem_wait_uninterruptible(&inst->stat_lock);
+          if (inst->stat == ALTEVTBUF_ST_WRITABLE)
+            {
+              write_func(inst->outparam, inp);
+              dev->evtbitmap |= (1ULL << idx);
+              ret = WRITE_OK;
+            }
+
+          nxsem_post(&inst->stat_lock);
+        }
+    }
+
+  nxsem_post(&dev->evtmaplock);
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: lock_evtbuffinst
+ ****************************************************************************/
+
+static void lock_evtbuffinst(FAR alt_evtbuf_inst_t *inst,
+  FAR struct alt1250_dev_s *dev)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+  nxsem_wait_uninterruptible(&inst->stat_lock);
+}
+
+/****************************************************************************
+ * Name: unlock_evtbufinst
+ ****************************************************************************/
+
+static void unlock_evtbufinst(FAR alt_evtbuf_inst_t *inst,
+  FAR struct alt1250_dev_s *dev)
+{
+  nxsem_post(&inst->stat_lock);
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: search_evtbufinst
+ ****************************************************************************/
+
+static FAR alt_evtbuf_inst_t *search_evtbufinst(uint16_t cid,
+  FAR uint64_t *bitmap, FAR struct alt1250_dev_s *dev)
+{
+  FAR alt_evtbuf_inst_t *ret = NULL;
+  unsigned int i;
+
+  *bitmap = 0ULL;
+
+  for (i = 0; i < dev->evtbuff->ninst; i++)
+    {
+      ret = &dev->evtbuff->inst[i];
+
+      if (ret->altcid == cid)
+        {
+          *bitmap = 1ULL << i;
+          return ret;
+        }
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: cid_to_searchable
+ ****************************************************************************/
+
+static uint16_t cid_to_searchable(uint16_t cid, uint8_t altver)
+{
+  uint16_t cidv1;
+
+  cid &= ~ALTCOM_CMDID_REPLY_BIT;
+  if (altver == ALTCOM_VER4)
+    {
+      /* Change the command ID to Version 1
+       * Even if it cannot be converted, try to search the table
+       * using the original command ID.
+       */
+
+      cidv1 = convert_cid2v1(cid);
+      if (cidv1 != APICMDID_UNKNOWN)
+        {
+          cid = cidv1;
+        }
+    }
+
+  return cid;
+}
+
+/****************************************************************************
+ * Name: get_bitmap
+ ****************************************************************************/
+
+static uint64_t get_bitmap(FAR struct alt1250_dev_s *dev, uint16_t cid,
+  uint8_t altver)
+{
+  uint64_t bitmap = 0ULL;
+
+  cid = cid_to_searchable(cid, altver);
+
+  search_evtbufinst(cid, &bitmap, dev);
+
+  return bitmap;
+}
+
+/****************************************************************************
+ * Name: get_evtbuffinst_withlock
+ ****************************************************************************/
+
+static FAR alt_evtbuf_inst_t *get_evtbuffinst_withlock(
+  FAR struct alt1250_dev_s *dev, uint16_t cid, uint8_t altver,
+  FAR uint64_t *bitmap)
+{
+  FAR alt_evtbuf_inst_t *inst = NULL;
+  FAR alt_evtbuf_inst_t *ret = NULL;
+
+  cid = cid_to_searchable(cid, altver);
+
+  if (cid == APICMDID_SOCK_SELECT)
+    {
+      ret = &dev->select_inst;
+
+      lock_evtbuffinst(ret, dev);
+
+      ret->outparam = dev->select_container->outparam;
+      ret->outparamlen = dev->select_container->outparamlen;
+
+      search_evtbufinst(cid, bitmap, dev);
+    }
+  else
+    {
+      inst = search_evtbufinst(cid, bitmap, dev);
+      if (inst)
+        {
+          lock_evtbuffinst(inst, dev);
+
+          if (inst->stat == ALTEVTBUF_ST_WRITABLE)
+            {
+              ret = inst;
+            }
+          else
+            {
+              unlock_evtbufinst(inst, dev);
+            }
+        }
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: write_restart_param
+ ****************************************************************************/
+
+static void write_restart_param(FAR void *outp[], FAR void *buff)
+{
+  FAR int *out_reason = (FAR int *)outp[0];
+  FAR int *in_reason = (FAR int *)buff;
+
+  *out_reason = *in_reason;
+}
+
+/****************************************************************************
+ * Name: pollnotify
+ ****************************************************************************/
+
+static void pollnotify(FAR struct alt1250_dev_s *dev)
+{
+  nxsem_wait_uninterruptible(&dev->pfdlock);
+
+  if (dev->pfd)
+    {
+      /* If poll() waits, notify  */
+
+      poll_notify(&dev->pfd, 1, POLLIN);
+    }
+
+  nxsem_post(&dev->pfdlock);
+}
+
+/****************************************************************************
+ * Name: get_composehdlr
+ ****************************************************************************/
+
+compose_handler_t get_composehdlr(uint32_t cmdid, FAR uint8_t *payload,
+  size_t size)
+{
+  compose_handler_t ret = NULL;
+
+  ret = alt1250_composehdlr(cmdid);
+
+#ifdef CONFIG_MODEM_ALT1250_ADDITIONAL_FUNC
+  if (ret == NULL)
+    {
+      ret = alt1250_additional_composehdlr(cmdid, payload, size);
+    }
+#endif
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: get_parsehdlr
+ ****************************************************************************/
+
+parse_handler_t get_parsehdlr(uint16_t altcid, uint8_t altver)
+{
+  parse_handler_t ret = NULL;
+
+  ret = alt1250_parsehdlr(altcid, altver);
+
+#ifdef CONFIG_MODEM_ALT1250_ADDITIONAL_FUNC
+  if (ret == NULL)
+    {
+      ret = alt1250_additional_parsehdlr(altcid, altver);
+    }
+#endif
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: alt1250_power_control
+ ****************************************************************************/
+
+static int alt1250_power_control(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_power_s *req)
+{
+  int ret = OK;
+
+  switch (req->cmdid)
+    {
+      case LTE_CMDID_POWERON:
+        ret = altmdm_poweron();
+        break;
+
+      case LTE_CMDID_POWEROFF:
+        ret = altmdm_poweroff();
+        break;
+
+      case LTE_CMDID_TAKEWLOCK:
+        ret = altmdm_take_wlock();
+        break;
+
+      case LTE_CMDID_GIVEWLOCK:
+        ret = altmdm_give_wlock();
+        break;
+
+      default:
+        ret = -EINVAL;
+        break;
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: make_altcomcmd_and_send
+ ****************************************************************************/
+
+static int make_altcomcmd_and_send(FAR struct alt1250_dev_s *dev,
+  FAR alt_container_t *req)
+{
+  int ret = OK;
+  compose_handler_t handler;
+  uint8_t altver;
+  uint16_t cid;
+  uint16_t tid;
+  FAR uint8_t *payload;
+  int remainlen;
+  int pos;
+
+  m_info("send request: command ID=0x%08lx\n", req->cmdid);
+
+  payload = get_payload((FAR struct altcom_cmdhdr_s *)g_sendbuff);
+
+  handler = get_composehdlr(req->cmdid & ~LTE_CMDOPT_ASYNC_BIT, payload,
+    ALTCOM_PAYLOAD_SIZE_MAX);
+  if (handler)
+    {
+      altver = altmdm_get_protoversion();
+      if ((altver == ALTCOM_VERX) || is_senddisable(dev))
+        {
+          ret = -ENETDOWN;
+        }
+      else
+        {
+          ret = handler(req->inparam, req->inparamlen, altver, payload,
+            ALTCOM_PAYLOAD_SIZE_MAX, &cid);
+
+          ret = (ret > ALTCOM_PAYLOAD_SIZE_MAX) ? -ENOSPC : ret;
+
+          if (ret >= 0)
+            {
+              tid = altcom_make_header(
+                (FAR struct altcom_cmdhdr_s *)g_sendbuff,
+                altver, cid, ret);
+
+              req->altcid = cid | ALTCOM_CMDID_REPLY_BIT;
+              req->alttid = tid;
+
+              if (req->outparam != NULL)
+                {
+                  add_list(&dev->waitlist, req);
+                }
+
+              remainlen = get_pktlen(altver, (uint16_t)ret);
+              pos = 0;
+
+              /* If the modem sleeps during the split transmission,
+               * the receive buffer of the modem will be cleared.
+               * Therefore, split packets sent before sleep will be
+               * discarded. To avoid this, do not enter sleep state
+               * until all the packets have been sent.
+               */
+
+              altmdm_take_wlock();
+
+              do
+                {
+                  ret = altmdm_write(&g_sendbuff[pos], remainlen);
+                  if (ret < 0)
+                    {
+                      break;
+                    }
+                  else
+                    {
+                      m_info(
+                        "write success: size=%d, cid=0x%04x tid=0x%04x\n",
+                        ret, cid, tid);
+                      remainlen -= ret;
+                      pos += ret;
+                    }
+                }
+              while (remainlen > 0);
+
+              altmdm_give_wlock();
+
+              if (ret < 0)
+                {
+                  m_err("altmdm_write() failed: %d\n", ret);
+                  ret = -ENETDOWN;
+
+                  /* If the container is not left in the waitlist,
+                   * it has already been processed by the recvthread.
+                   * ENETRESET is returned to the caller to indicate that
+                   * the container has been processed.
+                   */
+
+                  if ((req->outparam != NULL) &&
+                    (remove_list(&dev->waitlist, req->altcid, req->alttid)
+                      == NULL))
+                    {
+                      ret = -ENETRESET;
+                    }
+                }
+              else
+                {
+                  m_info("write success: size=%d, cid=0x%04x tid=0x%04x\n",
+                    ret, cid, tid);
+                  ret = OK;
+                }
+            }
+          else
+            {
+              m_err("handler() failed: %d\n", ret);
+            }
+        }
+    }
+  else
+    {
+      ret = -ENOSYS;
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: exchange_selectcontainer
+ ****************************************************************************/
+
+static int exchange_selectcontainer(FAR struct alt1250_dev_s *dev,
+  FAR alt_container_t **container)
+{
+  FAR alt_container_t *newcontainer;
+
+  if (container == NULL)
+    {
+      return -EINVAL;
+    }
+
+  nxsem_wait_uninterruptible(&dev->select_inst.stat_lock);
+
+  newcontainer = *container;
+  *container = dev->select_container;
+  dev->select_container = newcontainer;
+
+  nxsem_post(&dev->select_inst.stat_lock);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: altcom_recvthread
+ ****************************************************************************/
+
+static void altcom_recvthread(FAR void *arg)
+{
+  int ret;
+  FAR struct alt1250_dev_s *dev = (FAR struct alt1250_dev_s *)arg;
+  bool is_running = true;
+  FAR struct alt_container_s *head;
+  FAR struct alt_container_s *container;
+  uint16_t cid;
+  uint16_t tid;
+  uint8_t altver;
+  parse_handler_t handler;
+  uint64_t bitmap = 0ULL;
+  int recvedlen = 0;
+
+  m_info("recv thread start\n");
+
+  altmdm_init(dev->spi, dev->lower);
+
+  while (is_running)
+    {
+      ret = altmdm_read(g_recvbuff + recvedlen,
+                        ALTCOM_RX_PKT_SIZE_MAX - recvedlen);
+
+      /* Normal packet received */
+
+      if (ret >= 0)
+        {
+          m_info("read packet %d bytes\n", ret);
+
+          recvedlen += ret;
+
+          ret = altcom_is_pkt_ok(g_recvbuff, recvedlen);
+          if (ret > 0)
+            {
+              /* Cases in which fragmented packets are received.
+               * Therefore, the receive process is performed again.
+               */
+
+              m_info("This is fragmented packet received. remain len: %d\n",
+                     ret);
+              continue;
+            }
+
+          if (ret < 0)
+            {
+              /* Forced reset of modem due to packet format error detected */
+
+              m_err("[altcom] Forced modem reset due to parse failure\n");
+
+              altmdm_reset();
+            }
+          else
+            {
+              bool is_discard = false;
+
+              /* parse ALTCOM command ID and transaction ID from header */
+
+              cid = parse_cid((FAR struct altcom_cmdhdr_s *)g_recvbuff);
+              tid = parse_tid((FAR struct altcom_cmdhdr_s *)g_recvbuff);
+              altver = get_altver(
+                    (FAR struct altcom_cmdhdr_s *)g_recvbuff);
+
+              m_info("receive cid:0x%04x tid:0x%04x\n", cid, tid);
+
+              /* Is error indication packet?
+               * This packet is a response to a command that is not supported
+               * by the ALT1250. The header of the request packet is included
+               * in the contents of the this packet.
+               */
+
+              if (is_errind(cid))
+                {
+                  /* Get ALTCOM command ID and transaction ID
+                   * from error indication packet
+                   */
+
+                  cid = parse_cid4errind(
+                    (FAR struct altcom_cmdhdr_s *)g_recvbuff);
+                  tid = parse_tid4errind(
+                    (FAR struct altcom_cmdhdr_s *)g_recvbuff);
+
+                  m_info("receive errind cid:0x%04x tid:0x%04x\n", cid, tid);
+
+                  container = remove_list(&dev->waitlist, cid, tid);
+                  if (container)
+                    {
+                      /* It means that requested command not implemented
+                       * by modem
+                       */
+
+                      container->result = -ENOSYS;
+                    }
+                  else
+                    {
+                      /* Discard the event packet */
+
+                      is_discard = true;
+
+                      m_warn("container is not found\n");
+                    }
+                }
+              else
+                {
+                  container = remove_list(&dev->waitlist, cid, tid);
+
+                  handler = get_parsehdlr(cid, altver);
+                  if (handler)
+                    {
+                      FAR uint8_t *payload = get_payload(
+                        (FAR struct altcom_cmdhdr_s *)g_recvbuff);
+
+                      if (container)
+                        {
+                          m_info("handler and container is found\n");
+
+                          bitmap = get_bitmap(dev, cid, altver);
+
+                          /* Perform parse handler */
+
+                          container->result = handler(dev, payload,
+                            get_payload_len(
+                              (FAR struct altcom_cmdhdr_s *)g_recvbuff),
+                            altver, container->outparam,
+                            container->outparamlen, &bitmap);
+                        }
+                      else
+                        {
+                          FAR alt_evtbuf_inst_t *inst;
+
+                          m_warn("container is not found\n");
+
+                          /* If the state of the instance is NotWritable,
+                           * instanse will be returned as NULL.
+                           */
+
+                          inst = get_evtbuffinst_withlock(dev, cid, altver,
+                                                          &bitmap);
+                          if (inst)
+                            {
+                              /* Perform parse handler */
+
+                              ret = handler(dev, payload, get_payload_len(
+                                (FAR struct altcom_cmdhdr_s *)g_recvbuff),
+                                altver, inst->outparam, inst->outparamlen,
+                                &bitmap);
+
+                              unlock_evtbufinst(inst, dev);
+
+                              if (ret >= 0)
+                                {
+                                  write_evtbitmap(dev, bitmap);
+                                }
+                              else
+                                {
+                                  /* Discard the event packet */
+
+                                  is_discard = true;
+                                }
+                            }
+                          else
+                            {
+                              /* Discard the event packet */
+
+                              is_discard = true;
+                            }
+                        }
+                    }
+                  else if (container)
+                    {
+                      container->result = -ENOSYS;
+                      m_warn("handler is not found\n");
+                    }
+                  else
+                    {
+                      /* Discard the event packet */
+
+                      is_discard = true;
+
+                      m_warn("container and handler is not found\n");
+                    }
+                }
+
+              if (container)
+                {
+                  if (container->cmdid & LTE_CMDOPT_ASYNC_BIT)
+                    {
+                      bitmap |= ALT1250_EVTBIT_REPLY;
+                    }
+                  else
+                    {
+                      bitmap = ALT1250_EVTBIT_REPLY;
+                    }
+
+                  write_evtbitmapwithlist(dev, bitmap, container);
+                }
+
+              if (is_discard)
+                {
+                  dev->discardcnt++;
+                  m_err("discard event %lu\n", dev->discardcnt);
+                }
+              else
+                {
+                  pollnotify(dev);
+                }
+            }
+        }
+      else
+        {
+          switch (ret)
+            {
+              case ALTMDM_RETURN_RESET_PKT:
+                {
+                  m_info("recieve ALTMDM_RETURN_RESET_PKT\n");
+                  set_senddisable(dev, true);
+                }
+                break;
+
+              case ALTMDM_RETURN_RESET_V1:
+              case ALTMDM_RETURN_RESET_V4:
+                {
+                  uint32_t reason = altmdm_get_reset_reason();
+
+                  m_info("recieve ALTMDM_RETURN_RESET_V1/V4\n");
+
+                  ret = write_evtbuff_byidx(dev, 0, write_restart_param,
+                    (FAR void *)&reason);
+
+                  /* If there is a waiting list,
+                   * replace it with the replay list.
+                   */
+
+                  head = remove_list_all(&dev->waitlist);
+
+                  write_evtbitmapwithlist(dev, ALT1250_EVTBIT_RESET, head);
+                  pollnotify(dev);
+                }
+                break;
+
+              case ALTMDM_RETURN_EXIT:
+                {
+                  m_info("recieve ALTMDM_RETURN_EXIT\n");
+                  is_running = false;
+                }
+                break;
+
+              default:
+                DEBUGASSERT(0);
+                break;
+            }
+        }
+
+      recvedlen = 0;
+    }
+
+  m_info("recv thread end\n");
+
+  pthread_exit(0);
+}
+
+/****************************************************************************
+ * Name: alt1250_open
+ ****************************************************************************/
+
+static int alt1250_open(FAR struct file *filep)
+{
+  FAR struct inode *inode;
+  FAR struct alt1250_dev_s *dev;
+  int ret = OK;
+
+  /* Get our private data structure */
+
+  DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
+  inode = filep->f_inode;
+
+  dev = (FAR struct alt1250_dev_s *)inode->i_private;
+  DEBUGASSERT(dev);
+
+  nxsem_wait_uninterruptible(&dev->refslock);
+
+  if (dev->crefs > 0)
+    {
+      ret = -EPERM;
+    }
+
+  /* Increment the count of open references on the driver */
+
+  dev->crefs++;
+
+  nxsem_post(&dev->refslock);
+
+  if (ret == OK)
+    {
+      nxsem_init(&dev->waitlist.lock, 0, 1);
+      nxsem_init(&dev->replylist.lock, 0, 1);
+      nxsem_init(&dev->evtmaplock, 0, 1);
+      nxsem_init(&dev->pfdlock, 0, 1);
+      nxsem_init(&dev->senddisablelock, 0, 1);
+      nxsem_init(&dev->select_inst.stat_lock, 0, 1);
+
+      sq_init(&dev->waitlist.queue);
+      sq_init(&dev->replylist.queue);
+
+      dev->senddisable = true;
+
+      ret = pthread_create(&dev->recvthread, NULL,
+        (pthread_startroutine_t)altcom_recvthread,
+        (pthread_addr_t)dev);
+      if (ret < 0)
+        {
+          m_err("thread create failed: %d\n", errno);
+          ret = -errno;
+
+          nxsem_destroy(&dev->waitlist.lock);
+          nxsem_destroy(&dev->replylist.lock);
+          nxsem_destroy(&dev->evtmaplock);
+          nxsem_destroy(&dev->pfdlock);
+          nxsem_destroy(&dev->senddisablelock);
+          nxsem_destroy(&dev->select_inst.stat_lock);
+
+          nxsem_wait_uninterruptible(&dev->refslock);
+          dev->crefs--;
+          nxsem_post(&dev->refslock);
+        }
+      else
+        {
+          pthread_setname_np(dev->recvthread, "altcom_recvthread");
+        }
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: alt1250_close
+ ****************************************************************************/
+
+static int alt1250_close(FAR struct file *filep)
+{
+  FAR struct inode *inode;
+  FAR struct alt1250_dev_s *dev;
+  int ret = OK;
+
+  /* Get our private data structure */
+
+  DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
+  inode = filep->f_inode;
+
+  dev = (FAR struct alt1250_dev_s *)inode->i_private;
+  DEBUGASSERT(dev);
+
+  nxsem_wait_uninterruptible(&dev->refslock);
+
+  if (dev->crefs == 0)
+    {
+      ret = -EPERM;
+    }
+  else
+    {
+      /* Decrement the count of open references on the driver */
+
+      dev->crefs--;
+    }
+
+  nxsem_post(&dev->refslock);
+
+  if (ret == OK)
+    {
+      nxsem_destroy(&dev->waitlist.lock);
+      nxsem_destroy(&dev->replylist.lock);
+      nxsem_destroy(&dev->evtmaplock);
+      nxsem_destroy(&dev->pfdlock);
+      nxsem_destroy(&dev->senddisablelock);
+      nxsem_destroy(&dev->select_inst.stat_lock);
+
+      altmdm_fin();
+      pthread_join(dev->recvthread, NULL);
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: alt1250_read
+ ****************************************************************************/
+
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len)
+{
+  FAR struct inode *inode;
+  FAR struct alt1250_dev_s *dev;
+
+  /* Get our private data structure */
+
+  DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
+  inode = filep->f_inode;
+
+  dev = (FAR struct alt1250_dev_s *)inode->i_private;
+  DEBUGASSERT(dev);
+
+  if (len != sizeof(struct alt_readdata_s))
+    {
+      return -EINVAL;
+    }
+
+  return read_data(dev, (FAR struct alt_readdata_s *)buffer);
+}
+
+/****************************************************************************
+ * Name: alt1250_ioctl
+ ****************************************************************************/
+
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+  FAR struct inode *inode;
+  FAR struct alt1250_dev_s *dev;
+  int ret = OK;
+
+  /* Get our private data structure */
+
+  DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
+  inode = filep->f_inode;
+
+  dev = (FAR struct alt1250_dev_s *)inode->i_private;
+  DEBUGASSERT(dev);
+
+  switch (cmd)
+    {
+      case ALT1250_IOC_POWER:
+        {
+          FAR struct alt_power_s *req = (FAR struct alt_power_s *)arg;
+
+          /* Performs power control or power consumption control
+           * of the modem.
+           */
+
+          ret = alt1250_power_control(dev, req);
+        }
+        break;
+
+      case ALT1250_IOC_SEND:
+        {
+          FAR alt_container_t *req = (FAR alt_container_t *)arg;
+
+          ret = make_altcomcmd_and_send(dev, req);
+        }
+        break;
+
+      case ALT1250_IOC_SETEVTBUFF:
+        {
+          FAR struct alt_evtbuffer_s *buff =
+            (FAR struct alt_evtbuffer_s *)arg;
+          add_evtbuff(dev, buff);
+        }
+        break;
+
+      case ALT1250_IOC_EXCHGCONTAINER:
+        {
+          FAR alt_container_t **container = (FAR alt_container_t **)arg;
+
+          ret = exchange_selectcontainer(dev, container);
+        }
+        break;
+
+      default:
+        ret = -EINVAL;
+        break;
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: alt1250_poll
+ ****************************************************************************/
+
+static int alt1250_poll(FAR struct file *filep, FAR struct pollfd *fds,
+  bool setup)
+{
+  FAR struct inode *inode;
+  FAR struct alt1250_dev_s *dev;
+
+  /* Get our private data structure */
+
+  DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
+  inode = filep->f_inode;
+
+  dev = (FAR struct alt1250_dev_s *)inode->i_private;
+  DEBUGASSERT(dev);
+
+  if (setup)
+    {
+       poll_notify(&fds, 1, POLLIN);
+    }
+
+  return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+FAR void *alt1250_register(FAR const char *devpath,
+  FAR struct spi_dev_s *dev, FAR const struct alt1250_lower_s *lower)
+{
+  FAR struct alt1250_dev_s *priv;
+  int ret;
+
+  priv = (FAR struct alt1250_dev_s *)
+    kmm_malloc(sizeof(struct alt1250_dev_s));
+  if (!priv)
+    {
+      m_err("Failed to allocate instance.\n");
+      return NULL;
+    }
+
+  memset(priv, 0, sizeof(struct alt1250_dev_s));
+
+  priv->spi = dev;
+  priv->lower = lower;
+
+  nxsem_init(&priv->refslock, 0, 1);
+
+  ret = register_driver(devpath, &g_alt1250fops, 0666, priv);
+  if (ret < 0)
+    {
+      m_err("Failed to register driver: %d\n", ret);
+      kmm_free(priv);
+      return NULL;
+    }
+
+  return (FAR void *)priv;

Review Comment:
   I do not think that we need cast here



##########
drivers/modem/alt1250/altcom_cmd_sms.h:
##########
@@ -0,0 +1,212 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_cmd_sms.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_CMD_SMS_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_CMD_SMS_H__
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+#include <nuttx/modem/alt1250.h>
+#include <nuttx/net/sms.h>
+
+#include <stdbool.h>
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ALTCOM_SMS_MSG_VALID_UD         (0x01 << 0)
+#define ALTCOM_SMS_MSG_VALID_SRR        (0x01 << 1)
+#define ALTCOM_SMS_MSG_VALID_CONCAT_HDR (0x01 << 3)
+#define ALTCOM_SMS_MSG_VALID_TOA        (0x01 << 4)
+
+#define ALTCOM_SMS_DELIVERY_STAT_CAT_MASK (0x60)
+#define ALTCOM_SMS_DELIVERY_STAT_CAT_OK   (0x00)
+#define ALTCOM_SMS_DELIVERY_STAT_CAT_PEND (0x01 << 6)
+#define ALTCOM_SMS_DELIVERY_STAT_CAT_FAIL (0x01 << 7)
+
+#define ALTCOM_SMS_MSG_TYPE_SEND (0x01 << 0)
+#define ALTCOM_SMS_MSG_TYPE_RECV (0x01 << 1)
+#define ALTCOM_SMS_MSG_TYPE_DELIVER_REPORT (0x01 << 2)
+
+#define ALTCOM_SMS_CHSET_GSM7   0
+#define ALTCOM_SMS_CHSET_BINARY 1
+#define ALTCOM_SMS_CHSET_UCS2   2
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+begin_packed_struct struct apicmd_sms_time_s
+{
+  uint8_t year; /* Years (0-99) */
+  uint8_t mon;  /* Month (1-12) */
+  uint8_t mday; /* Day of the month (1-31) */
+  uint8_t hour; /* Hours (0-23) */
+  uint8_t min;  /* Minutes (0-59) */
+  uint8_t sec;  /* Seconds (0-59) */
+  int8_t  tz;   /* Time zone in hour (-24 - +24) */
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_sms_addr_s
+{
+  /* Type of address is reserved. */
+
+  uint8_t toa;
+  uint8_t length;
+  uint16_t address[SMS_MAX_ADDRLEN];
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_sms_concat_hdr_s
+{
+  /* Contain a modulo 256 counter indicating the reference number
+   * for a particular concatenated short message.
+   */
+
+  uint8_t ref_num;
+
+  /* Contain a value in the range 0 to 255 indicating the total number of
+   * short messages within the concatenated short message.
+   */
+
+  uint8_t max_num;
+
+  /* Contain a value in the range 0 to 255 indicating the sequence number
+   * of a particular short message within the concatenated short message.
+   */
+
+  uint8_t seq_num;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_sms_userdata_s
+{
+  /* Set the character set used for SMS */
+
+  uint8_t chset;
+
+  /* Buffer length of User-Data field. */
+
+  uint16_t data_len;
+
+  /* User data in utf-8 format. */
+
+  uint8_t *data;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_sms_msg_s
+{
+  uint8_t  type;
+
+  union
+    {
+      /* SMS-DELIVER */
+
+      struct
+        {
+          uint8_t valid_indicator;
+          struct apicmd_sms_addr_s src_addr;
+          struct apicmd_sms_time_s sc_time;
+          struct apicmd_sms_concat_hdr_s concat_hdr;
+          struct apicmd_sms_userdata_s userdata;
+
+          /* Variable length array */
+
+          uint16_t user_data[0];
+        } recv;
+
+      /* SMS-STATUS-REPORT */
+
+      struct
+        {
+          uint8_t status;
+          struct apicmd_sms_time_s sc_time;
+          uint8_t ref_id;
+          struct apicmd_sms_time_s discharge_time;
+        } delivery_report;
+    } u;
+} end_packed_struct;
+
+/* Command format for these response
+ * APICMDID_SMS_INIT, APICMDID_SMS_FIN, APICMDID_SMS_REPORT_RECV,
+ * APICMDID_SMS_DELETE
+ */
+
+begin_packed_struct struct apicmd_sms_res_s
+{
+  int32_t result;
+} end_packed_struct;
+
+/* Command format for APICMDID_SMS_INIT request */
+
+begin_packed_struct struct apicmd_sms_init_req_s
+{
+  uint8_t types;
+  uint8_t storage_use;
+} end_packed_struct;
+
+/* Command format for APICMDID_SMS_SEND request */
+
+begin_packed_struct struct apicmd_sms_send_req_s
+{
+  struct apicmd_sms_addr_s sc_addr;
+
+  /* SMS-SUBMIT */
+
+  uint8_t valid_indicator;
+  struct apicmd_sms_addr_s dest_addr;
+  struct apicmd_sms_userdata_s userdata;
+
+  /* Variable length array */
+
+  uint16_t user_data[0];
+} end_packed_struct;
+
+/* Command format for APICMDID_SMS_SEND response */
+
+begin_packed_struct struct apicmd_sms_sendres_s
+{
+  int32_t result;
+  uint8_t mr_num;
+  uint8_t mr_list[SMS_CONCATENATE_MAX];
+} end_packed_struct;
+
+/* Command format for APICMDID_SMS_REPORT_RECV request */
+
+begin_packed_struct struct apicmd_sms_reprecv_s
+{
+  uint16_t index;
+  struct apicmd_sms_addr_s sc_addr;
+  struct apicmd_sms_msg_s msg;
+} end_packed_struct;
+
+/* Command format for APICMDID_SMS_DELETE request */
+
+begin_packed_struct struct apicmd_sms_delete_s
+{
+  uint16_t index;
+  uint8_t types;
+} end_packed_struct;
+
+#endif  /* __DRIVERS_MODEM_ALT1250_ALTCOM_CMD_SMS_H__ */

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



##########
drivers/modem/alt1250/altcom_cmd.h:
##########
@@ -0,0 +1,965 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_cmd.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_CMD_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_CMD_H__
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+
+#include <stdbool.h>
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define APICMD_ACTIVATEPDN_APNNAME_MAXLEN         (101)
+#define APICMD_ACTIVATEPDN_USERNAME_MAXLEN        (64)
+#define APICMD_ACTIVATEPDN_PASSWORD_MAXLEN        (32)
+
+#define APICMD_CELLINFO_CELLID_MIN    (0)
+#define APICMD_CELLINFO_CELLID_MAX    (503)
+#define APICMD_CELLINFO_EARFCN_MIN    (0)
+#define APICMD_CELLINFO_EARFCN_MAX    (262143)
+#define APICMD_CELLINFO_DIGIT_NUM_MIN (0)
+#define APICMD_CELLINFO_DIGIT_NUM_MAX (9)
+#define APICMD_CELLINFO_MCC_DIGIT             (3)
+#define APICMD_CELLINFO_MNC_DIGIT_MIN         (2)
+#define APICMD_CELLINFO_MNC_DIGIT_MAX         (3)
+#define APICMD_CELLINFO_GCID_MAX              (16)
+#define APICMD_CELLINFO_TIMEDIFF_INDEX_MAX    (4095)
+#define APICMD_CELLINFO_TA_MAX                (1282)
+#define APICMD_CELLINFO_SFN_MAX               (0x03FF)
+#define APICMD_CELLINFO_NEIGHBOR_CELL_NUM_MAX (32)
+#define APICMD_CELLINFO_VALID_TIMEDIFFIDX     (1 << 1)
+#define APICMD_CELLINFO_VALID_TA              (1 << 2)
+#define APICMD_CELLINFO_VALID_SFN             (1 << 3)
+#define APICMD_CELLINFO_VALID_RSRP            (1 << 4)
+#define APICMD_CELLINFO_VALID_RSRQ            (1 << 5)
+
+#define APICMD_DATAALLOW_DATAALLOW_ALLOW        (0)
+#define APICMD_DATAALLOW_DATAALLOW_DISALLOW     (1)
+
+#define APICMD_DATAALLOW_DATAROAMALLOW_ALLOW    (0)
+#define APICMD_DATAALLOW_DATAROAMALLOW_DISALLOW (1)
+
+#define APICMD_DEACTIVATEPDN_SESSIONID_MIN          (0)
+#define APICMD_DEACTIVATEPDN_SESSIONID_MAX          (255)
+
+#define APICMD_EDRX_ACTTYPE_NOTUSE   (0) /* eDRX is not running */
+#define APICMD_EDRX_ACTTYPE_ECGSMIOT (1) /* EC-GSM-IoT (A/Gb mode) */
+#define APICMD_EDRX_ACTTYPE_GSM      (2) /* GSM (A/Gb mode) */
+#define APICMD_EDRX_ACTTYPE_IU       (3) /* UTRAN (Iu mode) */
+#define APICMD_EDRX_ACTTYPE_WBS1     (4) /* E-UTRAN (WB-S1 mode) */
+#define APICMD_EDRX_ACTTYPE_NBS1     (5) /* E-UTRAN (NB-S1 mode) */
+
+#define APICMD_ENTERPIN_NEWPINCODE_UNUSE         (0)
+#define APICMD_ENTERPIN_NEWPINCODE_USE           (1)
+#define APICMD_ENTERPIN_PINCODE_LEN              9
+
+#define APICMD_ERRINFO_ERRSTR_MAX_LEN                (64)
+
+#define APICMD_IMSCAP_ENABLE         (0)
+#define APICMD_IMSCAP_DISABLE        (1)
+
+#define APICMD_GETSIMINFO_MCC_DIXIT_MAX          (3)
+#define APICMD_GETSIMINFO_MNC_DIXIT_MAX          (3)
+#define APICMD_GETSIMINFO_SPN_MAX_LEN            (16)
+#define APICMD_GETSIMINFO_ICCID_MAX_LEN          (10)
+#define APICMD_GETSIMINFO_IMSI_LEN               (15)
+#define APICMD_GETSIMINFO_GID_LEN                (128)
+
+#define APICMD_IMEI_LEN     16
+#define APICMD_IMSI_LEN                   16
+
+#define APICMD_NETINFO_PDNCOUNT_MAX           (5)
+
+#define APICMD_OPERATOR_LEN     17
+#define APICMD_OPERATOR_LEN_V4  33
+
+#define APICMD_PDN_IMS_REG                (0)
+#define APICMD_PDN_IMS_UNREG              (1)
+
+#define APICMD_PDN_DATAALLOW_ALLOW        (0)
+#define APICMD_PDN_DATAALLOW_DISALLOW     (1)
+
+#define APICMD_PDN_DATAROAMALLOW_ALLOW    (0)
+#define APICMD_PDN_DATAROAMALLOW_DISALLOW (1)
+
+#define APICMD_PDN_IPCOUNT_MAX            (2)
+#define APICMD_PDN_IPADDR_MAXLEN          (40)
+
+#define APICMD_PDN_DNSCOUNT_MAX           (4)
+
+#define APICMD_PHONENO_LEN                   41
+
+#define APICMD_PSM_TIMER_MIN        (1)
+#define APICMD_PSM_TIMER_MAX        (31)
+
+#define APICMD_QUALITY_DISABLE  (0)
+#define APICMD_QUALITY_ENABLE   (1)
+#define APICMD_QUALITY_RSRP_MIN (-140)
+#define APICMD_QUALITY_RSRP_MAX (0)
+#define APICMD_QUALITY_RSRQ_MIN (-60)
+#define APICMD_QUALITY_RSRQ_MAX (0)
+#define APICMD_QUALITY_SINR_MIN (-128)
+#define APICMD_QUALITY_SINR_MAX (40)
+
+#define APICMD_RAT_RES_OK            (0)
+#define APICMD_RAT_RES_ERR           (1)
+#define APICMD_RAT_RAT_DEFAULT       (1)
+#define APICMD_RAT_RAT_CATM          (2)
+#define APICMD_RAT_RAT_NBIOT         (3)
+#define APICMD_RAT_RAT_GSM           (4)
+#define APICMD_RAT_RAT_C2D           (5)
+#define APICMD_RAT_RAT_N2D           (6)
+#define APICMD_RAT_RAT_G2D           (7)
+#define APICMD_RAT_NOT_PERSIS        (0)
+#define APICMD_RAT_PERSIS            (1)
+#define APICMD_RAT_RAT_MODE_SINGLE   (0)
+#define APICMD_RAT_RAT_MODE_MULTIPLE (1)
+#define APICMD_RAT_SOURCE_NONE       (0)
+#define APICMD_RAT_SOURCE_HOST       (1)
+#define APICMD_RAT_SOURCE_LWM2M      (2)
+
+#define APICMD_SET_REPCELLINFO_INTERVAL_MIN  (1)
+#define APICMD_SET_REPCELLINFO_INTERVAL_MAX  (4233600)
+
+#define APICMD_SET_REP_EVT_DISABLE                          (0)
+#define APICMD_SET_REP_EVT_ENABLE                           (1)
+
+#define APICMD_SET_REP_EVT_LTIME                            (1 << 0)
+#define APICMD_SET_REP_EVT_SIMD                             (1 << 1)
+#define APICMD_SET_REP_EVT_SIMSTATE                         (1 << 2)
+#define APICMD_SET_REP_EVT_REGSTATE                         (1 << 3)
+#define APICMD_SET_REP_EVT_PSMSTATE                         (1 << 4)
+#define APICMD_SET_REP_EVT_DYNPSM                           (1 << 5)
+#define APICMD_SET_REP_EVT_DYNEDRX                          (1 << 6)
+#define APICMD_SET_REP_EVT_CONNPHASE                        (1 << 7)
+#define APICMD_SET_REP_EVT_ANTITAMPER                       (1 << 8)
+#define APICMD_SET_REP_EVT_MAX                              (1 << 15)
+
+#define APICMD_SET_REP_EVT_RES_OK                           (0)
+#define APICMD_SET_REP_EVT_RES_ERR                          (1)
+
+#define APICMD_REPORT_EVT_TYPE_LTIME                        (0)
+#define APICMD_REPORT_EVT_TYPE_SIMD                         (1)
+#define APICMD_REPORT_EVT_TYPE_SIMSTATE                     (2)
+#define APICMD_REPORT_EVT_TYPE_REGSTATE                     (3)
+#define APICMD_REPORT_EVT_TYPE_PSMSTATE                     (4)
+#define APICMD_REPORT_EVT_TYPE_DYNPSM                       (5)
+#define APICMD_REPORT_EVT_TYPE_DYNEDRX                      (6)
+#define APICMD_REPORT_EVT_TYPE_CONNPHASE                    (7)
+#define APICMD_REPORT_EVT_TYPE_ANTITAMPER                   (8)
+
+#define APICMD_REPORT_EVT_SIMD_REMOVAL                      (0)
+#define APICMD_REPORT_EVT_SIMD_INSERTION                    (1)
+
+#define APICMD_REPORT_EVT_SIMSTATE_DEACTIVATED              (0)
+#define APICMD_REPORT_EVT_SIMSTATE_SIM_INIT_WAIT_PIN_UNLOCK (1)
+#define APICMD_REPORT_EVT_SIMSTATE_PERSONALIZATION_FAILED   (2)
+#define APICMD_REPORT_EVT_SIMSTATE_ACTIVATION_COMPLETED     (3)
+
+#define APICMD_REPORT_EVT_ALERTU_TEMP                       (0)
+#define APICMD_REPORT_EVT_ALERTU_ANTIAMPER                  (1)
+
+#define APICMD_REP_PSMST_NOT_ACTIVE                         (0)
+#define APICMD_REP_PSMST_ACTIVE                             (1)
+#define APICMD_REP_PSMST_ACTIVE_AND_CAMPED                  (2)
+#define APICMD_REP_PSMST_CAMP_INTERRUPTED                   (3)
+
+#define APICMD_REP_CONNPHASE_START_SCAN                     (0)
+#define APICMD_REP_CONNPHASE_FAIL_SCAN                      (1)
+#define APICMD_REP_CONNPHASE_ENTER_CAMPED                   (2)
+#define APICMD_REP_CONNPHASE_CONNECTION_ESTABLISHMENT       (3)
+#define APICMD_REP_CONNPHASE_START_RESCAN                   (4)
+#define APICMD_REP_CONNPHASE_ENTER_CONNECTED                (5)
+#define APICMD_REP_CONNPHASE_NO_SUITABLE_CELL               (6)
+#define APICMD_REP_CONNPHASE_REG_ATTEMPT_FAILED             (7)
+#define APICMD_REP_CONNPHASE_NOT_AVAIL                      (99)
+
+#define APICMD_REP_CONPHASE_RAT_CATM                        (0)
+#define APICMD_REP_CONPHASE_RAT_NBIOT                       (1)
+#define APICMD_REP_CONPHASE_RAT_GSM                         (3)
+#define APICMD_REP_CONPHASE_RAT_NOT_AVAIL                   (99)
+
+#define APICMD_REP_CONPHASE_SCAN_MRU_ONLY                   (0)
+#define APICMD_REP_CONPHASE_SCAN_MRU_AND_FULL_SCAN          (1)
+#define APICMD_REP_CONPHASE_SCAN_MRU_AND_COUNTRY_SCAN       (2)
+#define APICMD_REP_CONPHASE_SCAN_MRU_AND_LS                 (3)
+#define APICMD_REP_CONPHASE_SCAN_MRU_NOT_AVAIL              (99)
+
+#define APICMD_REP_CONPHASE_SCAN_REASON_INIT_SCAN           (0)
+#define APICMD_REP_CONPHASE_SCAN_REASON_OUT_OF_COVERAGE     (1)
+#define APICMD_REP_CONPHASE_SCAN_REASON_HIGH_PRIORITY       (2)
+#define APICMD_REP_CONPHASE_SCAN_REASON_LIMITED_SERVICE     (3)
+#define APICMD_REP_CONPHASE_SCAN_REASON_COPS                (4)
+#define APICMD_REP_CONPHASE_SCAN_REASON_OTHER               (5)
+#define APICMD_REP_CONPHASE_SCAN_REASON_NOT_AVAIL           (99)
+
+#define APICMD_REPNETINFO_RES_OK                 (0)
+#define APICMD_REPNETINFO_RES_ERR                (1)
+
+#define APICMD_REPNETINFO_REPORT_ENABLE          (0)
+#define APICMD_REPNETINFO_REPORT_DISABLE         (1)
+
+#define APICMD_REPNETINFO_NWSTAT_ATCH            (0)
+#define APICMD_REPNETINFO_NWSTAT_DTCH            (1)
+
+#define APICMD_SET_REPQUALITY_DISABLE      (0)
+#define APICMD_SET_REPQUALITY_ENABLE       (1)
+#define APICMD_SET_REPQUALITY_INTERVAL_MIN (1)
+#define APICMD_SET_REPQUALITY_INTERVAL_MAX (4233600)
+
+#define APICMD_SETPINCODE_PINCODE_LEN  9
+
+#define APICMD_SETPINCODE_CHGTYPE_PIN  (1)
+#define APICMD_SETPINCODE_CHGTYPE_PIN2 (2)
+
+#define APICMD_SETPINLOCK_PINCODE_LEN    9
+
+#define APICMD_VERSION_RES_BB_PRODUCT_LEN   5
+#define APICMD_VERSION_RES_NP_PACKAGE_LEN   32
+
+#define APICMD_FW_INJECTDATA_MAXLEN    (4096)
+#define APICMD_FW_INJECTDATA_MAXLEN_V4 (3000)
+
+#define APICMD_IPV4_LEN (4)
+#define APICMD_IPV6_LEN (16)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* structure for common */
+
+begin_packed_struct struct apicmd_ipaddr_s
+{
+  uint8_t iptype;
+  uint8_t address[APICMD_PDN_IPADDR_MAXLEN];
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_pdnset_s
+{
+  uint8_t session_id;
+  uint8_t activate;
+  uint32_t apntype;
+  uint8_t ipaddr_num;
+  struct apicmd_ipaddr_s
+    ip_address[APICMD_PDN_IPCOUNT_MAX];
+  uint8_t imsregister;
+  uint8_t dataallow;
+  uint8_t dararoamingallow;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_pdnset_v4_s
+{
+  uint8_t session_id;
+  uint8_t activate;
+  uint32_t apntype;
+  uint8_t ipaddr_num;
+  struct apicmd_ipaddr_s
+    ip_address[APICMD_PDN_IPCOUNT_MAX];
+  uint8_t imsregister;
+  uint8_t dataallow;
+  uint8_t dararoamingallow;
+  uint8_t dnsaddr_num;
+  struct apicmd_ipaddr_s
+    dns_address[APICMD_PDN_DNSCOUNT_MAX];
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_neighbor_cell_s
+{
+  uint8_t  valid;
+  uint32_t cell_id;
+  uint32_t earfcn;
+  uint16_t sfn;
+  int16_t  rsrp;
+  int16_t  rsrq;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_edrxset_s
+{
+  uint8_t acttype;
+  uint8_t enable;
+  uint8_t edrx_cycle;
+  uint8_t ptw_val;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_ltime_s
+{
+  uint8_t year;
+  uint8_t month;
+  uint8_t day;
+  uint8_t hour;
+  uint8_t minutes;
+  uint8_t seconds;
+  int32_t timezone;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_netinfo_rejectcause_s
+{
+  uint8_t category;
+  uint8_t value;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_netinfo_nwerrinfo_s
+{
+  uint8_t err_type;
+  struct apicmd_netinfo_rejectcause_s reject_cause;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_netinfo_s
+{
+  uint8_t nw_stat;
+  uint8_t pdn_count;
+  struct apicmd_netinfo_nwerrinfo_s err_info;
+  struct apicmd_pdnset_s pdn[APICMD_NETINFO_PDNCOUNT_MAX];
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_netinfo_v4_s
+{
+  uint8_t nw_stat;
+  uint8_t pdn_count;
+  struct apicmd_netinfo_nwerrinfo_s err_info;
+  struct apicmd_pdnset_v4_s pdn[APICMD_NETINFO_PDNCOUNT_MAX];
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_psm_timeval_s
+{
+  uint8_t unit;
+  uint8_t time_val;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_psm_set_s
+{
+  uint8_t enable;
+  struct apicmd_cmddat_psm_timeval_s rat_time;
+  struct apicmd_cmddat_psm_timeval_s tau_time;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_quality_s
+{
+  uint8_t enability;
+  int16_t rsrp;
+  int16_t rsrq;
+  int16_t sinr;
+  int16_t rssi;
+} end_packed_struct;
+
+/* structure for APICMDID_ACTIVATE_PDN */
+
+begin_packed_struct struct apicmd_cmddat_activatepdn_s
+{
+  uint32_t apntype;
+  uint8_t iptype;
+  uint8_t apnname[APICMD_ACTIVATEPDN_APNNAME_MAXLEN];
+  uint8_t authtype;
+  uint8_t username[APICMD_ACTIVATEPDN_USERNAME_MAXLEN];
+  uint8_t password[APICMD_ACTIVATEPDN_PASSWORD_MAXLEN];
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_activatepdnres_s
+{
+  uint8_t result;
+  struct apicmd_pdnset_s pdnset;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_activatepdnres_v4_s
+{
+  uint8_t result;
+  struct apicmd_pdnset_v4_s pdnset;
+} end_packed_struct;
+
+/* structure for APICMDID_ACTIVATE_PDN_CANCEL */
+
+begin_packed_struct struct apicmd_cmddat_activatepdn_cancel_res_s
+{
+  uint8_t result;
+} end_packed_struct;
+
+/* structure for APICMDID_GET_CELLINFO */
+
+begin_packed_struct struct apicmd_cmddat_cellinfo_s
+{
+  uint8_t  valid;
+  uint32_t cell_id;
+  uint32_t earfcn;
+  uint8_t  mcc[APICMD_CELLINFO_MCC_DIGIT];
+  uint8_t  mnc_digit;
+  uint8_t  mnc[APICMD_CELLINFO_MNC_DIGIT_MAX];
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_cellinfo_v4_s
+{
+  uint8_t enability;
+  uint32_t cell_id;
+  uint32_t earfcn;
+  uint8_t mcc[APICMD_CELLINFO_MCC_DIGIT];
+  uint8_t mnc_digit;
+  uint8_t mnc[APICMD_CELLINFO_MNC_DIGIT_MAX];
+  uint8_t cgid[APICMD_CELLINFO_GCID_MAX + 1];
+  uint16_t tac;
+  uint16_t time_diffidx;
+  uint16_t ta;
+  uint16_t sfn;
+  int16_t rsrp;
+  int16_t rsrq;
+  uint8_t neighbor_num;
+  struct apicmd_cmddat_neighbor_cell_s
+           neighbor_cell[APICMD_CELLINFO_NEIGHBOR_CELL_NUM_MAX];
+} end_packed_struct;
+
+/* structure for APICMDID_DATA_ALLOW */
+
+begin_packed_struct struct apicmd_cmddat_dataallow_s
+{
+  uint8_t session_id;
+  uint8_t data_allow;
+  uint8_t dataroam_allow;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_dataallowres_s
+{
+  uint8_t result;
+} end_packed_struct;
+
+/* structure for APICMDID_DEACTIVATE_PDN */
+
+begin_packed_struct struct apicmd_cmddat_deactivatepdn_s
+{
+  uint8_t session_id;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_deactivatepdnres_s
+{
+  uint8_t result;
+  uint8_t errcause;
+} end_packed_struct;
+
+/* structure for APICMDID_ENTER_PIN */
+
+begin_packed_struct struct apicmd_cmddat_enterpin_s
+{
+  uint8_t pincode[APICMD_ENTERPIN_PINCODE_LEN];
+  uint8_t newpincodeuse;
+  uint8_t newpincode[APICMD_ENTERPIN_PINCODE_LEN];
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_enterpinres_s
+{
+  uint8_t result;
+  uint8_t simstat;
+  uint8_t attemptsleft;
+} end_packed_struct;
+
+/* structure for APICMDID_ERRINFO */
+
+begin_packed_struct struct apicmd_cmddat_errinfo_s
+{
+  uint8_t indicator;
+  int32_t err_code;
+  int32_t err_no;
+  uint8_t err_str[APICMD_ERRINFO_ERRSTR_MAX_LEN];
+} end_packed_struct;
+
+/* structure for APICMDID_GET_CE */
+
+begin_packed_struct struct apicmd_cmddat_getceres_s
+{
+  uint8_t result;
+  uint8_t mode_a_enable;
+  uint8_t mode_b_enable;
+} end_packed_struct;
+
+/* structure for APICMDID_GET_CELLINFO */
+
+begin_packed_struct struct apicmd_cmddat_getcellinfores_v4_s
+{
+  struct apicmd_cmddat_cellinfo_v4_s cellinfo;
+} end_packed_struct;
+
+/* structure for APICMDID_GET_DYNAMICEDRX */
+
+begin_packed_struct struct apicmd_cmddat_getdynamicedrxres_s
+{
+  uint8_t result;
+  struct apicmd_edrxset_s set;
+} end_packed_struct;
+
+/* structure for APICMDID_GET_DYNAMICPSM */
+
+begin_packed_struct struct apicmd_cmddat_getdynamicpsmres_s
+{
+  uint8_t result;
+  struct apicmd_cmddat_psm_set_s set;
+} end_packed_struct;
+
+/* structure for APICMDID_GET_EDRX */
+
+begin_packed_struct struct apicmd_cmddat_getedrx_v4_s
+{
+  uint8_t type;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_getedrxres_s
+{
+  uint8_t result;
+  struct apicmd_edrxset_s set;
+} end_packed_struct;
+
+/* structure for APICMDID_GET_IMS_CAP */
+
+begin_packed_struct struct apicmd_cmddat_getimscapres_s
+{
+  uint8_t result;
+  uint8_t ims_cap;
+} end_packed_struct;
+
+/* structure for APICMDID_GET_NETINFO */
+
+begin_packed_struct struct apicmd_cmddat_getnetinfores_s
+{
+  uint8_t result;
+  struct apicmd_netinfo_s netinfo;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_getnetinfores_v4_s
+{
+  uint8_t result;
+  struct apicmd_netinfo_v4_s netinfo;
+} end_packed_struct;
+
+/* structure for APICMDID_GET_PINSET */
+
+begin_packed_struct struct apicmd_cmddat_getpinsetres_s
+{
+  uint8_t result;
+  uint8_t active;
+  uint8_t status;
+  uint8_t pin_attemptsleft;
+  uint8_t puk_attemptsleft;
+  uint8_t pin2_attemptsleft;
+  uint8_t puk2_attemptsleft;
+} end_packed_struct;
+
+/* structure for APICMDID_GET_PSM */
+
+begin_packed_struct struct apicmd_cmddat_getpsm_v4_s
+{
+  uint8_t type;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_getpsmres_s
+{
+  uint8_t result;
+  struct apicmd_cmddat_psm_set_s set;
+} end_packed_struct;
+
+/* structure for APICMDID_GET_QUALITY */
+
+begin_packed_struct struct apicmd_cmddat_getqualityres_s
+{
+  uint8_t result;
+  struct apicmd_cmddat_quality_s quality;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_getqualityres_v4_s
+{
+  struct apicmd_cmddat_quality_s quality;
+} end_packed_struct;
+
+/* structure for APICMDID_GET_SIMINFO */
+
+begin_packed_struct struct apicmd_cmddat_getsiminfo_s
+{
+  uint32_t option;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_getsiminfo_res_s
+{
+  uint8_t  result;
+  uint32_t option;
+  uint8_t  mcc[APICMD_GETSIMINFO_MCC_DIXIT_MAX];
+  uint8_t  mnc_digit;
+  uint8_t  mnc[APICMD_GETSIMINFO_MNC_DIXIT_MAX];
+  uint8_t  spn_len;
+  uint8_t  spn[APICMD_GETSIMINFO_SPN_MAX_LEN];
+  uint8_t  iccid_len;
+  uint8_t  iccid[APICMD_GETSIMINFO_ICCID_MAX_LEN];
+  uint8_t  imsi_len;
+  uint8_t  imsi[APICMD_GETSIMINFO_IMSI_LEN];
+  uint8_t  gid1_len;
+  uint8_t  gid1[APICMD_GETSIMINFO_GID_LEN];
+  uint8_t  gid2_len;
+  uint8_t  gid2[APICMD_GETSIMINFO_GID_LEN];
+} end_packed_struct;
+
+/* structure for APICMDID_GET_IMEI */
+
+begin_packed_struct struct apicmd_cmddat_getimeires_s
+{
+  uint8_t result;
+  uint8_t imei[APICMD_IMEI_LEN];
+} end_packed_struct;
+
+/* structure for APICMDID_GET_IMSI */
+
+begin_packed_struct struct apicmd_cmddat_getimsires_s
+{
+  uint8_t result;
+  uint8_t errcause;
+  uint8_t imsi[APICMD_IMSI_LEN];
+} end_packed_struct;
+
+/* structure for APICMDID_GET_LTIME */
+
+begin_packed_struct struct apicmd_cmddat_getltimeres_s
+{
+  uint8_t result;
+  struct apicmd_cmddat_ltime_s ltime;
+} end_packed_struct;
+
+/* structure for APICMDID_GET_OPERATOR */
+
+begin_packed_struct struct apicmd_cmddat_getoperatorres_s
+{
+  uint8_t result;
+  uint8_t oper[APICMD_OPERATOR_LEN];
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_getoperatorres_v4_s
+{
+  uint8_t result;
+  uint8_t oper[APICMD_OPERATOR_LEN_V4];
+} end_packed_struct;
+
+/* structure for APICMDID_GET_PHONENO */
+
+begin_packed_struct struct apicmd_cmddat_phonenores_s
+{
+  uint8_t result;
+  uint8_t errcause;
+  uint8_t phoneno[APICMD_PHONENO_LEN];
+} end_packed_struct;
+
+/* structure for APICMDID_RADIO_OFF */
+
+begin_packed_struct struct apicmd_cmddat_radiooffres_s
+{
+  uint8_t result;
+} end_packed_struct;
+
+/* structure for APICMDID_RADIO_ON */
+
+begin_packed_struct struct apicmd_cmddat_radioonres_s
+{
+  uint8_t result;
+} end_packed_struct;
+
+/* structure for APICMDID_SET_RAT */
+
+begin_packed_struct struct apicmd_cmddat_setrat_s
+{
+  uint8_t rat;
+  uint8_t persistency;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_setratres_s
+{
+  uint8_t result;
+} end_packed_struct;
+
+/* structure for APICMDID_GET_RAT */
+
+begin_packed_struct struct apicmd_cmddat_getratres_s
+{
+  uint8_t result;
+  uint8_t rat;
+  uint8_t rat_mode;
+  uint8_t source;
+} end_packed_struct;
+
+/* structure for APICMDID_SET_REP_CELLINFO */
+
+begin_packed_struct struct apicmd_cmddat_setrepcellinfo_s
+{
+  uint8_t enability;
+  uint32_t interval;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_setrepcellinfo_res_s
+{
+  uint8_t result;
+} end_packed_struct;
+
+/* structure for APICMDID_SET_REP_EVT */
+
+begin_packed_struct struct apicmd_cmddat_setrepevt_s
+{
+  uint8_t event;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_setrepevt_v4_s
+{
+  uint16_t event;
+  uint8_t enability;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_setrepevtres_s
+{
+  uint8_t result;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_setrepevtres_v4_s
+{
+  uint8_t result;
+  uint16_t event;
+} end_packed_struct;
+
+/* structure for APICMDID_REPORT_EVT */
+
+begin_packed_struct struct apicmd_cmddat_repevt_simd_s
+{
+  uint8_t status;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_repevt_simstate_s
+{
+  uint8_t state;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_repregstate_s
+{
+  uint8_t state;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_reppsmstate_s
+{
+  uint8_t state;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_repantitamper_s
+{
+  uint8_t data;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_repdynpsm_s
+{
+  struct apicmd_cmddat_psm_timeval_s at_val;
+  struct apicmd_cmddat_psm_timeval_s tau_val;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_repdynedrx_s
+{
+  uint8_t acttype;
+  uint8_t edrx_cycle;
+  uint8_t ptw_val;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_repconnphase_s
+{
+  uint8_t state;
+  uint8_t rat;
+  uint8_t scantype;
+  uint8_t scanreason;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_repevt_s
+{
+  uint8_t type;
+  union
+    {
+      struct apicmd_cmddat_ltime_s ltime;
+      struct apicmd_cmddat_repevt_simd_s simd;
+      struct apicmd_cmddat_repevt_simstate_s simstate;
+    } u;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_repevt_v4_s
+{
+  uint16_t type;
+  union
+    {
+      struct apicmd_cmddat_ltime_s ltime;
+      struct apicmd_cmddat_repevt_simd_s simd;
+      struct apicmd_cmddat_repevt_simstate_s simstate;
+      struct apicmd_cmddat_repregstate_s regstate;
+      struct apicmd_cmddat_reppsmstate_s psmstate;
+      struct apicmd_cmddat_repdynpsm_s dynpsm;
+      struct apicmd_cmddat_repdynedrx_s dynedrx;
+      struct apicmd_cmddat_repconnphase_s connphase;
+      struct apicmd_cmddat_repantitamper_s antitamper;
+    } u;
+} end_packed_struct;
+
+/* structure for APICMDID_SETREP_NETINFO */
+
+begin_packed_struct struct apicmd_cmddat_set_repnetinfo_s
+{
+  uint8_t report;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_set_repnetinfores_s
+{
+  uint8_t result;
+} end_packed_struct;
+
+/* structure for APICMDID_REPORT_NETINFO */
+
+begin_packed_struct struct apicmd_cmddat_rep_netinfo_s
+{
+  struct apicmd_netinfo_s netinfo;
+  uint8_t dnsaddrv4[APICMD_IPV4_LEN];
+  uint8_t dnsaddrv6[APICMD_IPV6_LEN];
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_rep_netinfo_v4_s
+{
+  struct apicmd_netinfo_v4_s netinfo;
+} end_packed_struct;
+
+/* structure for APICMDID_SET_REP_QUALITY */
+
+begin_packed_struct struct apicmd_cmddat_setrepquality_s
+{
+  uint8_t enability;
+  uint32_t interval;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_setrepquality_res_s
+{
+  uint8_t result;
+} end_packed_struct;
+
+/* structure for APICMDID_SET_CE */
+
+begin_packed_struct struct apicmd_cmddat_setce_s
+{
+  uint8_t mode_a_enable;
+  uint8_t mode_b_enable;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_setceres_s
+{
+  uint8_t result;
+} end_packed_struct;
+
+/* structure for APICMDID_SET_EDRX */
+
+begin_packed_struct struct apicmd_cmddat_setedrx_s
+{
+  uint8_t acttype;
+  uint8_t enable;
+  uint8_t edrx_cycle;
+  uint8_t ptw_val;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_setedrxres_s
+{
+  uint8_t result;
+} end_packed_struct;
+
+/* structure for APICMDID_SET_PIN_CODE */
+
+begin_packed_struct struct apicmd_cmddat_setpincode_s
+{
+  uint8_t chgtype;
+  uint8_t pincode[APICMD_SETPINCODE_PINCODE_LEN];
+  uint8_t newpincode[APICMD_SETPINCODE_PINCODE_LEN];
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_setpincoderes_s
+{
+  uint8_t result;
+  uint8_t attemptsleft;
+} end_packed_struct;
+
+/* structure for APICMDID_SET_PIN_LOCK */
+
+begin_packed_struct struct apicmd_cmddat_setpinlock_s
+{
+  uint8_t mode;
+  uint8_t pincode[APICMD_SETPINLOCK_PINCODE_LEN];
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_setpinlockres_s
+{
+  uint8_t result;
+  uint8_t attemptsleft;
+} end_packed_struct;
+
+/* structure for APICMDID_SET_PSM */
+
+begin_packed_struct struct apicmd_cmddat_setpsm_s
+{
+  struct apicmd_cmddat_psm_set_s set;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_setpsmres_s
+{
+  uint8_t result;
+} end_packed_struct;
+
+/* structure for APICMDID_GET_VERSION */
+
+begin_packed_struct struct apicmd_cmddat_getverres_s
+{
+  uint8_t result;
+  uint8_t bb_product[APICMD_VERSION_RES_BB_PRODUCT_LEN];
+  uint8_t np_package[APICMD_VERSION_RES_NP_PACKAGE_LEN];
+} end_packed_struct;
+
+/* structure for APICMDID_FW_INJECTDELTAIMG */
+
+begin_packed_struct struct apicmd_cmddat_fw_injectdeltaimg_s
+{
+  uint8_t  data[APICMD_FW_INJECTDATA_MAXLEN];
+  uint32_t data_len;
+  uint8_t  inject_mode;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_fw_injectdeltaimg_v4_s
+{
+  uint8_t  inject_mode;
+  uint32_t data_len;
+
+  /* Variable length array */
+
+  uint8_t  data[1];
+} end_packed_struct;
+
+/* structure for APICMDID_FW_INJECTDELTAIMG_RES,
+ * APICMDID_FW_GETDELTAIMGLEN_RES, APICMDID_FW_EXECDELTAUPDATE_RES,
+ * APICMDID_FW_GETUPDATERESULT_RES
+ */
+
+begin_packed_struct struct apicmd_cmddat_fw_deltaupcommres_s
+{
+  int32_t  api_result;
+  uint16_t ltefw_result;
+} end_packed_struct;
+
+#endif  /* __DRIVERS_MODEM_ALT1250_ALTCOM_CMD_H__ */

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



##########
drivers/modem/alt1250/altcom_cmd_sock.h:
##########
@@ -0,0 +1,509 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_cmd_sock.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_CMD_SOCK_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_CMD_SOCK_H__
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+#include <nuttx/modem/alt1250.h>
+
+#include <stdbool.h>
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define APICMD_NAME_LENGTH        (256)
+#define APICMD_SERVNAME_LENGTH    (32)
+#define APICMD_H_ADDR_LENGTH      (16)
+#define APICMD_OPTVAL_LENGTH      (16)
+#define APICMD_DATA_LENGTH        (1500)
+#define APICMD_AI_COUNT           (2)
+
+#define APICMD_SELECT_NONBLOCK    (0)
+#define APICMD_SELECT_BLOCK       (1)
+#define APICMD_SELECT_BLOCKCANCEL (2)
+#define APICMD_SELECT_READ_BIT    (1 << 0)
+#define APICMD_SELECT_WRITE_BIT   (1 << 1)
+#define APICMD_SELECT_EXCEPT_BIT  (1 << 2)
+
+/* Using for socket: Address family
+ * Referenced from socket.h of lwIP-v2.02
+ */
+
+#define ALTCOM_AF_UNSPEC           0                /* Refer to AF_UNSPEC on lwIP */
+#define ALTCOM_AF_INET             2                /* Refer to AF_INET on lwIP   */
+#define ALTCOM_AF_INET6            10               /* Refer to AF_INET6 on lwIP  */
+#define ALTCOM_PF_INET             ALTCOM_AF_INET   /* Refer to PF_INET on lwIP   */
+#define ALTCOM_PF_INET6            ALTCOM_AF_INET6  /* Refer to PF_INET6 on lwIP  */
+#define ALTCOM_PF_UNSPEC           ALTCOM_AF_UNSPEC /* Refer to PF_UNSPEC on lwIP */
+
+/* Using for socket: Socket protocol type
+ * Referenced from socket.h of lwIP-v2.02
+ */
+
+#define ALTCOM_SOCK_STREAM         1   /* Refer to SOCK_STREAM on lwIP     */
+#define ALTCOM_SOCK_DGRAM          2   /* Refer to SOCK_DGRAM on lwIP      */
+#define ALTCOM_SOCK_RAW            3   /* Refer to SOCK_RAW on lwIP        */
+#define ALTCOM_SOCK_DGRAM_DTLS     130 /* Refer to SOCK_DGRAM_DTLS on lwIP */
+
+/* Using for socket: Protocol
+ * Referenced from socket.h of lwIP-v2.02
+ */
+
+#define ALTCOM_IPPROTO_IP          0   /* Refer to IPPROTO_IP on lwIP      */
+#define ALTCOM_IPPROTO_ICMP        1   /* Refer to IPPROTO_ICMP on lwIP    */
+#define ALTCOM_IPPROTO_TCP         6   /* Refer to IPPROTO_TCP on lwIP     */
+#define ALTCOM_IPPROTO_UDP         17  /* Refer to IPPROTO_UDP on lwIP     */
+#define ALTCOM_IPPROTO_IPV6        41  /* Refer to IPPROTO_IPV6 on lwIP    */
+#define ALTCOM_IPPROTO_ICMPV6      58  /* Refer to IPPROTO_ICMPV6 on lwIP  */
+#define ALTCOM_IPPROTO_UDPLITE     136 /* Refer to IPPROTO_UDPLITE on lwIP */
+#define ALTCOM_IPPROTO_RAW         255 /* Refer to IPPROTO_RAW on lwIP     */
+
+/* Using for recvfrom/sendto: Flags
+ * Referenced from socket.h of lwIP-v2.02
+ */
+
+#define ALTCOM_MSG_PEEK            0x01 /* Refer to MSG_PEEK on lwIP     */
+#define ALTCOM_MSG_WAITALL         0x02 /* Refer to MSG_WAITALL on lwIP  */
+#define ALTCOM_MSG_OOB             0x04 /* Refer to MSG_OOB on lwIP      */
+#define ALTCOM_MSG_DONTWAIT        0x08 /* Refer to MSG_DONTWAIT on lwIP */
+#define ALTCOM_MSG_MORE            0x10 /* Refer to MSG_MORE on lwIP     */
+
+/* Using for setsockopt/getsockopt: Level
+ * Referenced from socket.h of lwIP-v2.02
+ */
+
+#define ALTCOM_SOL_SOCKET          0xfff /* Refer to SOL_SOCKET on lwIP */
+
+/* Using for setsockopt/getsockopt: Option flags per-socket
+ * Referenced from socket.h of lwIP-v2.02
+ */
+
+#define ALTCOM_SO_REUSEADDR        0x0004 /* Refer to SO_REUSEADDR on lwIP */
+#define ALTCOM_SO_KEEPALIVE        0x0008 /* Refer to SO_KEEPALIVE on lwIP */
+#define ALTCOM_SO_BROADCAST        0x0020 /* Refer to SO_BROADCAST on lwIP */
+
+/* Using for setsockopt/getsockopt:
+ * Additional options, not kept in so_options
+ * Referenced from socket.h of lwIP-v2.02
+ */
+
+#define ALTCOM_SO_ACCEPTCONN       0x0002 /* Refer to SO_ACCEPTCONN on lwIP */
+#define ALTCOM_SO_LINGER           0x0080 /* Refer to SO_LINGER on lwIP     */
+#define ALTCOM_SO_RCVBUF           0x1002 /* Refer to SO_RCVBUF on lwIP     */
+#define ALTCOM_SO_SNDTIMEO         0x1005 /* Refer to SO_SNDTIMEO on lwIP   */
+#define ALTCOM_SO_RCVTIMEO         0x1006 /* Refer to SO_RCVTIMEO on lwIP   */
+#define ALTCOM_SO_ERROR            0x1007 /* Refer to SO_ERROR on lwIP      */
+#define ALTCOM_SO_TYPE             0x1008 /* Refer to SO_TYPE on lwIP       */
+#define ALTCOM_SO_NO_CHECK         0x100a /* Refer to SO_NO_CHECK on lwIP   ss*/
+
+/* Options for level IPPROTO_IP
+ * Referenced from socket.h of lwIP-v2.02
+ */
+
+#define ALTCOM_IP_TOS              1 /* Refer to IP_TOS on lwIP */
+#define ALTCOM_IP_TTL              2 /* Refer to IP_TTL on lwIP */
+
+/* Options and types related to multicast membership
+ * Referenced from socket.h of lwIP-v2.02
+ */
+
+#define ALTCOM_IP_ADD_MEMBERSHIP   3 /* Refer to IP_ADD_MEMBERSHIP on lwIP  */
+#define ALTCOM_IP_DROP_MEMBERSHIP  4 /* Refer to IP_DROP_MEMBERSHIP on lwIP */
+
+/* Options and types for UDP multicast traffic handling
+ * Referenced from socket.h of lwIP-v2.02
+ */
+
+#define ALTCOM_IP_MULTICAST_TTL    5 /* Refer to IP_MULTICAST_TTL on lwIP  */
+#define ALTCOM_IP_MULTICAST_IF     6 /* Refer to IP_MULTICAST_IF on lwIP   */
+#define ALTCOM_IP_MULTICAST_LOOP   7 /* Refer to IP_MULTICAST_LOOP on lwIP */
+
+/* Options for level ALTCOM_IPPROTO_TCP
+ * Referenced from socket.h of lwIP-v2.02
+ */
+
+#define ALTCOM_TCP_NODELAY         0x01 /* Refer to TCP_NODELAY on lwIP   */
+#define ALTCOM_TCP_KEEPALIVE       0x02 /* Refer to TCP_KEEPALIVE on lwIP */
+#define ALTCOM_TCP_KEEPIDLE        0x03 /* Refer to TCP_KEEPIDLE on lwIP  */
+#define ALTCOM_TCP_KEEPINTVL       0x04 /* Refer to TCP_KEEPINTVL on lwIP */
+#define ALTCOM_TCP_KEEPCNT         0x05 /* Refer to TCP_KEEPCNT on lwIP   */
+
+/* Options for level ALTCOM_IPPROTO_IPV6
+ * Referenced from socket.h of lwIP-v2.02
+ */
+
+#define ALTCOM_IPV6_V6ONLY         27 /* Refer to IPV6_V6ONLY on lwIP */
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+typedef uint8_t  altcom_sa_family_t;
+typedef uint32_t altcom_socklen_t;
+typedef uint16_t altcom_in_port_t;
+
+typedef uint32_t altcom_in_addr_t;
+
+struct altcom_in_addr
+{
+  altcom_in_addr_t s_addr;
+};
+
+struct altcom_in6_addr
+{
+  union
+  {
+    uint32_t u32_addr[4];
+    uint16_t u16_addr[8];
+    uint8_t  u8_addr[16];
+  } un;
+#define altcom_s6_addr  un.u8_addr
+};
+
+struct altcom_sockaddr_storage
+{
+  uint8_t            s2_len;
+  altcom_sa_family_t ss_family;
+  char               s2_data1[2];
+  uint32_t           s2_data2[3];
+  uint32_t           s2_data3[3];
+};
+
+struct altcom_sockaddr_in
+{
+  uint8_t                sin_len;
+  altcom_sa_family_t     sin_family;
+  altcom_in_port_t       sin_port;
+  struct altcom_in_addr  sin_addr;
+#define ALTCOM_SIN_ZERO_LEN 8
+  char                   sin_zero[ALTCOM_SIN_ZERO_LEN];
+};
+
+struct altcom_sockaddr_in6
+{
+  uint8_t                sin6_len;
+  altcom_sa_family_t     sin6_family;
+  altcom_in_port_t       sin6_port;
+  uint32_t               sin6_flowinfo;
+  struct altcom_in6_addr sin6_addr;
+  uint32_t               sin6_scope_id;
+};
+
+struct altcom_ip_mreq
+{
+  struct altcom_in_addr imr_multiaddr;
+  struct altcom_in_addr imr_interface;
+};
+
+struct altcom_linger
+{
+  int l_onoff;
+  int l_linger;
+};
+
+/* structure for APICMDID_SOCK_ACCEPT and APICMDID_SOCK_GETSOCKNAME */
+
+begin_packed_struct struct altmdmpkt_sockaddrlen_s
+{
+  int32_t sockfd;
+  uint32_t addrlen;
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_BIND and APICMDID_SOCK_CONNECT */
+
+begin_packed_struct struct altmdmpkt_sockaddr_s
+{
+  int32_t sockfd;
+  uint32_t namelen;
+  struct altcom_sockaddr_storage name;
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_CLOSE */
+
+begin_packed_struct struct apicmd_close_s
+{
+  int32_t sockfd;
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_FCNTL */
+
+begin_packed_struct struct apicmd_fcntl_s
+{
+  int32_t sockfd;
+  int32_t cmd;
+  int32_t val;
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_GETADDRINFO */
+
+begin_packed_struct struct apicmd_getaddrinfo_s
+{
+  uint32_t nodenamelen;
+  int8_t nodename[APICMD_NAME_LENGTH];
+  uint32_t servnamelen;
+  int8_t servname[APICMD_SERVNAME_LENGTH];
+  int32_t hints_flag;
+  int32_t ai_flags;
+  int32_t ai_family;
+  int32_t ai_socktype;
+  int32_t ai_protocol;
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_GETHOSTBYNAME */
+
+begin_packed_struct struct apicmd_gethostbyname_s
+{
+  uint32_t namelen;
+  int8_t name[APICMD_NAME_LENGTH];
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_GETHOSTBYNAMER */
+
+begin_packed_struct struct apicmd_gethostbynamer_s
+{
+  uint32_t namelen;
+  int8_t name[APICMD_NAME_LENGTH];
+  int32_t buflen;
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_GETSOCKOPT */
+
+begin_packed_struct struct apicmd_getsockopt_s
+{
+  int32_t sockfd;
+  int32_t level;
+  int32_t optname;
+  int32_t optlen;
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_LISTEN */
+
+begin_packed_struct struct apicmd_listen_s
+{
+  int32_t sockfd;
+  int32_t backlog;
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_RECV */
+
+begin_packed_struct struct apicmd_recv_s
+{
+  int32_t sockfd;
+  int32_t recvlen;
+  int32_t flags;
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_RECVFROM */
+
+begin_packed_struct struct apicmd_recvfrom_s
+{
+  int32_t sockfd;
+  int32_t recvlen;
+  int32_t flags;
+  uint32_t fromlen;
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_SELECT */
+
+begin_packed_struct struct apicmd_select_s
+{
+  int32_t request;
+  int32_t id;
+  int32_t maxfds;
+  uint16_t used_setbit;
+  altcom_fd_set readset;
+  altcom_fd_set writeset;
+  altcom_fd_set exceptset;
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_SEND */
+
+begin_packed_struct struct apicmd_send_s
+{
+  int32_t sockfd;
+  int32_t flags;
+  int32_t datalen;
+  int8_t senddata[APICMD_DATA_LENGTH];
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_SENDTO */
+
+begin_packed_struct struct apicmd_sendto_s
+{
+  int32_t sockfd;
+  int32_t flags;
+  int32_t datalen;
+  uint32_t tolen;
+  struct altcom_sockaddr_storage to;
+  int8_t senddata[APICMD_DATA_LENGTH];
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_SETSOCKOPT */
+
+begin_packed_struct struct apicmd_setsockopt_s
+{
+  int32_t sockfd;
+  int32_t level;
+  int32_t optname;
+  int32_t optlen;
+  int8_t optval[APICMD_OPTVAL_LENGTH];
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_SHUTDOWN */
+
+begin_packed_struct struct apicmd_shutdown_s
+{
+  int32_t sockfd;
+  int32_t how;
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_SOCKET */
+
+begin_packed_struct struct apicmd_socket_s
+{
+  int32_t domain;
+  int32_t type;
+  int32_t protocol;
+} end_packed_struct;
+
+/****************************************************************************/
+
+/* structure for APICMDID_SOCK_BIND and APICMDID_SOCK_CLOSE,
+ * APICMDID_SOCK_CONNECT, APICMDID_SOCK_FCNTL, APICMDID_SOCK_LISTEN,
+ * APICMDID_SOCK_SEND, APICMDID_SOCK_SENDTO, APICMDID_SOCK_SETSOCKOPT,
+ * APICMDID_SOCK_SHUTDOWN, APICMDID_SOCK_SOCKET
+ */
+
+begin_packed_struct struct altmdmpktr_sockcomm_s
+{
+  int32_t ret_code;
+  int32_t err_code;
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_ACCEPT and APICMDID_SOCK_GETSOCKNAME */
+
+begin_packed_struct struct altmdmpktr_sockaddr_s
+{
+  int32_t ret_code;
+  int32_t err_code;
+  uint32_t addrlen;
+  struct altcom_sockaddr_storage address;
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_GETADDRINFO */
+
+begin_packed_struct struct apicmd_getaddrinfo_ai_s
+{
+  int32_t ai_flags;
+  int32_t ai_family;
+  int32_t ai_socktype;
+  int32_t ai_protocol;
+  altcom_socklen_t ai_addrlen;
+  struct altcom_sockaddr_storage ai_addr;
+  uint32_t ai_cnamelen;
+  int8_t ai_canonname[APICMD_NAME_LENGTH];
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_GETADDRINFO */
+
+begin_packed_struct struct apicmd_getaddrinfores_s
+{
+  int32_t ret_code;
+  uint32_t ai_num;
+  struct apicmd_getaddrinfo_ai_s ai[APICMD_AI_COUNT];
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_GETHOSTBYNAME */
+
+begin_packed_struct struct apicmd_gethostbynameres_s
+{
+  int32_t ret_code;
+  int8_t h_name[APICMD_NAME_LENGTH];
+  int8_t h_aliases[APICMD_NAME_LENGTH];
+  int32_t h_addrtype;
+  int32_t h_length;
+  int8_t h_addr_list[APICMD_H_ADDR_LENGTH];
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_GETHOSTBYNAMER */
+
+begin_packed_struct struct apicmd_gethostbynamer_res_s
+{
+  int32_t ret_code;
+  int32_t err_code;
+  int8_t h_name[APICMD_NAME_LENGTH];
+  int8_t h_aliases[APICMD_NAME_LENGTH];
+  int32_t h_addrtype;
+  int32_t h_length;
+  int8_t h_addr_list[APICMD_H_ADDR_LENGTH];
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_GETSOCKOPT */
+
+begin_packed_struct struct apicmd_getsockoptres_s
+{
+  int32_t ret_code;
+  int32_t err_code;
+  int32_t optlen;
+  int8_t optval[APICMD_OPTVAL_LENGTH];
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_RECV */
+
+begin_packed_struct struct apicmd_recvres_s
+{
+  int32_t ret_code;
+  int32_t err_code;
+  int8_t recvdata[APICMD_DATA_LENGTH];
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_RECVFROM */
+
+begin_packed_struct struct apicmd_recvfromres_s
+{
+  int32_t ret_code;
+  int32_t err_code;
+  uint32_t fromlen;
+  struct altcom_sockaddr_storage from;
+  int8_t recvdata[APICMD_DATA_LENGTH];
+} end_packed_struct;
+
+/* structure for APICMDID_SOCK_SELECT */
+
+begin_packed_struct struct apicmd_selectres_s
+{
+  int32_t ret_code;
+  int32_t err_code;
+  int32_t id;
+  uint16_t used_setbit;
+  altcom_fd_set readset;
+  altcom_fd_set writeset;
+  altcom_fd_set exceptset;
+} end_packed_struct;
+
+#endif  /* __DRIVERS_MODEM_ALT1250_ALTCOM_CMD_SOCK_H__ */

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



##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int alt1250_poll(FAR struct file *filep, struct pollfd *fds,
+  bool setup);
+
+parse_handler_t alt1250_additional_parsehdlr(uint16_t, uint8_t);
+compose_handler_t alt1250_additional_composehdlr(uint32_t,
+    FAR uint8_t *, size_t);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* This the vtable that supports the character driver interface. */
+
+static const struct file_operations g_alt1250fops =
+{
+  alt1250_open,  /* open */
+  alt1250_close, /* close */
+  alt1250_read,  /* read */
+  0,             /* write */
+  0,             /* seek */
+  alt1250_ioctl, /* ioctl */
+  alt1250_poll,  /* poll */
+};
+static uint8_t g_recvbuff[ALTCOM_RX_PKT_SIZE_MAX];
+static uint8_t g_sendbuff[ALTCOM_PKT_SIZE_MAX];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: add_list
+ ****************************************************************************/
+
+static void add_list(FAR struct alt_queue_s *head,
+  FAR struct alt_container_s *list)

Review Comment:
   ```suggestion
   static void add_list(FAR struct alt_queue_s *head,
                        FAR struct alt_container_s *list)
   ```



##########
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(uint8_t *stream, char *delim)

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



##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int alt1250_poll(FAR struct file *filep, struct pollfd *fds,
+  bool setup);
+
+parse_handler_t alt1250_additional_parsehdlr(uint16_t, uint8_t);
+compose_handler_t alt1250_additional_composehdlr(uint32_t,
+    FAR uint8_t *, size_t);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* This the vtable that supports the character driver interface. */
+
+static const struct file_operations g_alt1250fops =
+{
+  alt1250_open,  /* open */
+  alt1250_close, /* close */
+  alt1250_read,  /* read */
+  0,             /* write */
+  0,             /* seek */
+  alt1250_ioctl, /* ioctl */
+  alt1250_poll,  /* poll */
+};
+static uint8_t g_recvbuff[ALTCOM_RX_PKT_SIZE_MAX];
+static uint8_t g_sendbuff[ALTCOM_PKT_SIZE_MAX];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: add_list
+ ****************************************************************************/
+
+static void add_list(FAR struct alt_queue_s *head,
+  FAR struct alt_container_s *list)
+{
+  FAR struct alt_container_s *next;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  while (list != NULL)
+    {
+      next = (FAR struct alt_container_s *)sq_next(&list->node);
+
+      sq_next(&list->node) = NULL;
+      sq_addlast(&list->node, &head->queue);
+
+      list = next;
+    }
+
+  nxsem_post(&head->lock);
+}
+
+/****************************************************************************
+ * Name: remove_list_all
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list_all(
+  FAR struct alt_queue_s *head)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  sq_init(&head->queue);
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: remove_list
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list(FAR struct alt_queue_s *head,
+  uint16_t cmdid, uint16_t transid)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  while (list != NULL)
+    {
+      if ((list->altcid == cmdid) && (list->alttid == transid))
+        {
+          sq_rem(&list->node, &head->queue);
+          sq_next(&list->node) = NULL;
+          break;
+        }
+
+      list = (FAR struct alt_container_s *)sq_next(&list->node);
+    }
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: set_senddisable
+ ****************************************************************************/
+
+static void set_senddisable(FAR struct alt1250_dev_s *dev, bool disable)
+{
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  dev->senddisable = disable;
+
+  nxsem_post(&dev->senddisablelock);
+}
+
+/****************************************************************************
+ * Name: is_senddisable
+ ****************************************************************************/
+
+static bool is_senddisable(FAR struct alt1250_dev_s *dev)
+{
+  bool disable;
+
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  disable = dev->senddisable;
+
+  nxsem_post(&dev->senddisablelock);
+
+  return disable;
+}
+
+/****************************************************************************
+ * Name: read_evtbitmap
+ ****************************************************************************/
+
+static ssize_t read_data(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_readdata_s *rdata)
+{
+  int idx;
+
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  /* change status to NOT WRITABLE */
+
+  for (idx = 0; idx < (sizeof(uint64_t) * 8); idx++)
+    {
+      if (dev->evtbitmap & (1ULL << idx))
+        {
+          if (dev->evtbuff->ninst >= idx)
+            {
+              FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx];
+
+              nxsem_wait_uninterruptible(&inst->stat_lock);
+
+              inst->stat = ALTEVTBUF_ST_NOTWRITABLE;
+
+              nxsem_post(&inst->stat_lock);
+            }
+        }
+    }
+
+  rdata->evtbitmap = dev->evtbitmap;
+  rdata->head = remove_list_all(&dev->replylist);
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      /* Resume sending because daemon has been notified of the reset
+       * reliably.
+       */
+
+      set_senddisable(dev, false);
+    }
+
+  dev->evtbitmap = 0ULL;
+
+  nxsem_post(&dev->evtmaplock);
+
+  return sizeof(struct alt_readdata_s);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmap
+ ****************************************************************************/
+
+static void write_evtbitmap(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  m_info("write bitmap: 0x%llx\n", bitmap);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmapwithlist
+ ****************************************************************************/
+
+static void write_evtbitmapwithlist(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap, FAR struct alt_container_s *container)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  add_list(&dev->replylist, container);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: add_evtbuff
+ ****************************************************************************/
+
+static void add_evtbuff(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_evtbuffer_s *buff)
+{
+  dev->evtbuff = buff;
+}
+
+/****************************************************************************
+ * Name: write_evtbuff_byidx
+ ****************************************************************************/
+
+static int write_evtbuff_byidx(FAR struct alt1250_dev_s *dev,
+  uint64_t idx, void(*write_func)(FAR void *outp[], FAR void *inp),
+  FAR void *inp)
+{
+  int ret = WRITE_NG;
+
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  if (dev->evtbuff)
+    {
+      if (dev->evtbuff->ninst >= idx)
+        {
+          FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx];
+
+          nxsem_wait_uninterruptible(&inst->stat_lock);
+          if (inst->stat == ALTEVTBUF_ST_WRITABLE)
+            {
+              write_func(inst->outparam, inp);
+              dev->evtbitmap |= (1ULL << idx);
+              ret = WRITE_OK;
+            }
+
+          nxsem_post(&inst->stat_lock);
+        }
+    }
+
+  nxsem_post(&dev->evtmaplock);
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: lock_evtbuffinst
+ ****************************************************************************/
+
+static void lock_evtbuffinst(FAR alt_evtbuf_inst_t *inst,
+  FAR struct alt1250_dev_s *dev)

Review Comment:
   ```suggestion
   static void lock_evtbuffinst(FAR alt_evtbuf_inst_t *inst,
                                FAR struct alt1250_dev_s *dev)
   ```



##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int alt1250_poll(FAR struct file *filep, struct pollfd *fds,
+  bool setup);
+
+parse_handler_t alt1250_additional_parsehdlr(uint16_t, uint8_t);
+compose_handler_t alt1250_additional_composehdlr(uint32_t,
+    FAR uint8_t *, size_t);

Review Comment:
   ```suggestion
   compose_handler_t alt1250_additional_composehdlr(uint32_t,
                                                    FAR uint8_t *, size_t);
   ```



##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int alt1250_poll(FAR struct file *filep, struct pollfd *fds,
+  bool setup);
+
+parse_handler_t alt1250_additional_parsehdlr(uint16_t, uint8_t);
+compose_handler_t alt1250_additional_composehdlr(uint32_t,
+    FAR uint8_t *, size_t);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* This the vtable that supports the character driver interface. */
+
+static const struct file_operations g_alt1250fops =
+{
+  alt1250_open,  /* open */
+  alt1250_close, /* close */
+  alt1250_read,  /* read */
+  0,             /* write */
+  0,             /* seek */
+  alt1250_ioctl, /* ioctl */
+  alt1250_poll,  /* poll */
+};
+static uint8_t g_recvbuff[ALTCOM_RX_PKT_SIZE_MAX];
+static uint8_t g_sendbuff[ALTCOM_PKT_SIZE_MAX];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: add_list
+ ****************************************************************************/
+
+static void add_list(FAR struct alt_queue_s *head,
+  FAR struct alt_container_s *list)
+{
+  FAR struct alt_container_s *next;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  while (list != NULL)
+    {
+      next = (FAR struct alt_container_s *)sq_next(&list->node);
+
+      sq_next(&list->node) = NULL;
+      sq_addlast(&list->node, &head->queue);
+
+      list = next;
+    }
+
+  nxsem_post(&head->lock);
+}
+
+/****************************************************************************
+ * Name: remove_list_all
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list_all(
+  FAR struct alt_queue_s *head)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  sq_init(&head->queue);
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: remove_list
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list(FAR struct alt_queue_s *head,
+  uint16_t cmdid, uint16_t transid)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  while (list != NULL)
+    {
+      if ((list->altcid == cmdid) && (list->alttid == transid))
+        {
+          sq_rem(&list->node, &head->queue);
+          sq_next(&list->node) = NULL;
+          break;
+        }
+
+      list = (FAR struct alt_container_s *)sq_next(&list->node);
+    }
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: set_senddisable
+ ****************************************************************************/
+
+static void set_senddisable(FAR struct alt1250_dev_s *dev, bool disable)
+{
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  dev->senddisable = disable;
+
+  nxsem_post(&dev->senddisablelock);
+}
+
+/****************************************************************************
+ * Name: is_senddisable
+ ****************************************************************************/
+
+static bool is_senddisable(FAR struct alt1250_dev_s *dev)
+{
+  bool disable;
+
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  disable = dev->senddisable;
+
+  nxsem_post(&dev->senddisablelock);
+
+  return disable;
+}
+
+/****************************************************************************
+ * Name: read_evtbitmap
+ ****************************************************************************/
+
+static ssize_t read_data(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_readdata_s *rdata)
+{
+  int idx;
+
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  /* change status to NOT WRITABLE */
+
+  for (idx = 0; idx < (sizeof(uint64_t) * 8); idx++)
+    {
+      if (dev->evtbitmap & (1ULL << idx))
+        {
+          if (dev->evtbuff->ninst >= idx)
+            {
+              FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx];
+
+              nxsem_wait_uninterruptible(&inst->stat_lock);
+
+              inst->stat = ALTEVTBUF_ST_NOTWRITABLE;
+
+              nxsem_post(&inst->stat_lock);
+            }
+        }
+    }
+
+  rdata->evtbitmap = dev->evtbitmap;
+  rdata->head = remove_list_all(&dev->replylist);
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      /* Resume sending because daemon has been notified of the reset
+       * reliably.
+       */
+
+      set_senddisable(dev, false);
+    }
+
+  dev->evtbitmap = 0ULL;
+
+  nxsem_post(&dev->evtmaplock);
+
+  return sizeof(struct alt_readdata_s);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmap
+ ****************************************************************************/
+
+static void write_evtbitmap(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  m_info("write bitmap: 0x%llx\n", bitmap);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmapwithlist
+ ****************************************************************************/
+
+static void write_evtbitmapwithlist(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap, FAR struct alt_container_s *container)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  add_list(&dev->replylist, container);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: add_evtbuff
+ ****************************************************************************/
+
+static void add_evtbuff(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_evtbuffer_s *buff)
+{
+  dev->evtbuff = buff;
+}
+
+/****************************************************************************
+ * Name: write_evtbuff_byidx
+ ****************************************************************************/
+
+static int write_evtbuff_byidx(FAR struct alt1250_dev_s *dev,
+  uint64_t idx, void(*write_func)(FAR void *outp[], FAR void *inp),

Review Comment:
   ```suggestion
   static int write_evtbuff_byidx(FAR struct alt1250_dev_s *dev,
     uint64_t idx, CODE void(*write_func)(FAR void *outp[], FAR void *inp),
   ```



##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int alt1250_poll(FAR struct file *filep, struct pollfd *fds,
+  bool setup);
+
+parse_handler_t alt1250_additional_parsehdlr(uint16_t, uint8_t);
+compose_handler_t alt1250_additional_composehdlr(uint32_t,
+    FAR uint8_t *, size_t);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* This the vtable that supports the character driver interface. */
+
+static const struct file_operations g_alt1250fops =
+{
+  alt1250_open,  /* open */
+  alt1250_close, /* close */
+  alt1250_read,  /* read */
+  0,             /* write */
+  0,             /* seek */
+  alt1250_ioctl, /* ioctl */
+  alt1250_poll,  /* poll */
+};
+static uint8_t g_recvbuff[ALTCOM_RX_PKT_SIZE_MAX];
+static uint8_t g_sendbuff[ALTCOM_PKT_SIZE_MAX];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: add_list
+ ****************************************************************************/
+
+static void add_list(FAR struct alt_queue_s *head,
+  FAR struct alt_container_s *list)
+{
+  FAR struct alt_container_s *next;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  while (list != NULL)
+    {
+      next = (FAR struct alt_container_s *)sq_next(&list->node);
+
+      sq_next(&list->node) = NULL;
+      sq_addlast(&list->node, &head->queue);
+
+      list = next;
+    }
+
+  nxsem_post(&head->lock);
+}
+
+/****************************************************************************
+ * Name: remove_list_all
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list_all(
+  FAR struct alt_queue_s *head)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  sq_init(&head->queue);
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: remove_list
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list(FAR struct alt_queue_s *head,
+  uint16_t cmdid, uint16_t transid)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  while (list != NULL)
+    {
+      if ((list->altcid == cmdid) && (list->alttid == transid))
+        {
+          sq_rem(&list->node, &head->queue);
+          sq_next(&list->node) = NULL;
+          break;
+        }
+
+      list = (FAR struct alt_container_s *)sq_next(&list->node);
+    }
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: set_senddisable
+ ****************************************************************************/
+
+static void set_senddisable(FAR struct alt1250_dev_s *dev, bool disable)
+{
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  dev->senddisable = disable;
+
+  nxsem_post(&dev->senddisablelock);
+}
+
+/****************************************************************************
+ * Name: is_senddisable
+ ****************************************************************************/
+
+static bool is_senddisable(FAR struct alt1250_dev_s *dev)
+{
+  bool disable;
+
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  disable = dev->senddisable;
+
+  nxsem_post(&dev->senddisablelock);
+
+  return disable;
+}
+
+/****************************************************************************
+ * Name: read_evtbitmap
+ ****************************************************************************/
+
+static ssize_t read_data(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_readdata_s *rdata)
+{
+  int idx;
+
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  /* change status to NOT WRITABLE */
+
+  for (idx = 0; idx < (sizeof(uint64_t) * 8); idx++)
+    {
+      if (dev->evtbitmap & (1ULL << idx))
+        {
+          if (dev->evtbuff->ninst >= idx)
+            {
+              FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx];
+
+              nxsem_wait_uninterruptible(&inst->stat_lock);
+
+              inst->stat = ALTEVTBUF_ST_NOTWRITABLE;
+
+              nxsem_post(&inst->stat_lock);
+            }
+        }
+    }
+
+  rdata->evtbitmap = dev->evtbitmap;
+  rdata->head = remove_list_all(&dev->replylist);
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      /* Resume sending because daemon has been notified of the reset
+       * reliably.
+       */
+
+      set_senddisable(dev, false);
+    }
+
+  dev->evtbitmap = 0ULL;
+
+  nxsem_post(&dev->evtmaplock);
+
+  return sizeof(struct alt_readdata_s);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmap
+ ****************************************************************************/
+
+static void write_evtbitmap(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  m_info("write bitmap: 0x%llx\n", bitmap);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmapwithlist
+ ****************************************************************************/
+
+static void write_evtbitmapwithlist(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap, FAR struct alt_container_s *container)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  add_list(&dev->replylist, container);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: add_evtbuff
+ ****************************************************************************/
+
+static void add_evtbuff(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_evtbuffer_s *buff)
+{
+  dev->evtbuff = buff;
+}
+
+/****************************************************************************
+ * Name: write_evtbuff_byidx
+ ****************************************************************************/
+
+static int write_evtbuff_byidx(FAR struct alt1250_dev_s *dev,
+  uint64_t idx, void(*write_func)(FAR void *outp[], FAR void *inp),
+  FAR void *inp)
+{
+  int ret = WRITE_NG;
+
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  if (dev->evtbuff)
+    {
+      if (dev->evtbuff->ninst >= idx)
+        {
+          FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx];
+
+          nxsem_wait_uninterruptible(&inst->stat_lock);
+          if (inst->stat == ALTEVTBUF_ST_WRITABLE)
+            {
+              write_func(inst->outparam, inp);
+              dev->evtbitmap |= (1ULL << idx);
+              ret = WRITE_OK;
+            }
+
+          nxsem_post(&inst->stat_lock);
+        }
+    }
+
+  nxsem_post(&dev->evtmaplock);
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: lock_evtbuffinst
+ ****************************************************************************/
+
+static void lock_evtbuffinst(FAR alt_evtbuf_inst_t *inst,
+  FAR struct alt1250_dev_s *dev)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+  nxsem_wait_uninterruptible(&inst->stat_lock);
+}
+
+/****************************************************************************
+ * Name: unlock_evtbufinst
+ ****************************************************************************/
+
+static void unlock_evtbufinst(FAR alt_evtbuf_inst_t *inst,
+  FAR struct alt1250_dev_s *dev)
+{
+  nxsem_post(&inst->stat_lock);
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: search_evtbufinst
+ ****************************************************************************/
+
+static FAR alt_evtbuf_inst_t *search_evtbufinst(uint16_t cid,
+  FAR uint64_t *bitmap, FAR struct alt1250_dev_s *dev)
+{
+  FAR alt_evtbuf_inst_t *ret = NULL;
+  unsigned int i;
+
+  *bitmap = 0ULL;
+
+  for (i = 0; i < dev->evtbuff->ninst; i++)
+    {
+      ret = &dev->evtbuff->inst[i];
+
+      if (ret->altcid == cid)
+        {
+          *bitmap = 1ULL << i;
+          return ret;
+        }
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: cid_to_searchable
+ ****************************************************************************/
+
+static uint16_t cid_to_searchable(uint16_t cid, uint8_t altver)
+{
+  uint16_t cidv1;
+
+  cid &= ~ALTCOM_CMDID_REPLY_BIT;
+  if (altver == ALTCOM_VER4)
+    {
+      /* Change the command ID to Version 1
+       * Even if it cannot be converted, try to search the table
+       * using the original command ID.
+       */
+
+      cidv1 = convert_cid2v1(cid);
+      if (cidv1 != APICMDID_UNKNOWN)
+        {
+          cid = cidv1;
+        }
+    }
+
+  return cid;
+}
+
+/****************************************************************************
+ * Name: get_bitmap
+ ****************************************************************************/
+
+static uint64_t get_bitmap(FAR struct alt1250_dev_s *dev, uint16_t cid,
+  uint8_t altver)

Review Comment:
   ```suggestion
   static uint64_t get_bitmap(FAR struct alt1250_dev_s *dev, uint16_t cid,
                              uint8_t altver)
   ```



##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int alt1250_poll(FAR struct file *filep, struct pollfd *fds,
+  bool setup);
+
+parse_handler_t alt1250_additional_parsehdlr(uint16_t, uint8_t);
+compose_handler_t alt1250_additional_composehdlr(uint32_t,
+    FAR uint8_t *, size_t);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* This the vtable that supports the character driver interface. */
+
+static const struct file_operations g_alt1250fops =
+{
+  alt1250_open,  /* open */
+  alt1250_close, /* close */
+  alt1250_read,  /* read */
+  0,             /* write */
+  0,             /* seek */
+  alt1250_ioctl, /* ioctl */
+  alt1250_poll,  /* poll */

Review Comment:
   ```suggestion
     alt1250_poll   /* poll */
   #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
     , NULL         /* unlink */
   #endif
   ```



##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int alt1250_poll(FAR struct file *filep, struct pollfd *fds,
+  bool setup);
+
+parse_handler_t alt1250_additional_parsehdlr(uint16_t, uint8_t);
+compose_handler_t alt1250_additional_composehdlr(uint32_t,
+    FAR uint8_t *, size_t);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* This the vtable that supports the character driver interface. */
+
+static const struct file_operations g_alt1250fops =
+{
+  alt1250_open,  /* open */
+  alt1250_close, /* close */
+  alt1250_read,  /* read */
+  0,             /* write */
+  0,             /* seek */

Review Comment:
   ```suggestion
     NULL,          /* write */
     NULL,          /* seek */
   ```



##########
drivers/modem/alt1250/altcom_cmd.h:
##########
@@ -0,0 +1,965 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_cmd.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_CMD_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_CMD_H__

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



##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int alt1250_poll(FAR struct file *filep, struct pollfd *fds,
+  bool setup);
+
+parse_handler_t alt1250_additional_parsehdlr(uint16_t, uint8_t);
+compose_handler_t alt1250_additional_composehdlr(uint32_t,
+    FAR uint8_t *, size_t);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* This the vtable that supports the character driver interface. */
+
+static const struct file_operations g_alt1250fops =
+{
+  alt1250_open,  /* open */
+  alt1250_close, /* close */
+  alt1250_read,  /* read */
+  0,             /* write */
+  0,             /* seek */
+  alt1250_ioctl, /* ioctl */
+  alt1250_poll,  /* poll */
+};
+static uint8_t g_recvbuff[ALTCOM_RX_PKT_SIZE_MAX];
+static uint8_t g_sendbuff[ALTCOM_PKT_SIZE_MAX];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: add_list
+ ****************************************************************************/
+
+static void add_list(FAR struct alt_queue_s *head,
+  FAR struct alt_container_s *list)
+{
+  FAR struct alt_container_s *next;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  while (list != NULL)
+    {
+      next = (FAR struct alt_container_s *)sq_next(&list->node);
+
+      sq_next(&list->node) = NULL;
+      sq_addlast(&list->node, &head->queue);
+
+      list = next;
+    }
+
+  nxsem_post(&head->lock);
+}
+
+/****************************************************************************
+ * Name: remove_list_all
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list_all(
+  FAR struct alt_queue_s *head)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  sq_init(&head->queue);
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: remove_list
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list(FAR struct alt_queue_s *head,
+  uint16_t cmdid, uint16_t transid)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  while (list != NULL)
+    {
+      if ((list->altcid == cmdid) && (list->alttid == transid))
+        {
+          sq_rem(&list->node, &head->queue);
+          sq_next(&list->node) = NULL;
+          break;
+        }
+
+      list = (FAR struct alt_container_s *)sq_next(&list->node);
+    }
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: set_senddisable
+ ****************************************************************************/
+
+static void set_senddisable(FAR struct alt1250_dev_s *dev, bool disable)
+{
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  dev->senddisable = disable;
+
+  nxsem_post(&dev->senddisablelock);
+}
+
+/****************************************************************************
+ * Name: is_senddisable
+ ****************************************************************************/
+
+static bool is_senddisable(FAR struct alt1250_dev_s *dev)
+{
+  bool disable;
+
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  disable = dev->senddisable;
+
+  nxsem_post(&dev->senddisablelock);
+
+  return disable;
+}
+
+/****************************************************************************
+ * Name: read_evtbitmap
+ ****************************************************************************/
+
+static ssize_t read_data(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_readdata_s *rdata)
+{
+  int idx;
+
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  /* change status to NOT WRITABLE */
+
+  for (idx = 0; idx < (sizeof(uint64_t) * 8); idx++)
+    {
+      if (dev->evtbitmap & (1ULL << idx))
+        {
+          if (dev->evtbuff->ninst >= idx)
+            {
+              FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx];
+
+              nxsem_wait_uninterruptible(&inst->stat_lock);
+
+              inst->stat = ALTEVTBUF_ST_NOTWRITABLE;
+
+              nxsem_post(&inst->stat_lock);
+            }
+        }
+    }
+
+  rdata->evtbitmap = dev->evtbitmap;
+  rdata->head = remove_list_all(&dev->replylist);
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      /* Resume sending because daemon has been notified of the reset
+       * reliably.
+       */
+
+      set_senddisable(dev, false);
+    }
+
+  dev->evtbitmap = 0ULL;
+
+  nxsem_post(&dev->evtmaplock);
+
+  return sizeof(struct alt_readdata_s);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmap
+ ****************************************************************************/
+
+static void write_evtbitmap(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  m_info("write bitmap: 0x%llx\n", bitmap);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmapwithlist
+ ****************************************************************************/
+
+static void write_evtbitmapwithlist(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap, FAR struct alt_container_s *container)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  add_list(&dev->replylist, container);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: add_evtbuff
+ ****************************************************************************/
+
+static void add_evtbuff(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_evtbuffer_s *buff)
+{
+  dev->evtbuff = buff;
+}
+
+/****************************************************************************
+ * Name: write_evtbuff_byidx
+ ****************************************************************************/
+
+static int write_evtbuff_byidx(FAR struct alt1250_dev_s *dev,
+  uint64_t idx, void(*write_func)(FAR void *outp[], FAR void *inp),
+  FAR void *inp)
+{
+  int ret = WRITE_NG;
+
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  if (dev->evtbuff)
+    {
+      if (dev->evtbuff->ninst >= idx)
+        {
+          FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx];
+
+          nxsem_wait_uninterruptible(&inst->stat_lock);
+          if (inst->stat == ALTEVTBUF_ST_WRITABLE)
+            {
+              write_func(inst->outparam, inp);
+              dev->evtbitmap |= (1ULL << idx);
+              ret = WRITE_OK;
+            }
+
+          nxsem_post(&inst->stat_lock);
+        }
+    }
+
+  nxsem_post(&dev->evtmaplock);
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: lock_evtbuffinst
+ ****************************************************************************/
+
+static void lock_evtbuffinst(FAR alt_evtbuf_inst_t *inst,
+  FAR struct alt1250_dev_s *dev)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+  nxsem_wait_uninterruptible(&inst->stat_lock);
+}
+
+/****************************************************************************
+ * Name: unlock_evtbufinst
+ ****************************************************************************/
+
+static void unlock_evtbufinst(FAR alt_evtbuf_inst_t *inst,
+  FAR struct alt1250_dev_s *dev)
+{
+  nxsem_post(&inst->stat_lock);
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: search_evtbufinst
+ ****************************************************************************/
+
+static FAR alt_evtbuf_inst_t *search_evtbufinst(uint16_t cid,
+  FAR uint64_t *bitmap, FAR struct alt1250_dev_s *dev)
+{
+  FAR alt_evtbuf_inst_t *ret = NULL;
+  unsigned int i;
+
+  *bitmap = 0ULL;
+
+  for (i = 0; i < dev->evtbuff->ninst; i++)
+    {
+      ret = &dev->evtbuff->inst[i];
+
+      if (ret->altcid == cid)
+        {
+          *bitmap = 1ULL << i;
+          return ret;
+        }
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: cid_to_searchable
+ ****************************************************************************/
+
+static uint16_t cid_to_searchable(uint16_t cid, uint8_t altver)
+{
+  uint16_t cidv1;
+
+  cid &= ~ALTCOM_CMDID_REPLY_BIT;
+  if (altver == ALTCOM_VER4)
+    {
+      /* Change the command ID to Version 1
+       * Even if it cannot be converted, try to search the table
+       * using the original command ID.
+       */
+
+      cidv1 = convert_cid2v1(cid);
+      if (cidv1 != APICMDID_UNKNOWN)
+        {
+          cid = cidv1;
+        }
+    }
+
+  return cid;
+}
+
+/****************************************************************************
+ * Name: get_bitmap
+ ****************************************************************************/
+
+static uint64_t get_bitmap(FAR struct alt1250_dev_s *dev, uint16_t cid,
+  uint8_t altver)
+{
+  uint64_t bitmap = 0ULL;
+
+  cid = cid_to_searchable(cid, altver);
+
+  search_evtbufinst(cid, &bitmap, dev);
+
+  return bitmap;
+}
+
+/****************************************************************************
+ * Name: get_evtbuffinst_withlock
+ ****************************************************************************/
+
+static FAR alt_evtbuf_inst_t *get_evtbuffinst_withlock(
+  FAR struct alt1250_dev_s *dev, uint16_t cid, uint8_t altver,
+  FAR uint64_t *bitmap)
+{
+  FAR alt_evtbuf_inst_t *inst = NULL;
+  FAR alt_evtbuf_inst_t *ret = NULL;
+
+  cid = cid_to_searchable(cid, altver);
+
+  if (cid == APICMDID_SOCK_SELECT)
+    {
+      ret = &dev->select_inst;
+
+      lock_evtbuffinst(ret, dev);
+
+      ret->outparam = dev->select_container->outparam;
+      ret->outparamlen = dev->select_container->outparamlen;
+
+      search_evtbufinst(cid, bitmap, dev);
+    }
+  else
+    {
+      inst = search_evtbufinst(cid, bitmap, dev);
+      if (inst)
+        {
+          lock_evtbuffinst(inst, dev);
+
+          if (inst->stat == ALTEVTBUF_ST_WRITABLE)
+            {
+              ret = inst;
+            }
+          else
+            {
+              unlock_evtbufinst(inst, dev);
+            }
+        }
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: write_restart_param
+ ****************************************************************************/
+
+static void write_restart_param(FAR void *outp[], FAR void *buff)
+{
+  FAR int *out_reason = (FAR int *)outp[0];
+  FAR int *in_reason = (FAR int *)buff;
+
+  *out_reason = *in_reason;
+}
+
+/****************************************************************************
+ * Name: pollnotify
+ ****************************************************************************/
+
+static void pollnotify(FAR struct alt1250_dev_s *dev)
+{
+  nxsem_wait_uninterruptible(&dev->pfdlock);
+
+  if (dev->pfd)
+    {
+      /* If poll() waits, notify  */
+
+      poll_notify(&dev->pfd, 1, POLLIN);
+    }
+
+  nxsem_post(&dev->pfdlock);
+}
+
+/****************************************************************************
+ * Name: get_composehdlr
+ ****************************************************************************/
+
+compose_handler_t get_composehdlr(uint32_t cmdid, FAR uint8_t *payload,
+  size_t size)
+{
+  compose_handler_t ret = NULL;

Review Comment:
   ```suggestion
     compose_handler_t ret;
   ```



##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int alt1250_poll(FAR struct file *filep, struct pollfd *fds,
+  bool setup);
+
+parse_handler_t alt1250_additional_parsehdlr(uint16_t, uint8_t);
+compose_handler_t alt1250_additional_composehdlr(uint32_t,
+    FAR uint8_t *, size_t);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* This the vtable that supports the character driver interface. */
+
+static const struct file_operations g_alt1250fops =
+{
+  alt1250_open,  /* open */
+  alt1250_close, /* close */
+  alt1250_read,  /* read */
+  0,             /* write */
+  0,             /* seek */
+  alt1250_ioctl, /* ioctl */
+  alt1250_poll,  /* poll */
+};
+static uint8_t g_recvbuff[ALTCOM_RX_PKT_SIZE_MAX];
+static uint8_t g_sendbuff[ALTCOM_PKT_SIZE_MAX];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: add_list
+ ****************************************************************************/
+
+static void add_list(FAR struct alt_queue_s *head,
+  FAR struct alt_container_s *list)
+{
+  FAR struct alt_container_s *next;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  while (list != NULL)
+    {
+      next = (FAR struct alt_container_s *)sq_next(&list->node);
+
+      sq_next(&list->node) = NULL;
+      sq_addlast(&list->node, &head->queue);
+
+      list = next;
+    }
+
+  nxsem_post(&head->lock);
+}
+
+/****************************************************************************
+ * Name: remove_list_all
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list_all(
+  FAR struct alt_queue_s *head)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  sq_init(&head->queue);
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: remove_list
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list(FAR struct alt_queue_s *head,
+  uint16_t cmdid, uint16_t transid)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  while (list != NULL)
+    {
+      if ((list->altcid == cmdid) && (list->alttid == transid))
+        {
+          sq_rem(&list->node, &head->queue);
+          sq_next(&list->node) = NULL;
+          break;
+        }
+
+      list = (FAR struct alt_container_s *)sq_next(&list->node);
+    }
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: set_senddisable
+ ****************************************************************************/
+
+static void set_senddisable(FAR struct alt1250_dev_s *dev, bool disable)
+{
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  dev->senddisable = disable;
+
+  nxsem_post(&dev->senddisablelock);
+}
+
+/****************************************************************************
+ * Name: is_senddisable
+ ****************************************************************************/
+
+static bool is_senddisable(FAR struct alt1250_dev_s *dev)
+{
+  bool disable;
+
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  disable = dev->senddisable;
+
+  nxsem_post(&dev->senddisablelock);
+
+  return disable;
+}
+
+/****************************************************************************
+ * Name: read_evtbitmap
+ ****************************************************************************/
+
+static ssize_t read_data(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_readdata_s *rdata)
+{
+  int idx;
+
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  /* change status to NOT WRITABLE */
+
+  for (idx = 0; idx < (sizeof(uint64_t) * 8); idx++)
+    {
+      if (dev->evtbitmap & (1ULL << idx))
+        {
+          if (dev->evtbuff->ninst >= idx)
+            {
+              FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx];
+
+              nxsem_wait_uninterruptible(&inst->stat_lock);
+
+              inst->stat = ALTEVTBUF_ST_NOTWRITABLE;
+
+              nxsem_post(&inst->stat_lock);
+            }
+        }
+    }
+
+  rdata->evtbitmap = dev->evtbitmap;
+  rdata->head = remove_list_all(&dev->replylist);
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      /* Resume sending because daemon has been notified of the reset
+       * reliably.
+       */
+
+      set_senddisable(dev, false);
+    }
+
+  dev->evtbitmap = 0ULL;
+
+  nxsem_post(&dev->evtmaplock);
+
+  return sizeof(struct alt_readdata_s);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmap
+ ****************************************************************************/
+
+static void write_evtbitmap(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  m_info("write bitmap: 0x%llx\n", bitmap);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmapwithlist
+ ****************************************************************************/
+
+static void write_evtbitmapwithlist(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap, FAR struct alt_container_s *container)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  add_list(&dev->replylist, container);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: add_evtbuff
+ ****************************************************************************/
+
+static void add_evtbuff(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_evtbuffer_s *buff)
+{
+  dev->evtbuff = buff;
+}
+
+/****************************************************************************
+ * Name: write_evtbuff_byidx
+ ****************************************************************************/
+
+static int write_evtbuff_byidx(FAR struct alt1250_dev_s *dev,
+  uint64_t idx, void(*write_func)(FAR void *outp[], FAR void *inp),
+  FAR void *inp)
+{
+  int ret = WRITE_NG;
+
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  if (dev->evtbuff)
+    {
+      if (dev->evtbuff->ninst >= idx)
+        {
+          FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx];
+
+          nxsem_wait_uninterruptible(&inst->stat_lock);
+          if (inst->stat == ALTEVTBUF_ST_WRITABLE)
+            {
+              write_func(inst->outparam, inp);
+              dev->evtbitmap |= (1ULL << idx);
+              ret = WRITE_OK;
+            }
+
+          nxsem_post(&inst->stat_lock);
+        }
+    }
+
+  nxsem_post(&dev->evtmaplock);
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: lock_evtbuffinst
+ ****************************************************************************/
+
+static void lock_evtbuffinst(FAR alt_evtbuf_inst_t *inst,
+  FAR struct alt1250_dev_s *dev)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+  nxsem_wait_uninterruptible(&inst->stat_lock);
+}
+
+/****************************************************************************
+ * Name: unlock_evtbufinst
+ ****************************************************************************/
+
+static void unlock_evtbufinst(FAR alt_evtbuf_inst_t *inst,
+  FAR struct alt1250_dev_s *dev)
+{
+  nxsem_post(&inst->stat_lock);
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: search_evtbufinst
+ ****************************************************************************/
+
+static FAR alt_evtbuf_inst_t *search_evtbufinst(uint16_t cid,
+  FAR uint64_t *bitmap, FAR struct alt1250_dev_s *dev)
+{
+  FAR alt_evtbuf_inst_t *ret = NULL;
+  unsigned int i;
+
+  *bitmap = 0ULL;
+
+  for (i = 0; i < dev->evtbuff->ninst; i++)
+    {
+      ret = &dev->evtbuff->inst[i];
+
+      if (ret->altcid == cid)
+        {
+          *bitmap = 1ULL << i;
+          return ret;
+        }
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: cid_to_searchable
+ ****************************************************************************/
+
+static uint16_t cid_to_searchable(uint16_t cid, uint8_t altver)
+{
+  uint16_t cidv1;
+
+  cid &= ~ALTCOM_CMDID_REPLY_BIT;
+  if (altver == ALTCOM_VER4)
+    {
+      /* Change the command ID to Version 1
+       * Even if it cannot be converted, try to search the table
+       * using the original command ID.
+       */
+
+      cidv1 = convert_cid2v1(cid);
+      if (cidv1 != APICMDID_UNKNOWN)
+        {
+          cid = cidv1;
+        }
+    }
+
+  return cid;
+}
+
+/****************************************************************************
+ * Name: get_bitmap
+ ****************************************************************************/
+
+static uint64_t get_bitmap(FAR struct alt1250_dev_s *dev, uint16_t cid,
+  uint8_t altver)
+{
+  uint64_t bitmap = 0ULL;
+
+  cid = cid_to_searchable(cid, altver);
+
+  search_evtbufinst(cid, &bitmap, dev);
+
+  return bitmap;
+}
+
+/****************************************************************************
+ * Name: get_evtbuffinst_withlock
+ ****************************************************************************/
+
+static FAR alt_evtbuf_inst_t *get_evtbuffinst_withlock(
+  FAR struct alt1250_dev_s *dev, uint16_t cid, uint8_t altver,
+  FAR uint64_t *bitmap)
+{
+  FAR alt_evtbuf_inst_t *inst = NULL;
+  FAR alt_evtbuf_inst_t *ret = NULL;
+
+  cid = cid_to_searchable(cid, altver);
+
+  if (cid == APICMDID_SOCK_SELECT)
+    {
+      ret = &dev->select_inst;
+
+      lock_evtbuffinst(ret, dev);
+
+      ret->outparam = dev->select_container->outparam;
+      ret->outparamlen = dev->select_container->outparamlen;
+
+      search_evtbufinst(cid, bitmap, dev);
+    }
+  else
+    {
+      inst = search_evtbufinst(cid, bitmap, dev);
+      if (inst)
+        {
+          lock_evtbuffinst(inst, dev);
+
+          if (inst->stat == ALTEVTBUF_ST_WRITABLE)
+            {
+              ret = inst;
+            }
+          else
+            {
+              unlock_evtbufinst(inst, dev);
+            }
+        }
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: write_restart_param
+ ****************************************************************************/
+
+static void write_restart_param(FAR void *outp[], FAR void *buff)
+{
+  FAR int *out_reason = (FAR int *)outp[0];
+  FAR int *in_reason = (FAR int *)buff;
+
+  *out_reason = *in_reason;
+}
+
+/****************************************************************************
+ * Name: pollnotify
+ ****************************************************************************/
+
+static void pollnotify(FAR struct alt1250_dev_s *dev)
+{
+  nxsem_wait_uninterruptible(&dev->pfdlock);
+
+  if (dev->pfd)
+    {
+      /* If poll() waits, notify  */
+
+      poll_notify(&dev->pfd, 1, POLLIN);
+    }
+
+  nxsem_post(&dev->pfdlock);
+}
+
+/****************************************************************************
+ * Name: get_composehdlr
+ ****************************************************************************/
+
+compose_handler_t get_composehdlr(uint32_t cmdid, FAR uint8_t *payload,
+  size_t size)
+{
+  compose_handler_t ret = NULL;
+
+  ret = alt1250_composehdlr(cmdid);
+
+#ifdef CONFIG_MODEM_ALT1250_ADDITIONAL_FUNC
+  if (ret == NULL)
+    {
+      ret = alt1250_additional_composehdlr(cmdid, payload, size);
+    }
+#endif
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: get_parsehdlr
+ ****************************************************************************/
+
+parse_handler_t get_parsehdlr(uint16_t altcid, uint8_t altver)
+{
+  parse_handler_t ret = NULL;

Review Comment:
   ```suggestion
     parse_handler_t ret;
   ```



##########
drivers/modem/alt1250/altcom_cmd_log.h:
##########
@@ -0,0 +1,123 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_cmd_log.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_CMD_LOG_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_CMD_LOG_H__
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/compiler.h>
+#include <nuttx/modem/alt1250.h>
+#include <nuttx/wireless/lte/lte.h>
+
+#include <stdbool.h>
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ALTCOM_LOGSPATH "logs/"
+#define ALTCOM_PATH_LEN_MAX (LTE_LOG_NAME_LEN + 5)
+#define ALTCOM_LIST_LEN_MAX (LTE_LOG_LIST_SIZE * ALTCOM_PATH_LEN_MAX)
+#define ALTCOM_LOG_ACCESS_PATH_LEN_MAX (256)
+#define ALTCOM_LOG_READ_LEN_MAX (2000)
+#define ALTCOM_LOG_OPEN_FLAGS (0x1)
+#define ALTCOM_LOG_SEEK_SET (0)
+#define ALTCOM_LOG_SEEK_CUR (1)
+#define ALTCOM_LOG_SEEK_END (2)
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+begin_packed_struct struct apicmd_cmddat_clogs_s
+{
+  uint8_t pathlen;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_cmddat_clogsres_s
+{
+  int32_t altcom_result;
+  uint8_t pathlen;
+  char path[ALTCOM_PATH_LEN_MAX];
+} end_packed_struct;
+
+begin_packed_struct struct apicmddbg_getloglist_s
+{
+  uint8_t listsize;
+  uint8_t pathlen;
+} end_packed_struct;
+
+begin_packed_struct struct apicmddbg_getloglistres_s
+{
+  int32_t altcom_result;
+  uint8_t listsize;
+  uint8_t pathlen;
+  char list[ALTCOM_LIST_LEN_MAX];
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_logopen_s
+{
+  char path[ALTCOM_LOG_ACCESS_PATH_LEN_MAX];
+  int32_t flags;
+  int32_t mode;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_logcommonres_s
+{
+  int32_t altcom_result;
+  int32_t unused;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_logclose_s
+{
+  int32_t fd;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_logread_s
+{
+  int32_t fd;
+  int32_t readlen;
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_logreadres_s
+{
+  int32_t altcom_result;
+  int32_t unused;
+  char readdata[ALTCOM_LOG_READ_LEN_MAX];
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_logremove_s
+{
+  char path[ALTCOM_LOG_ACCESS_PATH_LEN_MAX];
+} end_packed_struct;
+
+begin_packed_struct struct apicmd_loglseek_s
+{
+  int32_t fd;
+  int32_t offset;
+  int32_t whence;
+} end_packed_struct;
+
+#endif  /* __DRIVERS_MODEM_ALT1250_ALTCOM_CMD_LOG_H__ */

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



##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int alt1250_poll(FAR struct file *filep, struct pollfd *fds,
+  bool setup);
+
+parse_handler_t alt1250_additional_parsehdlr(uint16_t, uint8_t);
+compose_handler_t alt1250_additional_composehdlr(uint32_t,
+    FAR uint8_t *, size_t);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* This the vtable that supports the character driver interface. */
+
+static const struct file_operations g_alt1250fops =
+{
+  alt1250_open,  /* open */
+  alt1250_close, /* close */
+  alt1250_read,  /* read */
+  0,             /* write */
+  0,             /* seek */
+  alt1250_ioctl, /* ioctl */
+  alt1250_poll,  /* poll */
+};
+static uint8_t g_recvbuff[ALTCOM_RX_PKT_SIZE_MAX];
+static uint8_t g_sendbuff[ALTCOM_PKT_SIZE_MAX];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: add_list
+ ****************************************************************************/
+
+static void add_list(FAR struct alt_queue_s *head,
+  FAR struct alt_container_s *list)
+{
+  FAR struct alt_container_s *next;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  while (list != NULL)
+    {
+      next = (FAR struct alt_container_s *)sq_next(&list->node);
+
+      sq_next(&list->node) = NULL;
+      sq_addlast(&list->node, &head->queue);
+
+      list = next;
+    }
+
+  nxsem_post(&head->lock);
+}
+
+/****************************************************************************
+ * Name: remove_list_all
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list_all(
+  FAR struct alt_queue_s *head)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  sq_init(&head->queue);
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: remove_list
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list(FAR struct alt_queue_s *head,
+  uint16_t cmdid, uint16_t transid)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  while (list != NULL)
+    {
+      if ((list->altcid == cmdid) && (list->alttid == transid))
+        {
+          sq_rem(&list->node, &head->queue);
+          sq_next(&list->node) = NULL;
+          break;
+        }
+
+      list = (FAR struct alt_container_s *)sq_next(&list->node);
+    }
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: set_senddisable
+ ****************************************************************************/
+
+static void set_senddisable(FAR struct alt1250_dev_s *dev, bool disable)
+{
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  dev->senddisable = disable;
+
+  nxsem_post(&dev->senddisablelock);
+}
+
+/****************************************************************************
+ * Name: is_senddisable
+ ****************************************************************************/
+
+static bool is_senddisable(FAR struct alt1250_dev_s *dev)
+{
+  bool disable;
+
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  disable = dev->senddisable;
+
+  nxsem_post(&dev->senddisablelock);
+
+  return disable;
+}
+
+/****************************************************************************
+ * Name: read_evtbitmap
+ ****************************************************************************/
+
+static ssize_t read_data(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_readdata_s *rdata)
+{
+  int idx;
+
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  /* change status to NOT WRITABLE */
+
+  for (idx = 0; idx < (sizeof(uint64_t) * 8); idx++)
+    {
+      if (dev->evtbitmap & (1ULL << idx))
+        {
+          if (dev->evtbuff->ninst >= idx)
+            {
+              FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx];
+
+              nxsem_wait_uninterruptible(&inst->stat_lock);
+
+              inst->stat = ALTEVTBUF_ST_NOTWRITABLE;
+
+              nxsem_post(&inst->stat_lock);
+            }
+        }
+    }
+
+  rdata->evtbitmap = dev->evtbitmap;
+  rdata->head = remove_list_all(&dev->replylist);
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      /* Resume sending because daemon has been notified of the reset
+       * reliably.
+       */
+
+      set_senddisable(dev, false);
+    }
+
+  dev->evtbitmap = 0ULL;
+
+  nxsem_post(&dev->evtmaplock);
+
+  return sizeof(struct alt_readdata_s);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmap
+ ****************************************************************************/
+
+static void write_evtbitmap(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  m_info("write bitmap: 0x%llx\n", bitmap);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmapwithlist
+ ****************************************************************************/
+
+static void write_evtbitmapwithlist(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap, FAR struct alt_container_s *container)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  add_list(&dev->replylist, container);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: add_evtbuff
+ ****************************************************************************/
+
+static void add_evtbuff(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_evtbuffer_s *buff)
+{
+  dev->evtbuff = buff;
+}
+
+/****************************************************************************
+ * Name: write_evtbuff_byidx
+ ****************************************************************************/
+
+static int write_evtbuff_byidx(FAR struct alt1250_dev_s *dev,
+  uint64_t idx, void(*write_func)(FAR void *outp[], FAR void *inp),
+  FAR void *inp)
+{
+  int ret = WRITE_NG;
+
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  if (dev->evtbuff)
+    {
+      if (dev->evtbuff->ninst >= idx)
+        {
+          FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx];
+
+          nxsem_wait_uninterruptible(&inst->stat_lock);
+          if (inst->stat == ALTEVTBUF_ST_WRITABLE)
+            {
+              write_func(inst->outparam, inp);
+              dev->evtbitmap |= (1ULL << idx);
+              ret = WRITE_OK;
+            }
+
+          nxsem_post(&inst->stat_lock);
+        }
+    }
+
+  nxsem_post(&dev->evtmaplock);
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: lock_evtbuffinst
+ ****************************************************************************/
+
+static void lock_evtbuffinst(FAR alt_evtbuf_inst_t *inst,
+  FAR struct alt1250_dev_s *dev)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+  nxsem_wait_uninterruptible(&inst->stat_lock);
+}
+
+/****************************************************************************
+ * Name: unlock_evtbufinst
+ ****************************************************************************/
+
+static void unlock_evtbufinst(FAR alt_evtbuf_inst_t *inst,
+  FAR struct alt1250_dev_s *dev)
+{
+  nxsem_post(&inst->stat_lock);
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: search_evtbufinst
+ ****************************************************************************/
+
+static FAR alt_evtbuf_inst_t *search_evtbufinst(uint16_t cid,
+  FAR uint64_t *bitmap, FAR struct alt1250_dev_s *dev)
+{
+  FAR alt_evtbuf_inst_t *ret = NULL;
+  unsigned int i;
+
+  *bitmap = 0ULL;
+
+  for (i = 0; i < dev->evtbuff->ninst; i++)
+    {
+      ret = &dev->evtbuff->inst[i];
+
+      if (ret->altcid == cid)
+        {
+          *bitmap = 1ULL << i;
+          return ret;
+        }
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: cid_to_searchable
+ ****************************************************************************/
+
+static uint16_t cid_to_searchable(uint16_t cid, uint8_t altver)
+{
+  uint16_t cidv1;
+
+  cid &= ~ALTCOM_CMDID_REPLY_BIT;
+  if (altver == ALTCOM_VER4)
+    {
+      /* Change the command ID to Version 1
+       * Even if it cannot be converted, try to search the table
+       * using the original command ID.
+       */
+
+      cidv1 = convert_cid2v1(cid);
+      if (cidv1 != APICMDID_UNKNOWN)
+        {
+          cid = cidv1;
+        }
+    }
+
+  return cid;
+}
+
+/****************************************************************************
+ * Name: get_bitmap
+ ****************************************************************************/
+
+static uint64_t get_bitmap(FAR struct alt1250_dev_s *dev, uint16_t cid,
+  uint8_t altver)
+{
+  uint64_t bitmap = 0ULL;
+
+  cid = cid_to_searchable(cid, altver);
+
+  search_evtbufinst(cid, &bitmap, dev);
+
+  return bitmap;
+}
+
+/****************************************************************************
+ * Name: get_evtbuffinst_withlock
+ ****************************************************************************/
+
+static FAR alt_evtbuf_inst_t *get_evtbuffinst_withlock(
+  FAR struct alt1250_dev_s *dev, uint16_t cid, uint8_t altver,
+  FAR uint64_t *bitmap)
+{
+  FAR alt_evtbuf_inst_t *inst = NULL;
+  FAR alt_evtbuf_inst_t *ret = NULL;
+
+  cid = cid_to_searchable(cid, altver);
+
+  if (cid == APICMDID_SOCK_SELECT)
+    {
+      ret = &dev->select_inst;
+
+      lock_evtbuffinst(ret, dev);
+
+      ret->outparam = dev->select_container->outparam;
+      ret->outparamlen = dev->select_container->outparamlen;
+
+      search_evtbufinst(cid, bitmap, dev);
+    }
+  else
+    {
+      inst = search_evtbufinst(cid, bitmap, dev);
+      if (inst)
+        {
+          lock_evtbuffinst(inst, dev);
+
+          if (inst->stat == ALTEVTBUF_ST_WRITABLE)
+            {
+              ret = inst;
+            }
+          else
+            {
+              unlock_evtbufinst(inst, dev);
+            }
+        }
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: write_restart_param
+ ****************************************************************************/
+
+static void write_restart_param(FAR void *outp[], FAR void *buff)
+{
+  FAR int *out_reason = (FAR int *)outp[0];
+  FAR int *in_reason = (FAR int *)buff;
+
+  *out_reason = *in_reason;
+}
+
+/****************************************************************************
+ * Name: pollnotify
+ ****************************************************************************/
+
+static void pollnotify(FAR struct alt1250_dev_s *dev)
+{
+  nxsem_wait_uninterruptible(&dev->pfdlock);
+
+  if (dev->pfd)
+    {
+      /* If poll() waits, notify  */
+
+      poll_notify(&dev->pfd, 1, POLLIN);
+    }
+
+  nxsem_post(&dev->pfdlock);
+}
+
+/****************************************************************************
+ * Name: get_composehdlr
+ ****************************************************************************/
+
+compose_handler_t get_composehdlr(uint32_t cmdid, FAR uint8_t *payload,
+  size_t size)
+{
+  compose_handler_t ret = NULL;
+
+  ret = alt1250_composehdlr(cmdid);
+
+#ifdef CONFIG_MODEM_ALT1250_ADDITIONAL_FUNC
+  if (ret == NULL)
+    {
+      ret = alt1250_additional_composehdlr(cmdid, payload, size);
+    }
+#endif
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: get_parsehdlr
+ ****************************************************************************/
+
+parse_handler_t get_parsehdlr(uint16_t altcid, uint8_t altver)
+{
+  parse_handler_t ret = NULL;
+
+  ret = alt1250_parsehdlr(altcid, altver);
+
+#ifdef CONFIG_MODEM_ALT1250_ADDITIONAL_FUNC
+  if (ret == NULL)
+    {
+      ret = alt1250_additional_parsehdlr(altcid, altver);
+    }
+#endif
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: alt1250_power_control
+ ****************************************************************************/
+
+static int alt1250_power_control(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_power_s *req)

Review Comment:
   ```suggestion
   static int alt1250_power_control(FAR struct alt1250_dev_s *dev,
                                    FAR struct alt_power_s *req)
   ```



##########
drivers/modem/alt1250/alt1250.c:
##########
@@ -0,0 +1,1279 @@
+/****************************************************************************
+ * drivers/modem/alt1250/alt1250.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 <nuttx/kmalloc.h>
+#include <nuttx/fs/fs.h>
+#include <poll.h>
+#include <errno.h>
+#include <nuttx/wireless/lte/lte_ioctl.h>
+#include <nuttx/modem/alt1250.h>
+#include <assert.h>
+
+#include "altcom_pkt.h"
+#include "altcom_hdlr.h"
+#include "altmdm.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define WRITE_OK 0
+#define WRITE_NG 1
+
+#define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev)
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/* Character driver methods. */
+
+static int alt1250_open(FAR struct file *filep);
+static int alt1250_close(FAR struct file *filep);
+static ssize_t alt1250_read(FAR struct file *filep, FAR char *buffer,
+  size_t len);
+static int alt1250_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
+static int alt1250_poll(FAR struct file *filep, struct pollfd *fds,
+  bool setup);
+
+parse_handler_t alt1250_additional_parsehdlr(uint16_t, uint8_t);
+compose_handler_t alt1250_additional_composehdlr(uint32_t,
+    FAR uint8_t *, size_t);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* This the vtable that supports the character driver interface. */
+
+static const struct file_operations g_alt1250fops =
+{
+  alt1250_open,  /* open */
+  alt1250_close, /* close */
+  alt1250_read,  /* read */
+  0,             /* write */
+  0,             /* seek */
+  alt1250_ioctl, /* ioctl */
+  alt1250_poll,  /* poll */
+};
+static uint8_t g_recvbuff[ALTCOM_RX_PKT_SIZE_MAX];
+static uint8_t g_sendbuff[ALTCOM_PKT_SIZE_MAX];
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: add_list
+ ****************************************************************************/
+
+static void add_list(FAR struct alt_queue_s *head,
+  FAR struct alt_container_s *list)
+{
+  FAR struct alt_container_s *next;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  while (list != NULL)
+    {
+      next = (FAR struct alt_container_s *)sq_next(&list->node);
+
+      sq_next(&list->node) = NULL;
+      sq_addlast(&list->node, &head->queue);
+
+      list = next;
+    }
+
+  nxsem_post(&head->lock);
+}
+
+/****************************************************************************
+ * Name: remove_list_all
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list_all(
+  FAR struct alt_queue_s *head)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  sq_init(&head->queue);
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: remove_list
+ ****************************************************************************/
+
+static FAR struct alt_container_s *remove_list(FAR struct alt_queue_s *head,
+  uint16_t cmdid, uint16_t transid)
+{
+  FAR struct alt_container_s *list;
+
+  nxsem_wait_uninterruptible(&head->lock);
+
+  list = (FAR struct alt_container_s *)sq_peek(&head->queue);
+  while (list != NULL)
+    {
+      if ((list->altcid == cmdid) && (list->alttid == transid))
+        {
+          sq_rem(&list->node, &head->queue);
+          sq_next(&list->node) = NULL;
+          break;
+        }
+
+      list = (FAR struct alt_container_s *)sq_next(&list->node);
+    }
+
+  nxsem_post(&head->lock);
+
+  return list;
+}
+
+/****************************************************************************
+ * Name: set_senddisable
+ ****************************************************************************/
+
+static void set_senddisable(FAR struct alt1250_dev_s *dev, bool disable)
+{
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  dev->senddisable = disable;
+
+  nxsem_post(&dev->senddisablelock);
+}
+
+/****************************************************************************
+ * Name: is_senddisable
+ ****************************************************************************/
+
+static bool is_senddisable(FAR struct alt1250_dev_s *dev)
+{
+  bool disable;
+
+  nxsem_wait_uninterruptible(&dev->senddisablelock);
+
+  disable = dev->senddisable;
+
+  nxsem_post(&dev->senddisablelock);
+
+  return disable;
+}
+
+/****************************************************************************
+ * Name: read_evtbitmap
+ ****************************************************************************/
+
+static ssize_t read_data(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_readdata_s *rdata)
+{
+  int idx;
+
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  /* change status to NOT WRITABLE */
+
+  for (idx = 0; idx < (sizeof(uint64_t) * 8); idx++)
+    {
+      if (dev->evtbitmap & (1ULL << idx))
+        {
+          if (dev->evtbuff->ninst >= idx)
+            {
+              FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx];
+
+              nxsem_wait_uninterruptible(&inst->stat_lock);
+
+              inst->stat = ALTEVTBUF_ST_NOTWRITABLE;
+
+              nxsem_post(&inst->stat_lock);
+            }
+        }
+    }
+
+  rdata->evtbitmap = dev->evtbitmap;
+  rdata->head = remove_list_all(&dev->replylist);
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      /* Resume sending because daemon has been notified of the reset
+       * reliably.
+       */
+
+      set_senddisable(dev, false);
+    }
+
+  dev->evtbitmap = 0ULL;
+
+  nxsem_post(&dev->evtmaplock);
+
+  return sizeof(struct alt_readdata_s);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmap
+ ****************************************************************************/
+
+static void write_evtbitmap(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  m_info("write bitmap: 0x%llx\n", bitmap);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: write_evtbitmapwithlist
+ ****************************************************************************/
+
+static void write_evtbitmapwithlist(FAR struct alt1250_dev_s *dev,
+  uint64_t bitmap, FAR struct alt_container_s *container)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  dev->evtbitmap |= bitmap;
+
+  if (dev->evtbitmap & ALT1250_EVTBIT_RESET)
+    {
+      dev->evtbitmap = ALT1250_EVTBIT_RESET;
+    }
+
+  add_list(&dev->replylist, container);
+
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: add_evtbuff
+ ****************************************************************************/
+
+static void add_evtbuff(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_evtbuffer_s *buff)
+{
+  dev->evtbuff = buff;
+}
+
+/****************************************************************************
+ * Name: write_evtbuff_byidx
+ ****************************************************************************/
+
+static int write_evtbuff_byidx(FAR struct alt1250_dev_s *dev,
+  uint64_t idx, void(*write_func)(FAR void *outp[], FAR void *inp),
+  FAR void *inp)
+{
+  int ret = WRITE_NG;
+
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+
+  if (dev->evtbuff)
+    {
+      if (dev->evtbuff->ninst >= idx)
+        {
+          FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx];
+
+          nxsem_wait_uninterruptible(&inst->stat_lock);
+          if (inst->stat == ALTEVTBUF_ST_WRITABLE)
+            {
+              write_func(inst->outparam, inp);
+              dev->evtbitmap |= (1ULL << idx);
+              ret = WRITE_OK;
+            }
+
+          nxsem_post(&inst->stat_lock);
+        }
+    }
+
+  nxsem_post(&dev->evtmaplock);
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: lock_evtbuffinst
+ ****************************************************************************/
+
+static void lock_evtbuffinst(FAR alt_evtbuf_inst_t *inst,
+  FAR struct alt1250_dev_s *dev)
+{
+  nxsem_wait_uninterruptible(&dev->evtmaplock);
+  nxsem_wait_uninterruptible(&inst->stat_lock);
+}
+
+/****************************************************************************
+ * Name: unlock_evtbufinst
+ ****************************************************************************/
+
+static void unlock_evtbufinst(FAR alt_evtbuf_inst_t *inst,
+  FAR struct alt1250_dev_s *dev)
+{
+  nxsem_post(&inst->stat_lock);
+  nxsem_post(&dev->evtmaplock);
+}
+
+/****************************************************************************
+ * Name: search_evtbufinst
+ ****************************************************************************/
+
+static FAR alt_evtbuf_inst_t *search_evtbufinst(uint16_t cid,
+  FAR uint64_t *bitmap, FAR struct alt1250_dev_s *dev)
+{
+  FAR alt_evtbuf_inst_t *ret = NULL;
+  unsigned int i;
+
+  *bitmap = 0ULL;
+
+  for (i = 0; i < dev->evtbuff->ninst; i++)
+    {
+      ret = &dev->evtbuff->inst[i];
+
+      if (ret->altcid == cid)
+        {
+          *bitmap = 1ULL << i;
+          return ret;
+        }
+    }
+
+  return NULL;
+}
+
+/****************************************************************************
+ * Name: cid_to_searchable
+ ****************************************************************************/
+
+static uint16_t cid_to_searchable(uint16_t cid, uint8_t altver)
+{
+  uint16_t cidv1;
+
+  cid &= ~ALTCOM_CMDID_REPLY_BIT;
+  if (altver == ALTCOM_VER4)
+    {
+      /* Change the command ID to Version 1
+       * Even if it cannot be converted, try to search the table
+       * using the original command ID.
+       */
+
+      cidv1 = convert_cid2v1(cid);
+      if (cidv1 != APICMDID_UNKNOWN)
+        {
+          cid = cidv1;
+        }
+    }
+
+  return cid;
+}
+
+/****************************************************************************
+ * Name: get_bitmap
+ ****************************************************************************/
+
+static uint64_t get_bitmap(FAR struct alt1250_dev_s *dev, uint16_t cid,
+  uint8_t altver)
+{
+  uint64_t bitmap = 0ULL;
+
+  cid = cid_to_searchable(cid, altver);
+
+  search_evtbufinst(cid, &bitmap, dev);
+
+  return bitmap;
+}
+
+/****************************************************************************
+ * Name: get_evtbuffinst_withlock
+ ****************************************************************************/
+
+static FAR alt_evtbuf_inst_t *get_evtbuffinst_withlock(
+  FAR struct alt1250_dev_s *dev, uint16_t cid, uint8_t altver,
+  FAR uint64_t *bitmap)
+{
+  FAR alt_evtbuf_inst_t *inst = NULL;
+  FAR alt_evtbuf_inst_t *ret = NULL;
+
+  cid = cid_to_searchable(cid, altver);
+
+  if (cid == APICMDID_SOCK_SELECT)
+    {
+      ret = &dev->select_inst;
+
+      lock_evtbuffinst(ret, dev);
+
+      ret->outparam = dev->select_container->outparam;
+      ret->outparamlen = dev->select_container->outparamlen;
+
+      search_evtbufinst(cid, bitmap, dev);
+    }
+  else
+    {
+      inst = search_evtbufinst(cid, bitmap, dev);
+      if (inst)
+        {
+          lock_evtbuffinst(inst, dev);
+
+          if (inst->stat == ALTEVTBUF_ST_WRITABLE)
+            {
+              ret = inst;
+            }
+          else
+            {
+              unlock_evtbufinst(inst, dev);
+            }
+        }
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: write_restart_param
+ ****************************************************************************/
+
+static void write_restart_param(FAR void *outp[], FAR void *buff)
+{
+  FAR int *out_reason = (FAR int *)outp[0];
+  FAR int *in_reason = (FAR int *)buff;
+
+  *out_reason = *in_reason;
+}
+
+/****************************************************************************
+ * Name: pollnotify
+ ****************************************************************************/
+
+static void pollnotify(FAR struct alt1250_dev_s *dev)
+{
+  nxsem_wait_uninterruptible(&dev->pfdlock);
+
+  if (dev->pfd)
+    {
+      /* If poll() waits, notify  */
+
+      poll_notify(&dev->pfd, 1, POLLIN);
+    }
+
+  nxsem_post(&dev->pfdlock);
+}
+
+/****************************************************************************
+ * Name: get_composehdlr
+ ****************************************************************************/
+
+compose_handler_t get_composehdlr(uint32_t cmdid, FAR uint8_t *payload,
+  size_t size)
+{
+  compose_handler_t ret = NULL;
+
+  ret = alt1250_composehdlr(cmdid);
+
+#ifdef CONFIG_MODEM_ALT1250_ADDITIONAL_FUNC
+  if (ret == NULL)
+    {
+      ret = alt1250_additional_composehdlr(cmdid, payload, size);
+    }
+#endif
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: get_parsehdlr
+ ****************************************************************************/
+
+parse_handler_t get_parsehdlr(uint16_t altcid, uint8_t altver)
+{
+  parse_handler_t ret = NULL;
+
+  ret = alt1250_parsehdlr(altcid, altver);
+
+#ifdef CONFIG_MODEM_ALT1250_ADDITIONAL_FUNC
+  if (ret == NULL)
+    {
+      ret = alt1250_additional_parsehdlr(altcid, altver);
+    }
+#endif
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: alt1250_power_control
+ ****************************************************************************/
+
+static int alt1250_power_control(FAR struct alt1250_dev_s *dev,
+  FAR struct alt_power_s *req)
+{
+  int ret = OK;
+
+  switch (req->cmdid)
+    {
+      case LTE_CMDID_POWERON:
+        ret = altmdm_poweron();
+        break;
+
+      case LTE_CMDID_POWEROFF:
+        ret = altmdm_poweroff();
+        break;
+
+      case LTE_CMDID_TAKEWLOCK:
+        ret = altmdm_take_wlock();
+        break;
+
+      case LTE_CMDID_GIVEWLOCK:
+        ret = altmdm_give_wlock();
+        break;
+
+      default:
+        ret = -EINVAL;
+        break;
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: make_altcomcmd_and_send
+ ****************************************************************************/
+
+static int make_altcomcmd_and_send(FAR struct alt1250_dev_s *dev,
+  FAR alt_container_t *req)
+{
+  int ret = OK;
+  compose_handler_t handler;
+  uint8_t altver;
+  uint16_t cid;
+  uint16_t tid;
+  FAR uint8_t *payload;
+  int remainlen;
+  int pos;
+
+  m_info("send request: command ID=0x%08lx\n", req->cmdid);
+
+  payload = get_payload((FAR struct altcom_cmdhdr_s *)g_sendbuff);
+
+  handler = get_composehdlr(req->cmdid & ~LTE_CMDOPT_ASYNC_BIT, payload,
+    ALTCOM_PAYLOAD_SIZE_MAX);
+  if (handler)
+    {
+      altver = altmdm_get_protoversion();
+      if ((altver == ALTCOM_VERX) || is_senddisable(dev))
+        {
+          ret = -ENETDOWN;
+        }
+      else
+        {
+          ret = handler(req->inparam, req->inparamlen, altver, payload,
+            ALTCOM_PAYLOAD_SIZE_MAX, &cid);
+
+          ret = (ret > ALTCOM_PAYLOAD_SIZE_MAX) ? -ENOSPC : ret;
+
+          if (ret >= 0)
+            {
+              tid = altcom_make_header(
+                (FAR struct altcom_cmdhdr_s *)g_sendbuff,
+                altver, cid, ret);
+
+              req->altcid = cid | ALTCOM_CMDID_REPLY_BIT;
+              req->alttid = tid;
+
+              if (req->outparam != NULL)
+                {
+                  add_list(&dev->waitlist, req);
+                }
+
+              remainlen = get_pktlen(altver, (uint16_t)ret);
+              pos = 0;
+
+              /* If the modem sleeps during the split transmission,
+               * the receive buffer of the modem will be cleared.
+               * Therefore, split packets sent before sleep will be
+               * discarded. To avoid this, do not enter sleep state
+               * until all the packets have been sent.
+               */
+
+              altmdm_take_wlock();
+
+              do
+                {
+                  ret = altmdm_write(&g_sendbuff[pos], remainlen);
+                  if (ret < 0)
+                    {
+                      break;
+                    }
+                  else
+                    {
+                      m_info(
+                        "write success: size=%d, cid=0x%04x tid=0x%04x\n",
+                        ret, cid, tid);
+                      remainlen -= ret;
+                      pos += ret;
+                    }
+                }
+              while (remainlen > 0);
+
+              altmdm_give_wlock();
+
+              if (ret < 0)
+                {
+                  m_err("altmdm_write() failed: %d\n", ret);
+                  ret = -ENETDOWN;
+
+                  /* If the container is not left in the waitlist,
+                   * it has already been processed by the recvthread.
+                   * ENETRESET is returned to the caller to indicate that
+                   * the container has been processed.
+                   */
+
+                  if ((req->outparam != NULL) &&
+                    (remove_list(&dev->waitlist, req->altcid, req->alttid)
+                      == NULL))
+                    {
+                      ret = -ENETRESET;
+                    }
+                }
+              else
+                {
+                  m_info("write success: size=%d, cid=0x%04x tid=0x%04x\n",
+                    ret, cid, tid);
+                  ret = OK;
+                }
+            }
+          else
+            {
+              m_err("handler() failed: %d\n", ret);
+            }
+        }
+    }
+  else
+    {
+      ret = -ENOSYS;
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: exchange_selectcontainer
+ ****************************************************************************/
+
+static int exchange_selectcontainer(FAR struct alt1250_dev_s *dev,
+  FAR alt_container_t **container)
+{
+  FAR alt_container_t *newcontainer;
+
+  if (container == NULL)
+    {
+      return -EINVAL;
+    }
+
+  nxsem_wait_uninterruptible(&dev->select_inst.stat_lock);
+
+  newcontainer = *container;
+  *container = dev->select_container;
+  dev->select_container = newcontainer;
+
+  nxsem_post(&dev->select_inst.stat_lock);
+
+  return OK;
+}
+
+/****************************************************************************
+ * Name: altcom_recvthread
+ ****************************************************************************/
+
+static void altcom_recvthread(FAR void *arg)
+{
+  int ret;
+  FAR struct alt1250_dev_s *dev = (FAR struct alt1250_dev_s *)arg;
+  bool is_running = true;
+  FAR struct alt_container_s *head;
+  FAR struct alt_container_s *container;
+  uint16_t cid;
+  uint16_t tid;
+  uint8_t altver;
+  parse_handler_t handler;
+  uint64_t bitmap = 0ULL;
+  int recvedlen = 0;
+
+  m_info("recv thread start\n");
+
+  altmdm_init(dev->spi, dev->lower);
+
+  while (is_running)
+    {
+      ret = altmdm_read(g_recvbuff + recvedlen,
+                        ALTCOM_RX_PKT_SIZE_MAX - recvedlen);
+
+      /* Normal packet received */
+
+      if (ret >= 0)
+        {
+          m_info("read packet %d bytes\n", ret);
+
+          recvedlen += ret;
+
+          ret = altcom_is_pkt_ok(g_recvbuff, recvedlen);
+          if (ret > 0)
+            {
+              /* Cases in which fragmented packets are received.
+               * Therefore, the receive process is performed again.
+               */
+
+              m_info("This is fragmented packet received. remain len: %d\n",
+                     ret);
+              continue;
+            }
+
+          if (ret < 0)
+            {
+              /* Forced reset of modem due to packet format error detected */
+
+              m_err("[altcom] Forced modem reset due to parse failure\n");
+
+              altmdm_reset();
+            }
+          else
+            {
+              bool is_discard = false;
+
+              /* parse ALTCOM command ID and transaction ID from header */
+
+              cid = parse_cid((FAR struct altcom_cmdhdr_s *)g_recvbuff);
+              tid = parse_tid((FAR struct altcom_cmdhdr_s *)g_recvbuff);
+              altver = get_altver(
+                    (FAR struct altcom_cmdhdr_s *)g_recvbuff);
+
+              m_info("receive cid:0x%04x tid:0x%04x\n", cid, tid);
+
+              /* Is error indication packet?
+               * This packet is a response to a command that is not supported
+               * by the ALT1250. The header of the request packet is included
+               * in the contents of the this packet.
+               */
+
+              if (is_errind(cid))
+                {
+                  /* Get ALTCOM command ID and transaction ID
+                   * from error indication packet
+                   */
+
+                  cid = parse_cid4errind(
+                    (FAR struct altcom_cmdhdr_s *)g_recvbuff);
+                  tid = parse_tid4errind(
+                    (FAR struct altcom_cmdhdr_s *)g_recvbuff);
+
+                  m_info("receive errind cid:0x%04x tid:0x%04x\n", cid, tid);
+
+                  container = remove_list(&dev->waitlist, cid, tid);
+                  if (container)
+                    {
+                      /* It means that requested command not implemented
+                       * by modem
+                       */
+
+                      container->result = -ENOSYS;
+                    }
+                  else
+                    {
+                      /* Discard the event packet */
+
+                      is_discard = true;
+
+                      m_warn("container is not found\n");
+                    }
+                }
+              else
+                {
+                  container = remove_list(&dev->waitlist, cid, tid);
+
+                  handler = get_parsehdlr(cid, altver);
+                  if (handler)
+                    {
+                      FAR uint8_t *payload = get_payload(
+                        (FAR struct altcom_cmdhdr_s *)g_recvbuff);
+
+                      if (container)
+                        {
+                          m_info("handler and container is found\n");
+
+                          bitmap = get_bitmap(dev, cid, altver);
+
+                          /* Perform parse handler */
+
+                          container->result = handler(dev, payload,
+                            get_payload_len(
+                              (FAR struct altcom_cmdhdr_s *)g_recvbuff),
+                            altver, container->outparam,
+                            container->outparamlen, &bitmap);
+                        }
+                      else
+                        {
+                          FAR alt_evtbuf_inst_t *inst;
+
+                          m_warn("container is not found\n");
+
+                          /* If the state of the instance is NotWritable,
+                           * instanse will be returned as NULL.
+                           */
+
+                          inst = get_evtbuffinst_withlock(dev, cid, altver,
+                                                          &bitmap);
+                          if (inst)
+                            {
+                              /* Perform parse handler */
+
+                              ret = handler(dev, payload, get_payload_len(
+                                (FAR struct altcom_cmdhdr_s *)g_recvbuff),
+                                altver, inst->outparam, inst->outparamlen,
+                                &bitmap);
+
+                              unlock_evtbufinst(inst, dev);
+
+                              if (ret >= 0)
+                                {
+                                  write_evtbitmap(dev, bitmap);
+                                }
+                              else
+                                {
+                                  /* Discard the event packet */
+
+                                  is_discard = true;
+                                }
+                            }
+                          else
+                            {
+                              /* Discard the event packet */
+
+                              is_discard = true;
+                            }
+                        }
+                    }
+                  else if (container)
+                    {
+                      container->result = -ENOSYS;
+                      m_warn("handler is not found\n");
+                    }
+                  else
+                    {
+                      /* Discard the event packet */
+
+                      is_discard = true;
+
+                      m_warn("container and handler is not found\n");
+                    }
+                }
+
+              if (container)
+                {
+                  if (container->cmdid & LTE_CMDOPT_ASYNC_BIT)
+                    {
+                      bitmap |= ALT1250_EVTBIT_REPLY;
+                    }
+                  else
+                    {
+                      bitmap = ALT1250_EVTBIT_REPLY;
+                    }
+
+                  write_evtbitmapwithlist(dev, bitmap, container);
+                }
+
+              if (is_discard)
+                {
+                  dev->discardcnt++;
+                  m_err("discard event %lu\n", dev->discardcnt);
+                }
+              else
+                {
+                  pollnotify(dev);
+                }
+            }
+        }
+      else
+        {
+          switch (ret)
+            {
+              case ALTMDM_RETURN_RESET_PKT:
+                {
+                  m_info("recieve ALTMDM_RETURN_RESET_PKT\n");
+                  set_senddisable(dev, true);
+                }
+                break;
+
+              case ALTMDM_RETURN_RESET_V1:
+              case ALTMDM_RETURN_RESET_V4:
+                {
+                  uint32_t reason = altmdm_get_reset_reason();
+
+                  m_info("recieve ALTMDM_RETURN_RESET_V1/V4\n");
+
+                  ret = write_evtbuff_byidx(dev, 0, write_restart_param,
+                    (FAR void *)&reason);
+
+                  /* If there is a waiting list,
+                   * replace it with the replay list.
+                   */
+
+                  head = remove_list_all(&dev->waitlist);
+
+                  write_evtbitmapwithlist(dev, ALT1250_EVTBIT_RESET, head);
+                  pollnotify(dev);
+                }
+                break;
+
+              case ALTMDM_RETURN_EXIT:
+                {
+                  m_info("recieve ALTMDM_RETURN_EXIT\n");
+                  is_running = false;
+                }
+                break;
+
+              default:
+                DEBUGASSERT(0);
+                break;
+            }
+        }
+
+      recvedlen = 0;
+    }
+
+  m_info("recv thread end\n");
+
+  pthread_exit(0);
+}
+
+/****************************************************************************
+ * Name: alt1250_open
+ ****************************************************************************/
+
+static int alt1250_open(FAR struct file *filep)
+{
+  FAR struct inode *inode;
+  FAR struct alt1250_dev_s *dev;
+  int ret = OK;
+
+  /* Get our private data structure */
+
+  DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
+  inode = filep->f_inode;
+
+  dev = (FAR struct alt1250_dev_s *)inode->i_private;
+  DEBUGASSERT(dev);
+
+  nxsem_wait_uninterruptible(&dev->refslock);
+
+  if (dev->crefs > 0)
+    {
+      ret = -EPERM;
+    }
+
+  /* Increment the count of open references on the driver */
+
+  dev->crefs++;
+
+  nxsem_post(&dev->refslock);
+
+  if (ret == OK)
+    {
+      nxsem_init(&dev->waitlist.lock, 0, 1);
+      nxsem_init(&dev->replylist.lock, 0, 1);
+      nxsem_init(&dev->evtmaplock, 0, 1);
+      nxsem_init(&dev->pfdlock, 0, 1);
+      nxsem_init(&dev->senddisablelock, 0, 1);
+      nxsem_init(&dev->select_inst.stat_lock, 0, 1);

Review Comment:
   let's use nxmutex here



##########
drivers/modem/alt1250/altcom_cmd_log.h:
##########
@@ -0,0 +1,123 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_cmd_log.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_CMD_LOG_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_CMD_LOG_H__

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



##########
drivers/modem/alt1250/altcom_cmd_sock.h:
##########
@@ -0,0 +1,509 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_cmd_sock.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_CMD_SOCK_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_CMD_SOCK_H__

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



##########
drivers/modem/alt1250/altcom_cmd_sms.h:
##########
@@ -0,0 +1,212 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_cmd_sms.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_CMD_SMS_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_CMD_SMS_H__

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



##########
drivers/modem/alt1250/altcom_hdlr.h:
##########
@@ -0,0 +1,72 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_hdlr.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_HDLR_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_H__
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/modem/alt1250.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: alt1250_composehdlr
+ *
+ * Description:
+ *   Get the function pointer of the compose handler associated with the
+ *   LAPI command ID.
+ *
+ * Input Parameters:
+ *   cmdid   - ID of the LAPI command.
+ *
+ * Returned Value:
+ *   Returns a function pointer for the compose handler. If there is no
+ *   compose handler associated with the LAPI command ID, NULL is returned.
+ *
+ ****************************************************************************/
+
+compose_handler_t alt1250_composehdlr(uint32_t cmdid);
+
+/****************************************************************************
+ * Name: alt1250_parsehdlr
+ *
+ * Description:
+ *   Get the function pointer of the parse handler associated with the
+ *   ALTCOM command ID.
+ *
+ * Input Parameters:
+ *   altcid   - ID of the ALTCOM command.
+ *   altver   - Version of the ALTCOM command.
+ *
+ * Returned Value:
+ *   Returns a function pointer for the parse handler. If there is no
+ *   parse handler associated with the ALTCOM command ID, NULL is returned.
+ *
+ ****************************************************************************/
+
+parse_handler_t alt1250_parsehdlr(uint16_t altcid, uint8_t altver);
+
+#endif  /* __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_H__ */

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



##########
drivers/modem/alt1250/altcom_hdlr.h:
##########
@@ -0,0 +1,72 @@
+/****************************************************************************
+ * drivers/modem/alt1250/altcom_hdlr.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_HDLR_H__
+#define __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_H__

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



-- 
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-unsubscribe@nuttx.apache.org

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