From 06c8e43df9710aa6409b8a0db5e1ae48d092ba82 Mon Sep 17 00:00:00 2001 From: Alin Jerpelea Date: Tue, 18 Oct 2022 08:55:15 +0200 Subject: [PATCH] drivers: modem: update altair modem update Altair modem with the ALT1250 implementation Signed-off-by: Alin Jerpelea --- .../cxd56xx/spresense/configs/lte/defconfig | 7 +- drivers/modem/Kconfig | 2 +- drivers/modem/Make.defs | 2 +- drivers/modem/alt1250/Kconfig | 33 + drivers/modem/{altair => alt1250}/Make.defs | 19 +- drivers/modem/alt1250/alt1250.c | 1280 ++++ drivers/modem/alt1250/alt1250.h | 59 + drivers/modem/alt1250/altcom_cmd.h | 965 +++ drivers/modem/alt1250/altcom_cmd_log.h | 123 + drivers/modem/alt1250/altcom_cmd_sms.h | 212 + drivers/modem/alt1250/altcom_cmd_sock.h | 509 ++ drivers/modem/alt1250/altcom_hdlr.c | 5926 +++++++++++++++++ drivers/modem/alt1250/altcom_hdlr.h | 72 + drivers/modem/alt1250/altcom_lwm2m_hdlr.c | 412 ++ .../altcom_lwm2m_hdlr.h} | 66 +- drivers/modem/alt1250/altcom_pkt.c | 433 ++ drivers/modem/alt1250/altcom_pkt.h | 414 ++ drivers/modem/alt1250/altmdm.c | 1743 +++++ drivers/modem/alt1250/altmdm.h | 240 + drivers/modem/alt1250/altmdm_event.c | 209 + drivers/modem/alt1250/altmdm_event.h | 156 + drivers/modem/alt1250/altmdm_spi.c | 144 + drivers/modem/alt1250/altmdm_spi.h | 280 + drivers/modem/alt1250/altmdm_timer.c | 153 + drivers/modem/alt1250/altmdm_timer.h | 111 + drivers/modem/altair/Kconfig | 51 - drivers/modem/altair/altmdm.c | 427 -- drivers/modem/altair/altmdm_dev.h | 176 - drivers/modem/altair/altmdm_pm.c | 775 --- drivers/modem/altair/altmdm_pm.h | 212 - drivers/modem/altair/altmdm_pm_state.c | 139 - drivers/modem/altair/altmdm_spi.c | 2337 ------- drivers/modem/altair/altmdm_spi.h | 172 - drivers/modem/altair/altmdm_sys.c | 724 -- drivers/modem/altair/altmdm_sys.h | 260 - include/nuttx/fs/ioctl.h | 6 + include/nuttx/modem/alt1250.h | 394 ++ include/nuttx/modem/altmdm.h | 151 - include/nuttx/net/sms.h | 163 + include/nuttx/wireless/lte/lte.h | 2045 ++++++ include/nuttx/wireless/lte/lte_ioctl.h | 371 ++ 41 files changed, 16502 insertions(+), 5471 deletions(-) create mode 100644 drivers/modem/alt1250/Kconfig rename drivers/modem/{altair => alt1250}/Make.defs (73%) create mode 100644 drivers/modem/alt1250/alt1250.c create mode 100644 drivers/modem/alt1250/alt1250.h create mode 100644 drivers/modem/alt1250/altcom_cmd.h create mode 100644 drivers/modem/alt1250/altcom_cmd_log.h create mode 100644 drivers/modem/alt1250/altcom_cmd_sms.h create mode 100644 drivers/modem/alt1250/altcom_cmd_sock.h create mode 100644 drivers/modem/alt1250/altcom_hdlr.c create mode 100644 drivers/modem/alt1250/altcom_hdlr.h create mode 100644 drivers/modem/alt1250/altcom_lwm2m_hdlr.c rename drivers/modem/{altair/altmdm_pm_state.h => alt1250/altcom_lwm2m_hdlr.h} (61%) create mode 100644 drivers/modem/alt1250/altcom_pkt.c create mode 100644 drivers/modem/alt1250/altcom_pkt.h create mode 100644 drivers/modem/alt1250/altmdm.c create mode 100644 drivers/modem/alt1250/altmdm.h create mode 100644 drivers/modem/alt1250/altmdm_event.c create mode 100644 drivers/modem/alt1250/altmdm_event.h create mode 100644 drivers/modem/alt1250/altmdm_spi.c create mode 100644 drivers/modem/alt1250/altmdm_spi.h create mode 100644 drivers/modem/alt1250/altmdm_timer.c create mode 100644 drivers/modem/alt1250/altmdm_timer.h delete mode 100644 drivers/modem/altair/Kconfig delete mode 100644 drivers/modem/altair/altmdm.c delete mode 100644 drivers/modem/altair/altmdm_dev.h delete mode 100644 drivers/modem/altair/altmdm_pm.c delete mode 100644 drivers/modem/altair/altmdm_pm.h delete mode 100644 drivers/modem/altair/altmdm_pm_state.c delete mode 100644 drivers/modem/altair/altmdm_spi.c delete mode 100644 drivers/modem/altair/altmdm_spi.h delete mode 100644 drivers/modem/altair/altmdm_sys.c delete mode 100644 drivers/modem/altair/altmdm_sys.h create mode 100644 include/nuttx/modem/alt1250.h delete mode 100644 include/nuttx/modem/altmdm.h create mode 100644 include/nuttx/net/sms.h create mode 100644 include/nuttx/wireless/lte/lte.h create mode 100644 include/nuttx/wireless/lte/lte_ioctl.h diff --git a/boards/arm/cxd56xx/spresense/configs/lte/defconfig b/boards/arm/cxd56xx/spresense/configs/lte/defconfig index 3b090c159bb..98a52ced1e4 100644 --- a/boards/arm/cxd56xx/spresense/configs/lte/defconfig +++ b/boards/arm/cxd56xx/spresense/configs/lte/defconfig @@ -10,6 +10,7 @@ # CONFIG_MMCSD_SPI is not set # CONFIG_MTD_SMART_WEAR_LEVEL is not set # CONFIG_STANDARD_SERIAL is not set +CONFIG_ALLOW_MIT_COMPONENTS=y CONFIG_ARCH="arm" CONFIG_ARCH_BOARD="spresense" CONFIG_ARCH_BOARD_COMMON=y @@ -21,6 +22,7 @@ CONFIG_ARMV7M_USEBASEPRI=y CONFIG_BOARD_LOOPSPERMSEC=5434 CONFIG_BOOT_RUNFROMISRAM=y CONFIG_BUILTIN=y +CONFIG_CRYPTO_MBEDTLS=y CONFIG_CXD56_BINARY=y CONFIG_CXD56_I2C0=y CONFIG_CXD56_I2C=y @@ -40,16 +42,19 @@ CONFIG_FS_SMARTFS=y CONFIG_HAVE_CXX=y CONFIG_HAVE_CXXINITIALIZE=y CONFIG_INIT_ENTRYPOINT="spresense_main" +CONFIG_MBEDTLS_APPS=y +CONFIG_MBEDTLS_VERSION="2.28.0" CONFIG_MMCSD=y CONFIG_MMCSD_SDIO=y CONFIG_MODEM=y -CONFIG_MODEM_ALTMDM=y +CONFIG_MODEM_ALT1250=y CONFIG_MTD_BYTE_WRITE=y CONFIG_MTD_PARTITION=y CONFIG_MTD_SMART=y CONFIG_MTD_SMART_ENABLE_CRC=y CONFIG_MTD_SMART_SECTOR_SIZE=4096 CONFIG_NAME_MAX=128 +CONFIG_NET_UDP=y CONFIG_NSH_ARCHINIT=y CONFIG_NSH_BUILTIN_APPS=y CONFIG_NSH_READLINE=y diff --git a/drivers/modem/Kconfig b/drivers/modem/Kconfig index 214080dbd1b..c49b4116177 100644 --- a/drivers/modem/Kconfig +++ b/drivers/modem/Kconfig @@ -27,6 +27,6 @@ config MODEM_U_BLOX_DEBUG ---help--- Allow the u-blox modem driver print debug information. -source "drivers/modem/altair/Kconfig" +source "drivers/modem/alt1250/Kconfig" endif # MODEM diff --git a/drivers/modem/Make.defs b/drivers/modem/Make.defs index 43ce01c85a8..5e2061f235b 100644 --- a/drivers/modem/Make.defs +++ b/drivers/modem/Make.defs @@ -24,7 +24,7 @@ ifeq ($(CONFIG_MODEM_U_BLOX),y) CSRCS += u-blox.c endif -include modem/altair/Make.defs +include modem/alt1250/Make.defs # Include modem driver build support diff --git a/drivers/modem/alt1250/Kconfig b/drivers/modem/alt1250/Kconfig new file mode 100644 index 00000000000..74c89b8868d --- /dev/null +++ b/drivers/modem/alt1250/Kconfig @@ -0,0 +1,33 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +menuconfig MODEM_ALT1250 + bool "ALT1250 modem support" + default n + select SPI + select NET + select NETDEV_MODEM_LTE_IOCTL + ---help--- + Enable driver for the ALT1250 modem. + +if MODEM_ALT1250 + +config MODEM_ALT1250_ADDITIONAL_FUNC + bool + default n + +config MODEM_ALT1250_LOG_ACCESS + bool "Enable modem log access" + default n + ---help--- + Enables the feature to access the modem logs. + +config MODEM_ALT1250_DEBUG + bool "Enable debug mode for ALT1250 modem driver" + default n + ---help--- + Allow the ALT1250 modem driver print debug information. + +endif diff --git a/drivers/modem/altair/Make.defs b/drivers/modem/alt1250/Make.defs similarity index 73% rename from drivers/modem/altair/Make.defs rename to drivers/modem/alt1250/Make.defs index c71b6b24efb..4c0434701fa 100644 --- a/drivers/modem/altair/Make.defs +++ b/drivers/modem/alt1250/Make.defs @@ -1,5 +1,5 @@ ############################################################################ -# drivers/modem/altair/Make.defs +# drivers/modem/alt1250/Make.defs # # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with @@ -20,16 +20,19 @@ ifeq ($(CONFIG_MODEM),y) -ifeq ($(CONFIG_MODEM_ALTMDM),y) +ifeq ($(CONFIG_MODEM_ALT1250),y) +CSRCS += alt1250.c +CSRCS += altcom_pkt.c +CSRCS += altcom_hdlr.c +CSRCS += altcom_lwm2m_hdlr.c CSRCS += altmdm.c +CSRCS += altmdm_event.c CSRCS += altmdm_spi.c -CSRCS += altmdm_pm.c -CSRCS += altmdm_pm_state.c -CSRCS += altmdm_sys.c +CSRCS += altmdm_timer.c endif -DEPPATH += --dep-path modem$(DELIM)altair -VPATH += :modem$(DELIM)altair -CFLAGS += ${shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)modem} +DEPPATH += --dep-path modem$(DELIM)alt1250 +VPATH += :modem$(DELIM)alt1250 +CFLAGS += ${shell $(INCDIR) $(INCDIROPT) "$(CC)" $(TOPDIR)$(DELIM)drivers$(DELIM)modem} endif diff --git a/drivers/modem/alt1250/alt1250.c b/drivers/modem/alt1250/alt1250.c new file mode 100644 index 00000000000..972fea97ff3 --- /dev/null +++ b/drivers/modem/alt1250/alt1250.c @@ -0,0 +1,1280 @@ +/**************************************************************************** + * 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 + +#include +#include +#include +#include +#include +#include +#include + +#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, FAR 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 */ + NULL, /* write */ + NULL, /* 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; + + nxmutex_lock(&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; + } + + nxmutex_unlock(&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; + + nxmutex_lock(&head->lock); + + list = (FAR struct alt_container_s *)sq_peek(&head->queue); + sq_init(&head->queue); + + nxmutex_unlock(&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; + + nxmutex_lock(&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); + } + + nxmutex_unlock(&head->lock); + + return list; +} + +/**************************************************************************** + * Name: set_senddisable + ****************************************************************************/ + +static void set_senddisable(FAR struct alt1250_dev_s *dev, bool disable) +{ + nxmutex_lock(&dev->senddisablelock); + + dev->senddisable = disable; + + nxmutex_unlock(&dev->senddisablelock); +} + +/**************************************************************************** + * Name: is_senddisable + ****************************************************************************/ + +static bool is_senddisable(FAR struct alt1250_dev_s *dev) +{ + bool disable; + + nxmutex_lock(&dev->senddisablelock); + + disable = dev->senddisable; + + nxmutex_unlock(&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; + + nxmutex_lock(&dev->evtmaplock); + + /* change status to NOT WRITABLE */ + + for (idx = 0; idx < (sizeof(uint64_t) * 8); idx++) + { + if ((dev->evtbitmap & (1ULL << idx)) != 0) + { + if (dev->evtbuff->ninst >= idx) + { + FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx]; + + nxmutex_lock(&inst->stat_lock); + + inst->stat = ALTEVTBUF_ST_NOTWRITABLE; + + nxmutex_unlock(&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; + + nxmutex_unlock(&dev->evtmaplock); + + return sizeof(struct alt_readdata_s); +} + +/**************************************************************************** + * Name: write_evtbitmap + ****************************************************************************/ + +static void write_evtbitmap(FAR struct alt1250_dev_s *dev, + uint64_t bitmap) +{ + nxmutex_lock(&dev->evtmaplock); + + dev->evtbitmap |= bitmap; + + if ((dev->evtbitmap & ALT1250_EVTBIT_RESET) != 0) + { + dev->evtbitmap = ALT1250_EVTBIT_RESET; + } + + m_info("write bitmap: 0x%llx\n", bitmap); + + nxmutex_unlock(&dev->evtmaplock); +} + +/**************************************************************************** + * Name: write_evtbitmapwithlist + ****************************************************************************/ + +static void write_evtbitmapwithlist(FAR struct alt1250_dev_s *dev, + uint64_t bitmap, FAR struct alt_container_s *container) +{ + nxmutex_lock(&dev->evtmaplock); + + dev->evtbitmap |= bitmap; + + if (dev->evtbitmap & ALT1250_EVTBIT_RESET) + { + dev->evtbitmap = ALT1250_EVTBIT_RESET; + } + + add_list(&dev->replylist, container); + + nxmutex_unlock(&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, CODE void(*write_func)(FAR void *outp[], FAR void *inp), + FAR void *inp) +{ + int ret = WRITE_NG; + + nxmutex_lock(&dev->evtmaplock); + + if (dev->evtbuff) + { + if (dev->evtbuff->ninst >= idx) + { + FAR alt_evtbuf_inst_t *inst = &dev->evtbuff->inst[idx]; + + nxmutex_lock(&inst->stat_lock); + if (inst->stat == ALTEVTBUF_ST_WRITABLE) + { + write_func(inst->outparam, inp); + dev->evtbitmap |= (1ULL << idx); + ret = WRITE_OK; + } + + nxmutex_unlock(&inst->stat_lock); + } + } + + nxmutex_unlock(&dev->evtmaplock); + + return ret; +} + +/**************************************************************************** + * Name: lock_evtbuffinst + ****************************************************************************/ + +static void lock_evtbuffinst(FAR alt_evtbuf_inst_t *inst, + FAR struct alt1250_dev_s *dev) +{ + nxmutex_lock(&dev->evtmaplock); + nxmutex_lock(&inst->stat_lock); +} + +/**************************************************************************** + * Name: unlock_evtbufinst + ****************************************************************************/ + +static void unlock_evtbufinst(FAR alt_evtbuf_inst_t *inst, + FAR struct alt1250_dev_s *dev) +{ + nxmutex_unlock(&inst->stat_lock); + nxmutex_unlock(&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) +{ + nxmutex_lock(&dev->pfdlock); + + if (dev->pfd != NULL) + { + /* If poll() waits, notify */ + + poll_notify(&dev->pfd, 1, POLLIN); + } + + nxmutex_unlock(&dev->pfdlock); +} + +/**************************************************************************** + * Name: get_composehdlr + ****************************************************************************/ + +compose_handler_t get_composehdlr(uint32_t cmdid, FAR uint8_t *payload, + size_t size) +{ + compose_handler_t ret; + + 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; + + 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; + } + + nxmutex_lock(&dev->select_inst.stat_lock); + + newcontainer = *container; + *container = dev->select_container; + dev->select_container = newcontainer; + + nxmutex_unlock(&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 != NULL) + { + /* 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); + + nxmutex_lock(&dev->refslock); + + if (dev->crefs > 0) + { + ret = -EPERM; + } + + /* Increment the count of open references on the driver */ + + dev->crefs++; + + nxmutex_unlock(&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); + + nxmutex_lock(&dev->refslock); + dev->crefs--; + nxmutex_unlock(&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); + + nxmutex_lock(&dev->refslock); + + if (dev->crefs == 0) + { + ret = -EPERM; + } + else + { + /* Decrement the count of open references on the driver */ + + dev->crefs--; + } + + nxmutex_unlock(&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 priv; +} + +uint64_t get_event_lapibuffer(FAR struct alt1250_dev_s *dev, + uint32_t lapicmdid, + alt_evtbuf_inst_t **inst) +{ + FAR alt_evtbuf_inst_t *evtinst = NULL; + unsigned int i; + uint64_t ret = 0ULL; + + for (i = 0; i < dev->evtbuff->ninst; i++) + { + evtinst = &dev->evtbuff->inst[i]; + + if (evtinst->cmdid == lapicmdid) + { + nxmutex_lock(&evtinst->stat_lock); + + if (evtinst->stat == ALTEVTBUF_ST_WRITABLE) + { + *inst = evtinst; + ret = 1ULL << i; + } + + nxmutex_unlock(&evtinst->stat_lock); + break; + } + } + + return ret; +} diff --git a/drivers/modem/alt1250/alt1250.h b/drivers/modem/alt1250/alt1250.h new file mode 100644 index 00000000000..5f46bf49568 --- /dev/null +++ b/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 +#include + +#include +#include + +/**************************************************************************** + * 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 */ diff --git a/drivers/modem/alt1250/altcom_cmd.h b/drivers/modem/alt1250/altcom_cmd.h new file mode 100644 index 00000000000..3f476b7fde1 --- /dev/null +++ b/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 +#include + +#include +#include + +/**************************************************************************** + * 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 */ diff --git a/drivers/modem/alt1250/altcom_cmd_log.h b/drivers/modem/alt1250/altcom_cmd_log.h new file mode 100644 index 00000000000..337693a57a0 --- /dev/null +++ b/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 +#include +#include +#include + +#include +#include + +/**************************************************************************** + * 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 */ diff --git a/drivers/modem/alt1250/altcom_cmd_sms.h b/drivers/modem/alt1250/altcom_cmd_sms.h new file mode 100644 index 00000000000..6eb19572ad4 --- /dev/null +++ b/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 +#include +#include +#include + +#include +#include + +/**************************************************************************** + * 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 */ diff --git a/drivers/modem/alt1250/altcom_cmd_sock.h b/drivers/modem/alt1250/altcom_cmd_sock.h new file mode 100644 index 00000000000..5f115aacfe7 --- /dev/null +++ b/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 +#include +#include + +#include +#include + +/**************************************************************************** + * 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 */ diff --git a/drivers/modem/alt1250/altcom_hdlr.c b/drivers/modem/alt1250/altcom_hdlr.c new file mode 100644 index 00000000000..10591ac9f8a --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr.c @@ -0,0 +1,5926 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "alt1250.h" +#include "altcom_pkt.h" +#include "altcom_cmd.h" +#include "altcom_cmd_sock.h" +#include "altcom_cmd_sms.h" +#include "altcom_cmd_log.h" +#include "altcom_lwm2m_hdlr.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef ARRAY_SZ +# define ARRAY_SZ(array) (sizeof(array)/sizeof(array[0])) +#endif + +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#define ALTCOM_GETEDRX_TYPE_UE 0 +#define ALTCOM_GETEDRX_TYPE_NEGOTIATED 1 +#define ALTCOM_GETPSM_TYPE_UE 0 +#define ALTCOM_GETPSM_TYPE_NEGOTIATED 1 + +#define ALTCOMBS_EDRX_CYCLE_WBS1_MIN (LTE_EDRX_CYC_512) +#define ALTCOMBS_EDRX_CYCLE_WBS1_MAX (LTE_EDRX_CYC_262144) +#define ALTCOMBS_EDRX_CYCLE_NBS1_MIN (LTE_EDRX_CYC_2048) +#define ALTCOMBS_EDRX_CYCLE_NBS1_MAX (LTE_EDRX_CYC_1048576) +#define ALTCOMBS_EDRX_PTW_WBS1_MIN (0) +#define ALTCOMBS_EDRX_PTW_WBS1_MAX (15) +#define ALTCOMBS_EDRX_PTW_NBS1_MIN (0) +#define ALTCOMBS_EDRX_PTW_NBS1_MAX (15) +#define ALTCOMBS_PSM_UNIT_T3324_MIN (LTE_PSM_T3324_UNIT_2SEC) +#define ALTCOMBS_PSM_UNIT_T3324_MAX (LTE_PSM_T3324_UNIT_6MIN) +#define ALTCOMBS_PSM_UNIT_T3412_MIN (LTE_PSM_T3412_UNIT_2SEC) +#define ALTCOMBS_PSM_UNIT_T3412_MAX (LTE_PSM_T3412_UNIT_320HOUR) +#define ALTCOMBS_BASE_HEX 16 +#define ALTCOMBS_EDRX_INVALID (255) + +#define READSET_BIT (1 << 0) +#define WRITESET_BIT (1 << 1) +#define EXCEPTSET_BIT (1 << 2) + +#define ATCMD_HEADER "AT" +#define ATCMD_HEADER_LEN (2) +#define ATCMD_FOOTER '\r' +#define ATCMD_FOOTER_LEN (1) + +#define ALTCOM_SO_SETMODE_8BIT (1) +#define ALTCOM_SO_SETMODE_32BIT (2) +#define ALTCOM_SO_SETMODE_LINGER (3) +#define ALTCOM_SO_SETMODE_INADDR (4) +#define ALTCOM_SO_SETMODE_IPMREQ (5) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +typedef struct compose_inst_s +{ + uint32_t cmdid; + compose_handler_t hdlr; +} compose_inst_t; + +typedef struct parse_inst_s +{ + uint16_t altcid; + parse_handler_t hdlr; +} parse_inst_t; + +static uint16_t g_set_repevt = 0; + +static uint8_t g_edrx_acttype_table[] = +{ + LTE_EDRX_ACTTYPE_NOTUSE, + LTE_EDRX_ACTTYPE_ECGSMIOT, + LTE_EDRX_ACTTYPE_GSM, + LTE_EDRX_ACTTYPE_IU, + LTE_EDRX_ACTTYPE_WBS1, + LTE_EDRX_ACTTYPE_NBS1 +}; + +static const uint8_t g_edrx_cycle_wbs1_table[] = +{ + LTE_EDRX_CYC_512, + LTE_EDRX_CYC_1024, + LTE_EDRX_CYC_2048, + LTE_EDRX_CYC_4096, + LTE_EDRX_CYC_6144, + LTE_EDRX_CYC_8192, + LTE_EDRX_CYC_10240, + LTE_EDRX_CYC_12288, + LTE_EDRX_CYC_14336, + LTE_EDRX_CYC_16384, + LTE_EDRX_CYC_32768, + LTE_EDRX_CYC_65536, + LTE_EDRX_CYC_131072, + LTE_EDRX_CYC_262144, +}; + +static const uint8_t g_edrx_cycle_nbs1_table[] = +{ + ALTCOMBS_EDRX_INVALID, + ALTCOMBS_EDRX_INVALID, + LTE_EDRX_CYC_2048, + LTE_EDRX_CYC_4096, + ALTCOMBS_EDRX_INVALID, + LTE_EDRX_CYC_8192, + ALTCOMBS_EDRX_INVALID, + ALTCOMBS_EDRX_INVALID, + ALTCOMBS_EDRX_INVALID, + LTE_EDRX_CYC_16384, + LTE_EDRX_CYC_32768, + LTE_EDRX_CYC_65536, + LTE_EDRX_CYC_131072, + LTE_EDRX_CYC_262144, + LTE_EDRX_CYC_524288, + LTE_EDRX_CYC_1048576, +}; + +static const uint8_t g_edrx_ptw_wbs1_table[] = +{ + LTE_EDRX_PTW_128, + LTE_EDRX_PTW_256, + LTE_EDRX_PTW_384, + LTE_EDRX_PTW_512, + LTE_EDRX_PTW_640, + LTE_EDRX_PTW_768, + LTE_EDRX_PTW_896, + LTE_EDRX_PTW_1024, + LTE_EDRX_PTW_1152, + LTE_EDRX_PTW_1280, + LTE_EDRX_PTW_1408, + LTE_EDRX_PTW_1536, + LTE_EDRX_PTW_1664, + LTE_EDRX_PTW_1792, + LTE_EDRX_PTW_1920, + LTE_EDRX_PTW_2048, +}; + +static const uint8_t g_edrx_ptw_nbs1_table[] = +{ + LTE_EDRX_PTW_256, + LTE_EDRX_PTW_512, + LTE_EDRX_PTW_768, + LTE_EDRX_PTW_1024, + LTE_EDRX_PTW_1280, + LTE_EDRX_PTW_1536, + LTE_EDRX_PTW_1792, + LTE_EDRX_PTW_2048, + LTE_EDRX_PTW_2304, + LTE_EDRX_PTW_2560, + LTE_EDRX_PTW_2816, + LTE_EDRX_PTW_3072, + LTE_EDRX_PTW_3328, + LTE_EDRX_PTW_3584, + LTE_EDRX_PTW_3840, + LTE_EDRX_PTW_4096, +}; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int32_t getver_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getphone_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getimsi_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getimei_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getpinset_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t setpinlock_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t setpincode_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t enterpin_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getltime_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getoper_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t setrepqual_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t setrepcell_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t setrepevt_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getedrx_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t setedrx_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getpsm_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t setpsm_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getce_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t setce_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t radioon_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t radiooff_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t actpdn_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t deactpdn_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getnetinfo_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getimscap_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t setrepnet_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getsiminfo_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getdedrx_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getdpsm_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getqual_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t actpdncancel_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getcell_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getrat_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t setrat_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t socket_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t close_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t accept_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t bind_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t connect_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t fcntl_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getsockname_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getsockopt_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t listen_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t recvfrom_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t sendto_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t setsockopt_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t select_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t sendatcmd_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t injectimage_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getimagelen_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t execupdate_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t getupdateres_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t smsinit_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t smsfin_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t smssend_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t smsdelete_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t smsreportrecv_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t logsave_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t loglist_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +#ifdef CONFIG_MODEM_ALT1250_LOG_ACCESS +static int32_t logopen_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t logclose_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t logread_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t loglseek_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +static int32_t logremove_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid); +#endif /* CONFIG_MODEM_ALT1250_LOG_ACCESS */ + +static int32_t errinfo_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getver_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getphone_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getimsi_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getimei_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getpinset_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t setpinlock_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t setpincode_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t enterpin_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getltime_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getoper_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t setrepqual_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t setrepcell_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t setrepevt_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t repevt_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t repqual_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t repcell_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getedrx_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t setedrx_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getpsm_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t setpsm_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getce_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t setce_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t radioon_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t radiooff_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t actpdn_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t deactpdn_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getnetinfo_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getimscap_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t setrepnet_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t repnet_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getsiminfo_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getdedrx_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getdpsm_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getqual_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t actpdncancel_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getcell_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getrat_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t setrat_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t sockcomm_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t scokaddr_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t getsockopt_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t recvfrom_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t select_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t sendatcmd_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t fwcommon_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t smscommon_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t smssend_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t smsreportrecv_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t urc_event_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t logsave_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t loglist_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +#ifdef CONFIG_MODEM_ALT1250_LOG_ACCESS +static int32_t logcommon_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +static int32_t logread_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); +#endif /* CONFIG_MODEM_ALT1250_LOG_ACCESS */ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#define CTABLE_CONTENT(cmdid, hdlrname) \ + { LTE_CMDID_##cmdid, hdlrname##_pkt_compose } +#define PTABLE_CONTENT(altcid, hdlrname) \ + { APICMDID_##altcid, hdlrname##_pkt_parse } + +static compose_inst_t g_composehdlrs[] = +{ + CTABLE_CONTENT(GETVER, getver), + CTABLE_CONTENT(GETPHONE, getphone), + CTABLE_CONTENT(GETIMSI, getimsi), + CTABLE_CONTENT(GETIMEI, getimei), + CTABLE_CONTENT(GETPINSET, getpinset), + CTABLE_CONTENT(PINENABLE, setpinlock), + CTABLE_CONTENT(CHANGEPIN, setpincode), + CTABLE_CONTENT(ENTERPIN, enterpin), + CTABLE_CONTENT(GETLTIME, getltime), + CTABLE_CONTENT(GETOPER, getoper), + CTABLE_CONTENT(REPQUAL, setrepqual), + CTABLE_CONTENT(REPCELL, setrepcell), + CTABLE_CONTENT(REPSIMSTAT, setrepevt), + CTABLE_CONTENT(REPLTIME, setrepevt), + CTABLE_CONTENT(GETEDRX, getedrx), + CTABLE_CONTENT(SETEDRX, setedrx), + CTABLE_CONTENT(GETPSM, getpsm), + CTABLE_CONTENT(SETPSM, setpsm), + CTABLE_CONTENT(GETCE, getce), + CTABLE_CONTENT(SETCE, setce), + CTABLE_CONTENT(RADIOON, radioon), + CTABLE_CONTENT(RADIOOFF, radiooff), + CTABLE_CONTENT(ACTPDN, actpdn), + CTABLE_CONTENT(DEACTPDN, deactpdn), + CTABLE_CONTENT(GETNETINFO, getnetinfo), + CTABLE_CONTENT(IMSCAP, getimscap), + CTABLE_CONTENT(REPNETINFO, setrepnet), + CTABLE_CONTENT(GETSIMINFO, getsiminfo), + CTABLE_CONTENT(GETCEDRX, getdedrx), + CTABLE_CONTENT(GETCPSM, getdpsm), + CTABLE_CONTENT(GETQUAL, getqual), + CTABLE_CONTENT(ACTPDNCAN, actpdncancel), + CTABLE_CONTENT(GETCELL, getcell), + CTABLE_CONTENT(GETRAT, getrat), + CTABLE_CONTENT(GETRATINFO, getrat), + CTABLE_CONTENT(SETRAT, setrat), + CTABLE_CONTENT(ACCEPT, accept), + CTABLE_CONTENT(BIND, bind), + CTABLE_CONTENT(CLOSE, close), + CTABLE_CONTENT(CONNECT, connect), + CTABLE_CONTENT(FCNTL, fcntl), + CTABLE_CONTENT(GETSOCKNAME, getsockname), + CTABLE_CONTENT(GETSOCKOPT, getsockopt), + CTABLE_CONTENT(LISTEN, listen), + CTABLE_CONTENT(RECVFROM, recvfrom), + CTABLE_CONTENT(SELECT, select), + CTABLE_CONTENT(SENDTO, sendto), + CTABLE_CONTENT(SOCKET, socket), + CTABLE_CONTENT(SETSOCKOPT, setsockopt), + CTABLE_CONTENT(SENDATCMD, sendatcmd), + CTABLE_CONTENT(INJECTIMAGE, injectimage), + CTABLE_CONTENT(GETIMAGELEN, getimagelen), + CTABLE_CONTENT(EXEUPDATE, execupdate), + CTABLE_CONTENT(GETUPDATERES, getupdateres), + CTABLE_CONTENT(SMS_INIT, smsinit), + CTABLE_CONTENT(SMS_FIN, smsfin), + CTABLE_CONTENT(SMS_SEND, smssend), + CTABLE_CONTENT(SMS_DELETE, smsdelete), + CTABLE_CONTENT(SMS_REPORT_RECV, smsreportrecv), + CTABLE_CONTENT(SAVE_LOG, logsave), + CTABLE_CONTENT(GET_LOGLIST, loglist), +#ifdef CONFIG_MODEM_ALT1250_LOG_ACCESS + CTABLE_CONTENT(LOGOPEN, logopen), + CTABLE_CONTENT(LOGCLOSE, logclose), + CTABLE_CONTENT(LOGREAD, logread), + CTABLE_CONTENT(LOGLSEEK, loglseek), + CTABLE_CONTENT(LOGREMOVE, logremove), +#endif /* CONFIG_MODEM_ALT1250_LOG_ACCESS */ +}; + +static parse_inst_t g_parsehdlrs[] = +{ + PTABLE_CONTENT(ERRINFO, errinfo), + PTABLE_CONTENT(GET_VERSION, getver), + PTABLE_CONTENT(GET_PHONENO, getphone), + PTABLE_CONTENT(GET_IMSI, getimsi), + PTABLE_CONTENT(GET_IMEI, getimei), + PTABLE_CONTENT(GET_PINSET, getpinset), + PTABLE_CONTENT(SET_PIN_LOCK, setpinlock), + PTABLE_CONTENT(SET_PIN_CODE, setpincode), + PTABLE_CONTENT(ENTER_PIN, enterpin), + PTABLE_CONTENT(GET_LTIME, getltime), + PTABLE_CONTENT(GET_OPERATOR, getoper), + PTABLE_CONTENT(SET_REP_QUALITY, setrepqual), + PTABLE_CONTENT(SET_REP_CELLINFO, setrepcell), + PTABLE_CONTENT(SET_REP_EVT, setrepevt), + PTABLE_CONTENT(REPORT_EVT, repevt), + PTABLE_CONTENT(REPORT_QUALITY, repqual), + PTABLE_CONTENT(REPORT_CELLINFO, repcell), + PTABLE_CONTENT(GET_EDRX, getedrx), + PTABLE_CONTENT(SET_EDRX, setedrx), + PTABLE_CONTENT(GET_PSM, getpsm), + PTABLE_CONTENT(SET_PSM, setpsm), + PTABLE_CONTENT(GET_CE, getce), + PTABLE_CONTENT(SET_CE, setce), + PTABLE_CONTENT(RADIO_ON, radioon), + PTABLE_CONTENT(RADIO_OFF, radiooff), + PTABLE_CONTENT(ACTIVATE_PDN, actpdn), + PTABLE_CONTENT(DEACTIVATE_PDN, deactpdn), + PTABLE_CONTENT(GET_NETINFO, getnetinfo), + PTABLE_CONTENT(GET_IMS_CAP, getimscap), + PTABLE_CONTENT(SETREP_NETINFO, setrepnet), + PTABLE_CONTENT(REPORT_NETINFO, repnet), + PTABLE_CONTENT(GET_SIMINFO, getsiminfo), + PTABLE_CONTENT(GET_DYNAMICEDRX, getdedrx), + PTABLE_CONTENT(GET_DYNAMICPSM, getdpsm), + PTABLE_CONTENT(GET_QUALITY, getqual), + PTABLE_CONTENT(ACTIVATE_PDN_CANCEL, actpdncancel), + PTABLE_CONTENT(GET_CELLINFO, getcell), + PTABLE_CONTENT(GET_RAT, getrat), + PTABLE_CONTENT(SET_RAT, setrat), + PTABLE_CONTENT(SOCK_ACCEPT, scokaddr), + PTABLE_CONTENT(SOCK_BIND, sockcomm), + PTABLE_CONTENT(SOCK_CLOSE, sockcomm), + PTABLE_CONTENT(SOCK_CONNECT, sockcomm), + PTABLE_CONTENT(SOCK_FCNTL, sockcomm), + PTABLE_CONTENT(SOCK_GETSOCKNAME, scokaddr), + PTABLE_CONTENT(SOCK_GETSOCKOPT, getsockopt), + PTABLE_CONTENT(SOCK_LISTEN, sockcomm), + PTABLE_CONTENT(SOCK_RECVFROM, recvfrom), + PTABLE_CONTENT(SOCK_SELECT, select), + PTABLE_CONTENT(SOCK_SENDTO, sockcomm), + PTABLE_CONTENT(SOCK_SOCKET, sockcomm), + PTABLE_CONTENT(SOCK_SETSOCKOPT, sockcomm), + PTABLE_CONTENT(SEND_ATCMD, sendatcmd), + PTABLE_CONTENT(FW_INJECTDELTAIMG, fwcommon), + PTABLE_CONTENT(FW_GETDELTAIMGLEN, fwcommon), + PTABLE_CONTENT(FW_EXECDELTAUPDATE, fwcommon), + PTABLE_CONTENT(FW_GETUPDATERESULT, fwcommon), + PTABLE_CONTENT(SMS_INIT, smscommon), + PTABLE_CONTENT(SMS_FIN, smscommon), + PTABLE_CONTENT(SMS_SEND, smssend), + PTABLE_CONTENT(SMS_DELETE, smscommon), + PTABLE_CONTENT(SMS_REPORT_RECV, smsreportrecv), + PTABLE_CONTENT(URC_EVENT, urc_event), + PTABLE_CONTENT(CLOGS, logsave), + PTABLE_CONTENT(LOGLIST, loglist), +#ifdef CONFIG_MODEM_ALT1250_LOG_ACCESS + PTABLE_CONTENT(LOGOPEN, logcommon), + PTABLE_CONTENT(LOGCLOSE, logcommon), + PTABLE_CONTENT(LOGREAD, logread), + PTABLE_CONTENT(LOGLSEEK, logcommon), + PTABLE_CONTENT(LOGREMOVE, logcommon), +#endif /* CONFIG_MODEM_ALT1250_LOG_ACCESS */ +}; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +int32_t altcombs_set_pdninfo(struct apicmd_pdnset_s *cmd_pdn, + lte_pdn_t *lte_pdn) +{ + int32_t i; + + if (!cmd_pdn || !lte_pdn) + { + return -EINVAL; + } + + lte_pdn->session_id = cmd_pdn->session_id; + lte_pdn->active = cmd_pdn->activate; + lte_pdn->apn_type = htonl(cmd_pdn->apntype); + lte_pdn->ipaddr_num = cmd_pdn->ipaddr_num; + for (i = 0; i < lte_pdn->ipaddr_num; i++) + { + lte_pdn->address[i].ip_type = cmd_pdn->ip_address[i].iptype; + strncpy(lte_pdn->address[i].address, + (FAR char *)cmd_pdn->ip_address[i].address, + LTE_IPADDR_MAX_LEN - 1); + } + + lte_pdn->ims_register = cmd_pdn->imsregister == APICMD_PDN_IMS_REG ? + LTE_IMS_REGISTERED : LTE_IMS_NOT_REGISTERED; + lte_pdn->data_allow = cmd_pdn->dataallow == + APICMD_PDN_DATAALLOW_ALLOW ? + LTE_DATA_ALLOW : LTE_DATA_DISALLOW; + lte_pdn->data_roaming_allow = cmd_pdn->dararoamingallow == + APICMD_PDN_DATAROAMALLOW_ALLOW ? + LTE_DATA_ALLOW : LTE_DATA_DISALLOW; + + return 0; +} + +int32_t altcombs_set_pdninfo_v4(FAR struct apicmd_pdnset_v4_s *cmd_pdn, + FAR lte_pdn_t *lte_pdn, FAR uint8_t *ndnsaddrs, + FAR struct sockaddr_storage *dnsaddrs) +{ + int32_t i; + int af; + + if (!cmd_pdn || !lte_pdn) + { + return -EINVAL; + } + + lte_pdn->session_id = cmd_pdn->session_id; + lte_pdn->active = cmd_pdn->activate; + lte_pdn->apn_type = htonl(cmd_pdn->apntype); + lte_pdn->ipaddr_num = cmd_pdn->ipaddr_num; + for (i = 0; i < lte_pdn->ipaddr_num; i++) + { + lte_pdn->address[i].ip_type = cmd_pdn->ip_address[i].iptype; + strncpy(lte_pdn->address[i].address, + (FAR char *)cmd_pdn->ip_address[i].address, + LTE_IPADDR_MAX_LEN - 1); + } + + lte_pdn->ims_register = cmd_pdn->imsregister; + lte_pdn->data_allow = cmd_pdn->dataallow; + lte_pdn->data_roaming_allow = cmd_pdn->dararoamingallow; + + if (ndnsaddrs && dnsaddrs) + { + *ndnsaddrs = (cmd_pdn->dnsaddr_num > APICMD_PDN_DNSCOUNT_MAX) ? + APICMD_PDN_DNSCOUNT_MAX : cmd_pdn->dnsaddr_num; + for (i = 0; (i < APICMD_PDN_DNSCOUNT_MAX) && (i < *ndnsaddrs); i++) + { + af = (cmd_pdn->dns_address[i].iptype == LTE_IPTYPE_V4) ? + AF_INET : AF_INET6; + if (af == AF_INET) + { + FAR struct sockaddr_in *addr = + (FAR struct sockaddr_in *)&dnsaddrs[i]; + + addr->sin_family = AF_INET; + addr->sin_port = 0; + if (1 != inet_pton(af, + (FAR const char *)cmd_pdn->dns_address[i].address, + (FAR void *)&addr->sin_addr)) + { + /* inet_pton() failed, then force break */ + + *ndnsaddrs = i; + break; + } + } + else + { + FAR struct sockaddr_in6 *addr = + (FAR struct sockaddr_in6 *)&dnsaddrs[i]; + + addr->sin6_family = AF_INET6; + addr->sin6_port = 0; + if (1 != inet_pton(af, + (FAR const char *)cmd_pdn->dns_address[i].address, + (FAR void *)&addr->sin6_addr)) + { + /* inet_pton() failed, then force break */ + + *ndnsaddrs = i; + break; + } + } + } + } + + return 0; +} + +int32_t altcombs_convert_api_edrx_value(lte_edrx_setting_t *api_edrx, + struct apicmd_cmddat_setedrx_s *cmd_edrx, uint8_t altver) +{ + int i; + int table_size = 0; + + if (!cmd_edrx || !api_edrx) + { + m_err("null param\n"); + return -EINVAL; + } + + if (api_edrx->enable < LTE_DISABLE || + api_edrx->enable > LTE_ENABLE) + { + m_err("Invalid enable :%d\n", api_edrx->enable); + return -EINVAL; + } + + /* act_type check for version V4 or later */ + + if (altver == ALTCOM_VER1) + { + if (api_edrx->act_type != LTE_EDRX_ACTTYPE_WBS1 && + api_edrx->act_type != LTE_EDRX_ACTTYPE_NOTUSE) + { + m_err("Operation is not allowed[act_type : %d].\n", + api_edrx->act_type); + return -EPERM; + } + } + else if (altver == ALTCOM_VER4) + { + if (api_edrx->act_type != LTE_EDRX_ACTTYPE_WBS1 && + api_edrx->act_type != LTE_EDRX_ACTTYPE_NBS1 && + api_edrx->act_type != LTE_EDRX_ACTTYPE_NOTUSE) + { + m_err("Operation is not allowed[act_type : %d].\n", + api_edrx->act_type); + return -EPERM; + } + } + else + { + return -ENOSYS; + } + + table_size = ARRAY_SZ(g_edrx_acttype_table); + for (i = 0; i < table_size; i++) + { + if (api_edrx->act_type == g_edrx_acttype_table[i]) + { + cmd_edrx->acttype = (uint8_t)i; + break; + } + } + + if (LTE_ENABLE == api_edrx->enable) + { + cmd_edrx->enable = LTE_ENABLE; + + if (APICMD_EDRX_ACTTYPE_WBS1 == cmd_edrx->acttype) + { + table_size = ARRAY_SZ(g_edrx_cycle_wbs1_table); + + for (i = 0; i < table_size; i++) + { + if (api_edrx->edrx_cycle == g_edrx_cycle_wbs1_table[i]) + { + cmd_edrx->edrx_cycle = (uint8_t)i; + break; + } + } + + if (i == table_size) + { + m_err("Invalid cycle :%ld\n", api_edrx->edrx_cycle); + return -EINVAL; + } + + table_size = ARRAY_SZ(g_edrx_ptw_wbs1_table); + + for (i = 0; i < table_size; i++) + { + if (api_edrx->ptw_val == g_edrx_ptw_wbs1_table[i]) + { + cmd_edrx->ptw_val = (uint8_t)i; + break; + } + } + + if (i == table_size) + { + m_err("Invalid PTW :%ld\n", api_edrx->ptw_val); + return -EINVAL; + } + } + else if (APICMD_EDRX_ACTTYPE_NBS1 == cmd_edrx->acttype) + { + table_size = ARRAY_SZ(g_edrx_cycle_nbs1_table); + + for (i = 0; i < table_size; i++) + { + if (api_edrx->edrx_cycle == g_edrx_cycle_nbs1_table[i]) + { + cmd_edrx->edrx_cycle = (uint8_t)i; + break; + } + } + + if (i == table_size) + { + m_err("Invalid cycle :%ld\n", api_edrx->edrx_cycle); + return -EINVAL; + } + + table_size = ARRAY_SZ(g_edrx_ptw_nbs1_table); + + for (i = 0; i < table_size; i++) + { + if (api_edrx->ptw_val == g_edrx_ptw_nbs1_table[i]) + { + cmd_edrx->ptw_val = (uint8_t)i; + break; + } + } + + if (i == table_size) + { + m_err("Invalid PTW :%ld\n", api_edrx->ptw_val); + return -EINVAL; + } + } + } + else + { + cmd_edrx->enable = LTE_DISABLE; + } + + return 0; +} + +static void getnetinfo_parse_response( + FAR struct apicmd_cmddat_getnetinfores_s *resp, + FAR lte_netinfo_t *netinfo, + uint8_t pdn_num) +{ + uint8_t i; + + netinfo->nw_stat = resp->netinfo.nw_stat; + netinfo->nw_err.err_type = resp->netinfo.err_info.err_type; + netinfo->nw_err.reject_cause.category = + resp->netinfo.err_info.reject_cause.category; + netinfo->nw_err.reject_cause.value = + resp->netinfo.err_info.reject_cause.value; + netinfo->pdn_num = resp->netinfo.pdn_count; + + if ((0 < resp->netinfo.pdn_count) && (netinfo->pdn_stat)) + { + for (i = 0; (i < resp->netinfo.pdn_count) && (i < pdn_num); i++) + { + altcombs_set_pdninfo(&resp->netinfo.pdn[i], + &netinfo->pdn_stat[i]); + } + } +} + +static void getnetinfo_parse_response_v4( + FAR struct apicmd_cmddat_getnetinfores_v4_s *resp, + FAR lte_netinfo_t *netinfo, + uint8_t pdn_num) +{ + uint8_t i; + + netinfo->nw_stat = resp->netinfo.nw_stat; + netinfo->nw_err.err_type = resp->netinfo.err_info.err_type; + netinfo->nw_err.reject_cause.category = + resp->netinfo.err_info.reject_cause.category; + netinfo->nw_err.reject_cause.value = + resp->netinfo.err_info.reject_cause.value; + netinfo->pdn_num = resp->netinfo.pdn_count; + + if ((0 < resp->netinfo.pdn_count) && (netinfo->pdn_stat)) + { + for (i = 0; (i < resp->netinfo.pdn_count) && (i < pdn_num); i++) + { + altcombs_set_pdninfo_v4(&resp->netinfo.pdn[i], + &netinfo->pdn_stat[i], NULL, NULL); + } + } +} + +static bool altcombs_check_arrydigitnum(FAR uint8_t number[], uint8_t digit) +{ + uint8_t cnt; + + for (cnt = 0; cnt < digit; cnt++) + { + if (number[cnt] < APICMD_CELLINFO_DIGIT_NUM_MIN || + APICMD_CELLINFO_DIGIT_NUM_MAX < number[cnt]) + { + return false; + } + } + + return true; +} + +static void altcombs_set_cellinfo( + FAR struct apicmd_cmddat_cellinfo_s *cmd_cellinfo, + FAR lte_cellinfo_t *api_cellinfo) +{ + if (cmd_cellinfo->valid == LTE_VALID) + { + if (ntohl(cmd_cellinfo->cell_id) > APICMD_CELLINFO_CELLID_MAX) + { + m_err("cmd_cellinfo->cell_id error:%ld\n", + ntohl(cmd_cellinfo->cell_id)); + api_cellinfo->valid = LTE_INVALID; + } + else if (ntohl(cmd_cellinfo->earfcn) > APICMD_CELLINFO_EARFCN_MAX) + { + m_err("cmd_cellinfo->earfcn error:%ld\n", + ntohl(cmd_cellinfo->earfcn)); + api_cellinfo->valid = LTE_INVALID; + } + else if (!altcombs_check_arrydigitnum(cmd_cellinfo->mcc, + LTE_MCC_DIGIT)) + { + m_err("cmd_cellinfo->mcc error\n"); + api_cellinfo->valid = LTE_INVALID; + } + else if ( + cmd_cellinfo->mnc_digit < APICMD_CELLINFO_MNC_DIGIT_MIN || + cmd_cellinfo->mnc_digit > LTE_MNC_DIGIT_MAX) + { + m_err("cmd_cellinfo->mnc_digit error:%d\n", + cmd_cellinfo->mnc_digit); + api_cellinfo->valid = LTE_INVALID; + } + else if (!altcombs_check_arrydigitnum(cmd_cellinfo->mnc, + cmd_cellinfo->mnc_digit)) + { + m_err("cmd_cellinfo->mnc error\n"); + api_cellinfo->valid = LTE_INVALID; + } + else + { + api_cellinfo->valid = LTE_VALID; + api_cellinfo->phycell_id = ntohl(cmd_cellinfo->cell_id); + api_cellinfo->earfcn = ntohl(cmd_cellinfo->earfcn); + memcpy(api_cellinfo->mcc, cmd_cellinfo->mcc, LTE_MCC_DIGIT); + api_cellinfo->mnc_digit = cmd_cellinfo->mnc_digit; + memcpy(api_cellinfo->mnc, cmd_cellinfo->mnc, + cmd_cellinfo->mnc_digit); + } + } + else + { + api_cellinfo->valid = LTE_INVALID; + } + + api_cellinfo->option = 0; +} + +static void altcombs_set_cellinfo_v4( + FAR struct apicmd_cmddat_cellinfo_v4_s *cmd_cellinfo, + FAR lte_cellinfo_t *api_cellinfo) +{ + int i; + + api_cellinfo->valid = LTE_INVALID; + api_cellinfo->option = 0; + + if (cmd_cellinfo->enability != LTE_INVALID) + { + if (ntohl(cmd_cellinfo->cell_id) > APICMD_CELLINFO_CELLID_MAX) + { + m_err("cmd_cellinfo->cell_id error:%ld\n", + ntohl(cmd_cellinfo->cell_id)); + } + else if (ntohl(cmd_cellinfo->earfcn) > APICMD_CELLINFO_EARFCN_MAX) + { + m_err("cmd_cellinfo->earfcn error:%ld\n", + ntohl(cmd_cellinfo->earfcn)); + } + else if (!altcombs_check_arrydigitnum(cmd_cellinfo->mcc, + LTE_MCC_DIGIT)) + { + m_err("cmd_cellinfo->mcc error\n"); + } + else if ( + cmd_cellinfo->mnc_digit < APICMD_CELLINFO_MNC_DIGIT_MIN || + cmd_cellinfo->mnc_digit > LTE_MNC_DIGIT_MAX) + { + m_err("cmd_cellinfo->mnc_digit error:%d\n", + cmd_cellinfo->mnc_digit); + } + else if (!altcombs_check_arrydigitnum(cmd_cellinfo->mnc, + cmd_cellinfo->mnc_digit)) + { + m_err("cmd_cellinfo->mnc error\n"); + } + else if (strlen((const char *)cmd_cellinfo->cgid) > + APICMD_CELLINFO_GCID_MAX) + { + m_err("cmd_cellinfo->cgid error\n"); + } + else + { + api_cellinfo->valid = LTE_VALID; + api_cellinfo->phycell_id = ntohl(cmd_cellinfo->cell_id); + api_cellinfo->earfcn = ntohl(cmd_cellinfo->earfcn); + memcpy(api_cellinfo->mcc, cmd_cellinfo->mcc, LTE_MCC_DIGIT); + api_cellinfo->mnc_digit = cmd_cellinfo->mnc_digit; + memcpy(api_cellinfo->mnc, cmd_cellinfo->mnc, + cmd_cellinfo->mnc_digit); + + api_cellinfo->option |= LTE_CELLINFO_OPT_GCID; + api_cellinfo->gcid = strtoul((FAR const char *)cmd_cellinfo->cgid, + NULL, ALTCOMBS_BASE_HEX); + + api_cellinfo->option |= LTE_CELLINFO_OPT_AREACODE; + api_cellinfo->area_code = ntohs(cmd_cellinfo->tac); + + if (cmd_cellinfo->enability & APICMD_CELLINFO_VALID_SFN) + { + api_cellinfo->option |= LTE_CELLINFO_OPT_SFN; + api_cellinfo->sfn = ntohs(cmd_cellinfo->sfn); + } + + if (cmd_cellinfo->enability & APICMD_CELLINFO_VALID_RSRP) + { + api_cellinfo->option |= LTE_CELLINFO_OPT_RSRP; + api_cellinfo->rsrp = ntohs(cmd_cellinfo->rsrp); + } + + if (cmd_cellinfo->enability & APICMD_CELLINFO_VALID_RSRQ) + { + api_cellinfo->option |= LTE_CELLINFO_OPT_RSRQ; + api_cellinfo->rsrq = ntohs(cmd_cellinfo->rsrq); + } + + if (cmd_cellinfo->enability & APICMD_CELLINFO_VALID_TIMEDIFFIDX) + { + api_cellinfo->option |= LTE_CELLINFO_OPT_TIMEDIFFIDX; + api_cellinfo->time_diffidx = ntohs(cmd_cellinfo->time_diffidx); + } + + if (cmd_cellinfo->enability & APICMD_CELLINFO_VALID_TA) + { + api_cellinfo->option |= LTE_CELLINFO_OPT_TA; + api_cellinfo->ta = ntohs(cmd_cellinfo->ta); + } + + if (api_cellinfo->nr_neighbor > cmd_cellinfo->neighbor_num) + { + api_cellinfo->nr_neighbor = cmd_cellinfo->neighbor_num; + } + + for (i = 0; i < api_cellinfo->nr_neighbor; i++) + { + api_cellinfo->option |= LTE_CELLINFO_OPT_NEIGHBOR; + api_cellinfo->neighbors[i].option = 0; + api_cellinfo->neighbors[i].phycell_id = + ntohl(cmd_cellinfo->neighbor_cell[i].cell_id); + api_cellinfo->neighbors[i].earfcn = + ntohl(cmd_cellinfo->neighbor_cell[i].earfcn); + if (cmd_cellinfo->neighbor_cell[i].valid & + APICMD_CELLINFO_VALID_SFN) + { + api_cellinfo->neighbors[i].option |= LTE_CELLINFO_OPT_SFN; + api_cellinfo->neighbors[i].sfn = + ntohs(cmd_cellinfo->neighbor_cell[i].sfn); + } + + if (cmd_cellinfo->neighbor_cell[i].valid & + APICMD_CELLINFO_VALID_RSRP) + { + api_cellinfo->neighbors[i].option |= LTE_CELLINFO_OPT_RSRP; + api_cellinfo->neighbors[i].rsrp = + ntohs(cmd_cellinfo->neighbor_cell[i].rsrp); + } + + if (cmd_cellinfo->neighbor_cell[i].valid & + APICMD_CELLINFO_VALID_RSRQ) + { + api_cellinfo->neighbors[i].option |= LTE_CELLINFO_OPT_RSRQ; + api_cellinfo->neighbors[i].rsrq = + ntohs(cmd_cellinfo->neighbor_cell[i].rsrq); + } + } + } + } +} + +static int32_t altcombs_set_quality(FAR lte_quality_t *data, + FAR struct apicmd_cmddat_quality_s *cmd_quality) +{ + data->valid = APICMD_QUALITY_ENABLE == cmd_quality->enability ? + LTE_VALID : LTE_INVALID; + if (data->valid) + { + data->rsrp = ntohs(cmd_quality->rsrp); + data->rsrq = ntohs(cmd_quality->rsrq); + data->sinr = ntohs(cmd_quality->sinr); + data->rssi = ntohs(cmd_quality->rssi); + if (data->rsrp < APICMD_QUALITY_RSRP_MIN || + APICMD_QUALITY_RSRP_MAX < data->rsrp) + { + m_err("data.rsrp error:%d\n", data->rsrp); + data->valid = LTE_INVALID; + } + else if (data->rsrq < APICMD_QUALITY_RSRQ_MIN || + APICMD_QUALITY_RSRQ_MAX < data->rsrq) + { + m_err("data.rsrq error:%d\n", data->rsrq); + data->valid = LTE_INVALID; + } + else if (data->sinr < APICMD_QUALITY_SINR_MIN || + APICMD_QUALITY_SINR_MAX < data->sinr) + { + m_err("data->sinr error:%d\n", data->sinr); + data->valid = LTE_INVALID; + } + else + { + /* Do nothing. */ + } + } + + return 0; +} + +static int32_t altcombs_convert_apicmd_edrx_value( + struct apicmd_edrxset_s *cmd_edrx, lte_edrx_setting_t *api_edrx) +{ + if (!cmd_edrx || !api_edrx) + { + m_err("null param\n"); + return -EINVAL; + } + + if (LTE_DISABLE > cmd_edrx->enable || + LTE_ENABLE < cmd_edrx->enable) + { + m_err("Invalid enable :%d\n", cmd_edrx->enable); + return -EINVAL; + } + + if (LTE_ENABLE == cmd_edrx->enable) + { + if (APICMD_EDRX_ACTTYPE_NOTUSE != cmd_edrx->acttype && + APICMD_EDRX_ACTTYPE_WBS1 != cmd_edrx->acttype && + APICMD_EDRX_ACTTYPE_NBS1 != cmd_edrx->acttype) + { + m_err("Invalid acttype :%d\n", cmd_edrx->acttype); + return -EINVAL; + } + + if (LTE_EDRX_ACTTYPE_WBS1 == cmd_edrx->acttype) + { + if (cmd_edrx->edrx_cycle < ALTCOMBS_EDRX_CYCLE_WBS1_MIN || + cmd_edrx->edrx_cycle > ALTCOMBS_EDRX_CYCLE_WBS1_MAX) + { + m_err("Invalid cycle :%d\n", cmd_edrx->edrx_cycle); + return -EINVAL; + } + + if (ALTCOMBS_EDRX_PTW_WBS1_MIN > cmd_edrx->ptw_val || + ALTCOMBS_EDRX_PTW_WBS1_MAX < cmd_edrx->ptw_val) + { + m_err("Invalid PTW :%d\n", cmd_edrx->ptw_val); + return -EINVAL; + } + } + else if (LTE_EDRX_ACTTYPE_NBS1 == cmd_edrx->acttype) + { + if (cmd_edrx->edrx_cycle < ALTCOMBS_EDRX_CYCLE_NBS1_MIN || + cmd_edrx->edrx_cycle > ALTCOMBS_EDRX_CYCLE_NBS1_MAX) + { + m_err("Invalid cycle :%d\n", cmd_edrx->edrx_cycle); + return -EINVAL; + } + + if (cmd_edrx->ptw_val < ALTCOMBS_EDRX_PTW_NBS1_MIN || + cmd_edrx->ptw_val > ALTCOMBS_EDRX_PTW_NBS1_MAX) + { + m_err("Invalid PTW :%d\n", cmd_edrx->ptw_val); + return -EINVAL; + } + } + + api_edrx->enable = LTE_ENABLE; + api_edrx->act_type = g_edrx_acttype_table[cmd_edrx->acttype]; + if (APICMD_EDRX_ACTTYPE_WBS1 == cmd_edrx->acttype) + { + api_edrx->edrx_cycle = + g_edrx_cycle_wbs1_table[cmd_edrx->edrx_cycle]; + api_edrx->ptw_val = g_edrx_ptw_wbs1_table[cmd_edrx->ptw_val]; + } + else if (APICMD_EDRX_ACTTYPE_NBS1 == cmd_edrx->acttype) + { + api_edrx->edrx_cycle = + g_edrx_cycle_nbs1_table[cmd_edrx->edrx_cycle]; + api_edrx->ptw_val = g_edrx_ptw_nbs1_table[cmd_edrx->ptw_val]; + } + } + else + { + api_edrx->enable = LTE_DISABLE; + } + + return 0; +} + +static int32_t altcombs_set_psm(FAR struct apicmd_cmddat_psm_set_s *cmd_set, + FAR lte_psm_setting_t *api_set) +{ + if (!cmd_set || !api_set) + { + return -EINVAL; + } + + api_set->enable = cmd_set->enable; + api_set->req_active_time.unit = cmd_set->rat_time.unit; + api_set->req_active_time.time_val = cmd_set->rat_time.time_val; + api_set->ext_periodic_tau_time.unit = cmd_set->tau_time.unit; + api_set->ext_periodic_tau_time.time_val = cmd_set->tau_time.time_val; + + return 0; +} + +static void getce_parse_response(FAR struct apicmd_cmddat_getceres_s *resp, + FAR lte_ce_setting_t *ce) +{ + ce->mode_a_enable = resp->mode_a_enable; + ce->mode_b_enable = resp->mode_b_enable; +} + +static void getver_parse_response(FAR struct apicmd_cmddat_getverres_s *resp, + FAR lte_version_t *version) +{ + memset(version, 0, sizeof(*version)); + strncpy(version->bb_product, + (FAR const char *)resp->bb_product, LTE_VER_BB_PRODUCT_LEN - 1); + strncpy(version->np_package, + (FAR const char *)resp->np_package, LTE_VER_NP_PACKAGE_LEN - 1); +} + +static void getpinset_parse_response( + FAR struct apicmd_cmddat_getpinsetres_s *resp, + FAR lte_getpin_t *pinset) +{ + pinset->enable = resp->active; + pinset->status = resp->status; + pinset->pin_attemptsleft = resp->pin_attemptsleft; + pinset->puk_attemptsleft = resp->puk_attemptsleft; + pinset->pin2_attemptsleft = resp->pin2_attemptsleft; + pinset->puk2_attemptsleft = resp->puk2_attemptsleft; +} + +static void getltime_parse_response( + FAR struct apicmd_cmddat_getltimeres_s *resp, + FAR lte_localtime_t *localtime) +{ + localtime->year = resp->ltime.year; + localtime->mon = resp->ltime.month; + localtime->mday = resp->ltime.day; + localtime->hour = resp->ltime.hour; + localtime->min = resp->ltime.minutes; + localtime->sec = resp->ltime.seconds; + localtime->tz_sec = ntohl(resp->ltime.timezone); +} + +static void getsiminfo_parse_response( + FAR struct apicmd_cmddat_getsiminfo_res_s *resp, + FAR lte_siminfo_t *siminfo) +{ + siminfo->option = ntohl(resp->option); + + if (siminfo->option & LTE_SIMINFO_GETOPT_MCCMNC) + { + if (LTE_MNC_DIGIT_MAX < resp->mnc_digit) + { + resp->mnc_digit = LTE_MNC_DIGIT_MAX; + } + + memcpy(siminfo->mcc, resp->mcc, LTE_MCC_DIGIT); + siminfo->mnc_digit = resp->mnc_digit; + memcpy(siminfo->mnc, resp->mnc, resp->mnc_digit); + } + + if (siminfo->option & LTE_SIMINFO_GETOPT_SPN) + { + if (LTE_SIMINFO_SPN_LEN < resp->spn_len) + { + resp->spn_len = LTE_SIMINFO_SPN_LEN; + } + + siminfo->spn_len = resp->spn_len; + memcpy(siminfo->spn, resp->spn, resp->spn_len); + } + + if (siminfo->option & LTE_SIMINFO_GETOPT_ICCID) + { + if (LTE_SIMINFO_ICCID_LEN < resp->iccid_len) + { + resp->iccid_len = LTE_SIMINFO_ICCID_LEN; + } + + siminfo->iccid_len = resp->iccid_len; + memcpy(siminfo->iccid, resp->iccid, resp->iccid_len); + } + + if (siminfo->option & LTE_SIMINFO_GETOPT_IMSI) + { + if (LTE_SIMINFO_IMSI_LEN < resp->imsi_len) + { + resp->imsi_len = LTE_SIMINFO_IMSI_LEN; + } + + siminfo->imsi_len = resp->imsi_len; + memcpy(siminfo->imsi, resp->imsi, resp->imsi_len); + } + + if (siminfo->option & LTE_SIMINFO_GETOPT_GID1) + { + if (LTE_SIMINFO_GID_LEN < resp->gid1_len) + { + resp->gid1_len = LTE_SIMINFO_GID_LEN; + } + + siminfo->gid1_len = resp->gid1_len; + memcpy(siminfo->gid1, resp->gid1, resp->gid1_len); + } + + if (siminfo->option & LTE_SIMINFO_GETOPT_GID2) + { + if (LTE_SIMINFO_GID_LEN < resp->gid2_len) + { + resp->gid2_len = LTE_SIMINFO_GID_LEN; + } + + siminfo->gid2_len = resp->gid2_len; + memcpy(siminfo->gid2, resp->gid2, resp->gid2_len); + } +} + +static void parse_ltime(FAR struct apicmd_cmddat_ltime_s *from, + lte_localtime_t *to) +{ + to->year = from->year; + to->mon = from->month; + to->mday = from->day; + to->hour = from->hour; + to->min = from->minutes; + to->sec = from->seconds; + to->tz_sec = ntohl(from->timezone); +} + +static int parse_simd(FAR struct apicmd_cmddat_repevt_simd_s *simd, + FAR uint32_t *simstat) +{ + int ret = 0; + + switch (simd->status) + { + case APICMD_REPORT_EVT_SIMD_REMOVAL: + { + *simstat = LTE_SIMSTAT_REMOVAL; + } + break; + + case APICMD_REPORT_EVT_SIMD_INSERTION: + { + *simstat = LTE_SIMSTAT_INSERTION; + } + break; + + default: + { + m_err("Unsupport SIMD status. status:%d\n", simd->status); + return -EILSEQ; + } + break; + } + + return ret; +} + +static int parse_simstate( + FAR struct apicmd_cmddat_repevt_simstate_s *simstate, + FAR uint32_t *simstat) +{ + int ret = 0; + + switch (simstate->state) + { + case APICMD_REPORT_EVT_SIMSTATE_SIM_INIT_WAIT_PIN_UNLOCK: + { + *simstat = LTE_SIMSTAT_WAIT_PIN_UNLOCK; + } + break; + + case APICMD_REPORT_EVT_SIMSTATE_PERSONALIZATION_FAILED: + { + *simstat = LTE_SIMSTAT_PERSONAL_FAILED; + } + break; + + case APICMD_REPORT_EVT_SIMSTATE_ACTIVATION_COMPLETED: + { + *simstat = LTE_SIMSTAT_ACTIVATE; + } + break; + + case APICMD_REPORT_EVT_SIMSTATE_DEACTIVATED: + { + *simstat = LTE_SIMSTAT_DEACTIVATE; + } + break; + + default: + { + m_err("Unsupport SIM state. status:%d\n", simstate->state); + ret = -EILSEQ; + } + break; + } + + return ret; +} + +static void sockaddr2altstorage(FAR const struct sockaddr *from, + FAR struct altcom_sockaddr_storage *to) +{ + FAR struct sockaddr_in *inaddr_from; + FAR struct sockaddr_in6 *in6addr_from; + FAR struct altcom_sockaddr_in *inaddr_to; + FAR struct altcom_sockaddr_in6 *in6addr_to; + + if (from->sa_family == AF_INET) + { + inaddr_from = (FAR struct sockaddr_in *)from; + inaddr_to = (FAR struct altcom_sockaddr_in *)to; + + inaddr_to->sin_len = sizeof(struct altcom_sockaddr_in); + inaddr_to->sin_family = ALTCOM_AF_INET; + inaddr_to->sin_port = inaddr_from->sin_port; + memcpy(&inaddr_to->sin_addr, &inaddr_from->sin_addr, + sizeof(struct altcom_in_addr)); + } + else if (from->sa_family == AF_INET6) + { + in6addr_from = (FAR struct sockaddr_in6 *)from; + in6addr_to = (FAR struct altcom_sockaddr_in6 *)to; + + in6addr_to->sin6_len = sizeof(struct altcom_sockaddr_in6); + in6addr_to->sin6_family = ALTCOM_AF_INET6; + in6addr_to->sin6_port = in6addr_from->sin6_port; + memcpy(&in6addr_to->sin6_addr, &in6addr_from->sin6_addr, + sizeof(struct altcom_in6_addr)); + } +} + +static void altstorage2sockaddr( + FAR const struct altcom_sockaddr_storage *from, FAR struct sockaddr *to) +{ + FAR struct altcom_sockaddr_in *inaddr_from; + FAR struct altcom_sockaddr_in6 *in6addr_from; + FAR struct sockaddr_in *inaddr_to; + FAR struct sockaddr_in6 *in6addr_to; + + if (from->ss_family == ALTCOM_AF_INET) + { + inaddr_from = (FAR struct altcom_sockaddr_in *)from; + inaddr_to = (FAR struct sockaddr_in *)to; + + inaddr_to->sin_family = AF_INET; + inaddr_to->sin_port = inaddr_from->sin_port; + memcpy(&inaddr_to->sin_addr, &inaddr_from->sin_addr, + sizeof(struct in_addr)); + + /* LwIP does not use this member, so it should be set to 0 */ + + memset(inaddr_to->sin_zero, 0, sizeof(inaddr_to->sin_zero)); + } + else if (from->ss_family == ALTCOM_AF_INET6) + { + in6addr_from = (FAR struct altcom_sockaddr_in6 *)from; + in6addr_to = (FAR struct sockaddr_in6 *)to; + + in6addr_to->sin6_family = AF_INET6; + in6addr_to->sin6_port = in6addr_from->sin6_port; + memcpy(&in6addr_to->sin6_addr, &in6addr_from->sin6_addr, + sizeof(struct in6_addr)); + + /* LwIP does not use thease members, so it should be set to 0 */ + + in6addr_to->sin6_flowinfo = 0; + in6addr_to->sin6_scope_id = 0; + } +} + +static int flags2altflags(int32_t flags, int32_t *altflags) +{ + if (flags & (MSG_DONTROUTE | MSG_CTRUNC | MSG_PROXY | MSG_TRUNC | + MSG_EOR | MSG_FIN | MSG_SYN | MSG_CONFIRM | + MSG_RST | MSG_ERRQUEUE | MSG_NOSIGNAL)) + { + return -ENOPROTOOPT; + } + + *altflags = 0; + + if (flags & MSG_PEEK) + { + *altflags |= ALTCOM_MSG_PEEK; + } + + if (flags & MSG_WAITALL) + { + *altflags |= ALTCOM_MSG_WAITALL; + } + + if (flags & MSG_OOB) + { + *altflags |= ALTCOM_MSG_OOB; + } + + if (flags & MSG_DONTWAIT) + { + *altflags |= ALTCOM_MSG_DONTWAIT; + } + + if (flags & MSG_MORE) + { + *altflags |= ALTCOM_MSG_MORE; + } + + return 0; +} + +static int get_so_setmode(uint16_t level, uint16_t option) +{ + int setmode = 0; + + switch (level) + { + case SOL_SOCKET: + switch (option) + { + case SO_ACCEPTCONN: + case SO_ERROR: + case SO_BROADCAST: + case SO_KEEPALIVE: + case SO_REUSEADDR: + case SO_TYPE: + case SO_RCVBUF: + setmode = ALTCOM_SO_SETMODE_32BIT; + break; +#ifdef CONFIG_NET_SOLINGER + case SO_LINGER: + setmode = ALTCOM_SO_SETMODE_LINGER; + break; +#endif + default: + m_err("Not support option: %u\n", option); + setmode = -EILSEQ; + break; + } + break; + case IPPROTO_IP: + switch (option) + { + case IP_TOS: + case IP_TTL: + setmode = ALTCOM_SO_SETMODE_32BIT; + break; + case IP_MULTICAST_TTL: + case IP_MULTICAST_LOOP: + setmode = ALTCOM_SO_SETMODE_8BIT; + break; + case IP_MULTICAST_IF: + setmode = ALTCOM_SO_SETMODE_INADDR; + break; + case IP_ADD_MEMBERSHIP: + case IP_DROP_MEMBERSHIP: + setmode = ALTCOM_SO_SETMODE_IPMREQ; + break; + default: + m_err("Not support option: %u\n", option); + setmode = -EILSEQ; + break; + } + break; + case IPPROTO_TCP: + switch (option) + { + case TCP_NODELAY: + case TCP_KEEPIDLE: + case TCP_KEEPINTVL: + setmode = ALTCOM_SO_SETMODE_32BIT; + break; + default: + m_err("Not support option: %u\n", option); + setmode = -EILSEQ; + break; + } + break; + case IPPROTO_IPV6: + switch (option) + { + case IPV6_V6ONLY: + setmode = ALTCOM_SO_SETMODE_32BIT; + break; + default: + m_err("Not support option: %u\n", option); + setmode = -EILSEQ; + break; + } + break; + default: + m_err("Not support level: %u\n", level); + setmode = -EILSEQ; + break; + } + + return setmode; +} + +static int copy_logfilename(FAR char *filename, size_t fnamelen, + FAR char *path) +{ + int ret = OK; + size_t pathlen = strnlen(path, ALTCOM_PATH_LEN_MAX); + + if ((ALTCOM_PATH_LEN_MAX > pathlen) && + (strncmp(path, ALTCOM_LOGSPATH, strlen(ALTCOM_LOGSPATH)) == 0)) + { + path += strlen(ALTCOM_LOGSPATH); + pathlen -= strlen(ALTCOM_LOGSPATH); + + if (pathlen <= fnamelen) + { + strncpy(filename, path, fnamelen); + } + else + { + ret = -ENOBUFS; + } + } + else + { + ret = -EILSEQ; + } + + return ret; +} + +#ifdef CONFIG_MODEM_ALT1250_LOG_ACCESS + +static int create_logpath(FAR char *filename, FAR char *path) +{ + if (strlen(filename) + strlen(ALTCOM_LOGSPATH) >= + ALTCOM_LOG_ACCESS_PATH_LEN_MAX) + { + return -ENAMETOOLONG; + } + + snprintf(path, ALTCOM_LOG_ACCESS_PATH_LEN_MAX, "%s%s", ALTCOM_LOGSPATH, + filename); + + return OK; +} + +#endif /* CONFIG_MODEM_ALT1250_LOG_ACCESS */ + +static int32_t getver_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_VERSION; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_VERSION_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t getphone_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_PHONENO; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_PHONENO_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t getimsi_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_IMSI; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_IMSI_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t getimei_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_IMEI; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_IMEI_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t getpinset_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_PINSET; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_PINSET_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t setpinlock_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR bool *enable = (FAR bool *)arg[0]; + FAR char *pincode = (FAR char *)arg[1]; + + FAR struct apicmd_cmddat_setpinlock_s *out = + (FAR struct apicmd_cmddat_setpinlock_s *)pktbuf; + + out->mode = *enable; + strncpy((FAR char *)out->pincode, pincode, sizeof(out->pincode)); + + size = sizeof(struct apicmd_cmddat_setpinlock_s); + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_SET_PIN_LOCK; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_SET_PIN_LOCK_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t setpincode_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR int8_t *target_pin = (FAR int8_t *)arg[0]; + FAR char *pincode = (FAR char *)arg[1]; + FAR char *new_pincode = (FAR char *)arg[2]; + + FAR struct apicmd_cmddat_setpincode_s *out = + (FAR struct apicmd_cmddat_setpincode_s *)pktbuf; + + if (LTE_TARGET_PIN == *target_pin) + { + out->chgtype = APICMD_SETPINCODE_CHGTYPE_PIN; + } + else + { + out->chgtype = APICMD_SETPINCODE_CHGTYPE_PIN2; + } + + strncpy((FAR char *)out->pincode, pincode, sizeof(out->pincode)); + + strncpy((FAR char *)out->newpincode, new_pincode, sizeof(out->newpincode)); + + size = sizeof(struct apicmd_cmddat_setpincode_s); + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_SET_PIN_CODE; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_SET_PIN_CODE_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t enterpin_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR char *pincode = (FAR char *)arg[0]; + FAR char *new_pincode = (FAR char *)arg[1]; + + FAR struct apicmd_cmddat_enterpin_s *out = + (FAR struct apicmd_cmddat_enterpin_s *)pktbuf; + + strncpy((FAR char *)out->pincode, pincode, sizeof(out->pincode)); + if (new_pincode) + { + out->newpincodeuse = APICMD_ENTERPIN_NEWPINCODE_USE; + strncpy((FAR char *)out->newpincode, + new_pincode, sizeof(out->newpincode)); + } + else + { + out->newpincodeuse = APICMD_ENTERPIN_NEWPINCODE_UNUSE; + } + + size = sizeof(struct apicmd_cmddat_enterpin_s); + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_ENTER_PIN; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_ENTER_PIN_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t getltime_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_LTIME; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_LTIME_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t getoper_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_OPERATOR; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_OPERATOR_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t setrepqual_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR cellinfo_report_cb_t *callback = (FAR cellinfo_report_cb_t *)arg[0]; + FAR uint32_t *period = (FAR uint32_t *)arg[1]; + + FAR struct apicmd_cmddat_setrepquality_s *out = + (FAR struct apicmd_cmddat_setrepquality_s *)pktbuf; + + if (callback == NULL) + { + out->enability = APICMD_SET_REPQUALITY_DISABLE; + } + else + { + out->enability = APICMD_SET_REPQUALITY_ENABLE; + } + + out->interval = htonl(*period); + size = sizeof(struct apicmd_cmddat_setrepquality_s); + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_SET_REP_QUALITY; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_SET_REP_QUALITY_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t setrepcell_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR cellinfo_report_cb_t *callback = (FAR cellinfo_report_cb_t *)arg[0]; + FAR uint32_t *period = (FAR uint32_t *)arg[1]; + + FAR struct apicmd_cmddat_setrepcellinfo_s *out = + (FAR struct apicmd_cmddat_setrepcellinfo_s *)pktbuf; + + if (callback == NULL) + { + out->enability = LTE_DISABLE; + } + else + { + out->enability = LTE_ENABLE; + } + + out->interval = htonl(*period); + size = sizeof(struct apicmd_cmddat_setrepcellinfo_s); + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_SET_REP_CELLINFO; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_SET_REP_CELLINFO_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t setrepevt_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR simstat_report_cb_t *callback = (FAR simstat_report_cb_t *)arg[0]; + FAR int32_t *id = (FAR int32_t *)arg[1]; + + if (altver == ALTCOM_VER1) + { + FAR struct apicmd_cmddat_setrepevt_s *out = + (FAR struct apicmd_cmddat_setrepevt_s *)pktbuf; + + if (*id == LTE_CMDID_REPSIMSTAT) + { + if (callback) + { + g_set_repevt |= + (APICMD_SET_REP_EVT_SIMD | APICMD_SET_REP_EVT_SIMSTATE); + } + else + { + g_set_repevt &= + ~(APICMD_SET_REP_EVT_SIMD | APICMD_SET_REP_EVT_SIMSTATE); + } + } + else if(*id == LTE_CMDID_REPLTIME) + { + if (callback) + { + g_set_repevt |= APICMD_SET_REP_EVT_LTIME; + } + else + { + g_set_repevt &= ~APICMD_SET_REP_EVT_LTIME; + } + } + else + { + size = -ENOSYS; + } + + out->event = g_set_repevt; + size = sizeof(struct apicmd_cmddat_setrepevt_s); + *altcid = APICMDID_SET_REP_EVT; + } + else if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_setrepevt_v4_s *out = + (FAR struct apicmd_cmddat_setrepevt_v4_s *)pktbuf; + + if (*id == LTE_CMDID_REPSIMSTAT) + { + if (callback) + { + g_set_repevt |= + (APICMD_SET_REP_EVT_SIMD | APICMD_SET_REP_EVT_SIMSTATE); + out->enability = APICMD_SET_REP_EVT_ENABLE; + } + else + { + g_set_repevt &= + ~(APICMD_SET_REP_EVT_SIMD | APICMD_SET_REP_EVT_SIMSTATE); + out->enability = APICMD_SET_REP_EVT_DISABLE; + } + } + else if(*id == LTE_CMDID_REPLTIME) + { + if (callback) + { + g_set_repevt |= APICMD_SET_REP_EVT_LTIME; + out->enability = APICMD_SET_REP_EVT_ENABLE; + } + else + { + g_set_repevt &= ~APICMD_SET_REP_EVT_LTIME; + out->enability = APICMD_SET_REP_EVT_DISABLE; + } + } + else + { + size = -ENOSYS; + } + + out->event = htons(g_set_repevt); + size = sizeof(struct apicmd_cmddat_setrepevt_v4_s); + *altcid = APICMDID_SET_REP_EVT_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t getedrx_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + size = 0; + *altcid = APICMDID_GET_EDRX; + } + else if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_getedrx_v4_s *out = + (FAR struct apicmd_cmddat_getedrx_v4_s *)pktbuf; + + out->type = ALTCOM_GETEDRX_TYPE_UE; + size = sizeof(struct apicmd_cmddat_getedrx_v4_s); + *altcid = APICMDID_GET_EDRX_V4; + } + else + { + size = -ENOTSUP; + } + + return size; +} + +static int32_t setedrx_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR lte_edrx_setting_t *settings = (FAR lte_edrx_setting_t *)arg[0]; + int ret = 0; + + FAR struct apicmd_cmddat_setedrx_s *out = + (FAR struct apicmd_cmddat_setedrx_s *)pktbuf; + + size = sizeof(struct apicmd_cmddat_setedrx_s); + ret = altcombs_convert_api_edrx_value(settings, out, altver); + if (ret < 0) + { + size = ret; + } + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_SET_EDRX; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_SET_EDRX_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t getpsm_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + size = 0; + *altcid = APICMDID_GET_PSM; + } + else if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_getpsm_v4_s *out = + (FAR struct apicmd_cmddat_getpsm_v4_s *)pktbuf; + + out->type = ALTCOM_GETPSM_TYPE_UE; + + size = sizeof(struct apicmd_cmddat_getpsm_v4_s); + *altcid = APICMDID_GET_PSM_V4; + } + else + { + size = -ENOTSUP; + } + + return size; +} + +static int32_t setpsm_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR lte_psm_setting_t *settings = (FAR lte_psm_setting_t *)arg[0]; + + FAR struct apicmd_cmddat_setpsm_s *out = + (FAR struct apicmd_cmddat_setpsm_s *)pktbuf; + + out->set.enable = settings->enable; + out->set.rat_time.unit = settings->req_active_time.unit; + out->set.rat_time.time_val = settings->req_active_time.time_val; + out->set.tau_time.unit = settings->ext_periodic_tau_time.unit; + out->set.tau_time.time_val = settings->ext_periodic_tau_time.time_val; + + size = sizeof(struct apicmd_cmddat_setpsm_s); + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_SET_PSM; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_SET_PSM_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t getce_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_CE; + } + else + { + size = -ENOTSUP; + } + + return size; +} + +static int32_t setce_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR lte_ce_setting_t *settings = (FAR lte_ce_setting_t *)arg[0]; + + if (altver == ALTCOM_VER1) + { + FAR struct apicmd_cmddat_setce_s *out = + (FAR struct apicmd_cmddat_setce_s *)pktbuf; + + out->mode_a_enable = (uint8_t)settings->mode_a_enable; + out->mode_b_enable = (uint8_t)settings->mode_b_enable; + + size = sizeof(struct apicmd_cmddat_setce_s); + *altcid = APICMDID_SET_CE; + } + else + { + size = -ENOTSUP; + } + + return size; +} + +static int32_t radioon_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_RADIO_ON; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_RADIO_ON_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t radiooff_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_RADIO_OFF; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_RADIO_OFF_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t actpdn_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR lte_apn_setting_t *apn = (FAR lte_apn_setting_t *)arg[0]; + + FAR struct apicmd_cmddat_activatepdn_s *out = + (FAR struct apicmd_cmddat_activatepdn_s *)pktbuf; + + out->apntype = htonl(apn->apn_type); + if (apn->ip_type == LTE_IPTYPE_NON && altver == ALTCOM_VER1) + { + return -ENOTSUP; + } + + out->iptype = apn->ip_type; + out->authtype = apn->auth_type; + + strncpy((FAR char *)out->apnname, (FAR const char *)apn->apn, + sizeof(out->apnname)); + if (apn->auth_type != LTE_APN_AUTHTYPE_NONE) + { + strncpy((FAR char *)out->username, (FAR const char *)apn->user_name, + sizeof(out->username)); + strncpy((FAR char *)out->password, (FAR const char *)apn->password, + sizeof(out->password)); + } + + size = sizeof(struct apicmd_cmddat_activatepdn_s); + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_ACTIVATE_PDN; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_ACTIVATE_PDN_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t deactpdn_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR uint8_t *session_id = (FAR uint8_t *)arg[0]; + + FAR struct apicmd_cmddat_deactivatepdn_s *out = + (FAR struct apicmd_cmddat_deactivatepdn_s *)pktbuf; + + out->session_id = *session_id; + + size = sizeof(struct apicmd_cmddat_deactivatepdn_s); + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_DEACTIVATE_PDN; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_DEACTIVATE_PDN_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t getnetinfo_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_NETINFO; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_NETINFO_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t getimscap_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_IMS_CAP; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_IMS_CAP_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t setrepnet_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR struct apicmd_cmddat_set_repnetinfo_s *out = + (FAR struct apicmd_cmddat_set_repnetinfo_s *)pktbuf; + + out->report = APICMD_REPNETINFO_REPORT_ENABLE; + + size = sizeof(struct apicmd_cmddat_set_repnetinfo_s); + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_SETREP_NETINFO; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_SETREP_NETINFO_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t getsiminfo_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR uint32_t *option = (FAR uint32_t *)arg[0]; + + FAR struct apicmd_cmddat_getsiminfo_s *out = + (FAR struct apicmd_cmddat_getsiminfo_s *)pktbuf; + + out->option = htonl(*option); + size = sizeof(struct apicmd_cmddat_getsiminfo_s); + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_SIMINFO; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_SIMINFO_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t getdedrx_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + size = 0; + *altcid = APICMDID_GET_DYNAMICEDRX; + } + else if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_getedrx_v4_s *out = + (FAR struct apicmd_cmddat_getedrx_v4_s *)pktbuf; + + out->type = ALTCOM_GETEDRX_TYPE_NEGOTIATED; + size = sizeof(struct apicmd_cmddat_getedrx_v4_s); + *altcid = APICMDID_GET_EDRX_V4; + } + else + { + size = -ENOTSUP; + } + + return size; +} + +static int32_t getdpsm_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + size = 0; + *altcid = APICMDID_GET_DYNAMICPSM; + } + else if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_getpsm_v4_s *out = + (FAR struct apicmd_cmddat_getpsm_v4_s *)pktbuf; + + out->type = ALTCOM_GETPSM_TYPE_NEGOTIATED; + + size = sizeof(struct apicmd_cmddat_getpsm_v4_s); + *altcid = APICMDID_GET_PSM_V4; + } + else + { + size = -ENOTSUP; + } + + return size; +} + +static int32_t getqual_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_QUALITY; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_QUALITY_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t actpdncancel_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_ACTIVATE_PDN_CANCEL; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_ACTIVATE_PDN_CANCEL_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t getcell_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_CELLINFO_V4; + } + else + { + size = -ENOTSUP; + } + + return size; +} + +static int32_t getrat_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_RAT_V4; + } + else + { + size = -ENOTSUP; + } + + return size; +} + +static int32_t setrat_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR uint8_t *rat = (FAR uint8_t *)arg[0]; + FAR bool *persistent = (FAR bool *)arg[1]; + + if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_setrat_s *out = + (FAR struct apicmd_cmddat_setrat_s *)pktbuf; + + out->rat = *rat; + out->persistency = *persistent; + + size = sizeof(struct apicmd_cmddat_setrat_s); + + *altcid = APICMDID_SET_RAT_V4; + } + else + { + size = -ENOTSUP; + } + + return size; +} + +static int32_t sockaddrlen_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz) +{ + int32_t size = 0; + FAR int16_t *usockid = (FAR int16_t *)arg[0]; + FAR int16_t *addrlen = (FAR int16_t *)arg[1]; + + FAR struct altmdmpkt_sockaddrlen_s *out = + (FAR struct altmdmpkt_sockaddrlen_s *)pktbuf; + + out->sockfd = htonl(*usockid); + if (*addrlen == sizeof(struct sockaddr_in)) + { + out->addrlen = htonl(sizeof(struct altcom_sockaddr_in)); + } + else if (*addrlen == sizeof(struct sockaddr_in6)) + { + out->addrlen = htonl(sizeof(struct altcom_sockaddr_in6)); + } + else + { + size = -EINVAL; + } + + if (size == 0) + { + size = sizeof(struct altmdmpkt_sockaddrlen_s); + } + + return size; +} + +static int32_t sockaddr_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz) +{ + int32_t size = 0; + FAR int16_t *usockid = (FAR int16_t *)arg[0]; + FAR int16_t *addrlen = (FAR int16_t *)arg[1]; + FAR struct sockaddr_storage *sa = (FAR struct sockaddr_storage *)arg[2]; + + FAR struct altmdmpkt_sockaddr_s *out = + (FAR struct altmdmpkt_sockaddr_s *)pktbuf; + struct altcom_sockaddr_storage altsa; + + out->sockfd = htonl(*usockid); + if (*addrlen == sizeof(struct sockaddr_in)) + { + out->namelen = htonl(sizeof(struct altcom_sockaddr_in)); + } + else if (*addrlen == sizeof(struct sockaddr_in6)) + { + out->namelen = htonl(sizeof(struct altcom_sockaddr_in6)); + } + else + { + size = -EINVAL; + } + + sockaddr2altstorage((struct sockaddr *)sa, &altsa); + memcpy(&out->name, &altsa, sizeof(struct altcom_sockaddr_storage)); + + if (size == 0) + { + size = sizeof(struct altmdmpkt_sockaddr_s); + } + + return size; +} + +static int32_t socket_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR int16_t *domain = (FAR int16_t *)arg[0]; + FAR int16_t *type = (FAR int16_t *)arg[1]; + FAR int16_t *protocol = (FAR int16_t *)arg[2]; + + FAR struct apicmd_socket_s *out = + (FAR struct apicmd_socket_s *)pktbuf; + + /* convert domain */ + + if (*domain == PF_UNSPEC) + { + out->domain = htonl(ALTCOM_PF_UNSPEC); + } + else if (*domain == PF_INET) + { + out->domain = htonl(ALTCOM_PF_INET); + } + else if (*domain == PF_INET6) + { + out->domain = htonl(ALTCOM_PF_INET6); + } + else + { + size = -EAFNOSUPPORT; + } + + /* convert type */ + + if (*type == SOCK_STREAM) + { + out->type = htonl(ALTCOM_SOCK_STREAM); + } + else if (*type == SOCK_DGRAM) + { + out->type = htonl(ALTCOM_SOCK_DGRAM); + } + else if (*type == SOCK_RAW) + { + out->type = htonl(ALTCOM_SOCK_RAW); + } + else + { + size = -EAFNOSUPPORT; + } + + /* convert protocol */ + + if (*protocol == IPPROTO_IP) + { + out->protocol = htonl(ALTCOM_IPPROTO_IP); + } + else if (*protocol == IPPROTO_ICMP) + { + out->protocol = htonl(ALTCOM_IPPROTO_ICMP); + } + else if (*protocol == IPPROTO_TCP) + { + out->protocol = htonl(ALTCOM_IPPROTO_TCP); + } + else if (*protocol == IPPROTO_UDP) + { + out->protocol = htonl(ALTCOM_IPPROTO_UDP); + } + else if (*protocol == IPPROTO_IPV6) + { + out->protocol = htonl(ALTCOM_IPPROTO_IPV6); + } + else if (*protocol == IPPROTO_ICMP6) + { + out->protocol = htonl(ALTCOM_IPPROTO_ICMPV6); + } + else if (*protocol == IPPROTO_UDPLITE) + { + out->protocol = htonl(ALTCOM_IPPROTO_UDPLITE); + } + else if (*protocol == IPPROTO_RAW) + { + out->protocol = htonl(ALTCOM_IPPROTO_RAW); + } + else + { + size = -EAFNOSUPPORT; + } + + if (size == 0) + { + size = sizeof(struct apicmd_socket_s); + } + + *altcid = APICMDID_SOCK_SOCKET; + + return size; +} + +static int32_t close_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR int16_t *usockid = (FAR int16_t *)arg[0]; + + FAR struct apicmd_close_s *out = + (FAR struct apicmd_close_s *)pktbuf; + + out->sockfd = htonl(*usockid); + + size = sizeof(struct apicmd_close_s); + + *altcid = APICMDID_SOCK_CLOSE; + + return size; +} + +static int32_t accept_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + size = sockaddrlen_pkt_compose(arg, arglen, altver, pktbuf, pktsz); + + *altcid = APICMDID_SOCK_ACCEPT; + + return size; +} + +static int32_t bind_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + size = sockaddr_pkt_compose(arg, arglen, altver, pktbuf, pktsz); + + *altcid = APICMDID_SOCK_BIND; + + return size; +} + +static int32_t connect_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + size = sockaddr_pkt_compose(arg, arglen, altver, pktbuf, pktsz); + + *altcid = APICMDID_SOCK_CONNECT; + + return size; +} + +static int32_t fcntl_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR int32_t *sockfd = (FAR int32_t *)arg[0]; + FAR int32_t *cmd = (FAR int32_t *)arg[1]; + FAR int32_t *val = (FAR int32_t *)arg[2]; + + FAR struct apicmd_fcntl_s *out = + (FAR struct apicmd_fcntl_s *)pktbuf; + + out->sockfd = htonl(*sockfd); + out->cmd = htonl(*cmd); + out->val = htonl(*val); + + if (size == 0) + { + size = sizeof(struct apicmd_fcntl_s); + } + + *altcid = APICMDID_SOCK_FCNTL; + + return size; +} + +static int32_t getsockname_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + size = sockaddrlen_pkt_compose(arg, arglen, altver, pktbuf, pktsz); + + *altcid = APICMDID_SOCK_GETSOCKNAME; + + return size; +} + +static int32_t getsockopt_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR int32_t *sockfd = (FAR int32_t *)arg[0]; + FAR int16_t *level = (FAR int16_t *)arg[1]; + FAR int16_t *option = (FAR int16_t *)arg[2]; + FAR uint16_t *max_valuelen = (FAR uint16_t *)arg[3]; + + FAR struct apicmd_getsockopt_s *out = + (FAR struct apicmd_getsockopt_s *)pktbuf; + + out->sockfd = htonl(*sockfd); + if (*level == SOL_SOCKET) + { + out->level = htonl(ALTCOM_SOL_SOCKET); + out->optlen = htonl(*max_valuelen); + + if (*option == SO_ACCEPTCONN) + { + out->optname = htonl(ALTCOM_SO_ACCEPTCONN); + } + else if (*option == SO_ERROR) + { + out->optname = htonl(ALTCOM_SO_ERROR); + } + else if (*option == SO_BROADCAST) + { + out->optname = htonl(ALTCOM_SO_BROADCAST); + } + else if (*option == SO_KEEPALIVE) + { + out->optname = htonl(ALTCOM_SO_KEEPALIVE); + } + else if (*option == SO_REUSEADDR) + { + out->optname = htonl(ALTCOM_SO_REUSEADDR); + } + else if (*option == SO_TYPE) + { + out->optname = htonl(ALTCOM_SO_TYPE); + } + else if (*option == SO_RCVBUF) + { + out->optname = htonl(ALTCOM_SO_RCVBUF); + } +#ifdef CONFIG_NET_SOLINGER + else if (*option == SO_LINGER) + { + out->optname = htonl(ALTCOM_SO_LINGER); + } +#endif + else + { + size = -ENOPROTOOPT; + } + } + else if (*level == IPPROTO_IP) + { + out->level = htonl(ALTCOM_IPPROTO_IP); + out->optlen = htonl(*max_valuelen); + + if (*option == IP_TOS) + { + out->optname = htonl(ALTCOM_IP_TOS); + } + else if (*option == IP_TTL) + { + out->optname = htonl(ALTCOM_IP_TTL); + } + else if (*option == IP_MULTICAST_TTL) + { + out->optname = htonl(ALTCOM_IP_MULTICAST_TTL); + } + else if (*option == IP_MULTICAST_LOOP) + { + out->optname = htonl(ALTCOM_IP_MULTICAST_LOOP); + } + else if (*option == IP_MULTICAST_IF) + { + out->optname = htonl(ALTCOM_IP_MULTICAST_IF); + } + else + { + size = -ENOPROTOOPT; + } + } + else if (*level == IPPROTO_TCP) + { + out->level = htonl(ALTCOM_IPPROTO_TCP); + out->optlen = htonl(*max_valuelen); + if (*option == TCP_NODELAY) + { + out->optname = htonl(ALTCOM_TCP_NODELAY); + } + else if (*option == TCP_KEEPIDLE) + { + out->optname = htonl(ALTCOM_TCP_KEEPIDLE); + } + else if (*option == TCP_KEEPINTVL) + { + out->optname = htonl(ALTCOM_TCP_KEEPINTVL); + } + else + { + size = -ENOPROTOOPT; + } + } + else if (*level == IPPROTO_IPV6) + { + out->level = htonl(ALTCOM_IPPROTO_IPV6); + out->optlen = htonl(*max_valuelen); + if (*option == IPV6_V6ONLY) + { + out->optname = htonl(ALTCOM_IPV6_V6ONLY); + } + else + { + size = -ENOPROTOOPT; + } + } + else + { + size = -ENOPROTOOPT; + } + + if (size == 0) + { + size = sizeof(struct apicmd_getsockopt_s); + } + + *altcid = APICMDID_SOCK_GETSOCKOPT; + + return size; +} + +static int32_t listen_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR int32_t *sockfd = (FAR int32_t *)arg[0]; + FAR uint16_t *backlog = (FAR uint16_t *)arg[1]; + + FAR struct apicmd_listen_s *out = + (FAR struct apicmd_listen_s *)pktbuf; + + out->sockfd = htonl(*sockfd); + out->backlog = htonl(*backlog); + + size = sizeof(struct apicmd_listen_s); + + *altcid = APICMDID_SOCK_LISTEN; + + return size; +} + +static int32_t recvfrom_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR int32_t *sockfd = (FAR int32_t *)arg[0]; + FAR int32_t *flags = (FAR int32_t *)arg[1]; + FAR uint16_t *max_buflen = (FAR uint16_t *)arg[2]; + FAR uint16_t *max_addrlen = (FAR uint16_t *)arg[3]; + + FAR struct apicmd_recvfrom_s *out = + (FAR struct apicmd_recvfrom_s *)pktbuf; + int32_t flg; + + out->sockfd = htonl(*sockfd); + if (*max_buflen > APICMD_DATA_LENGTH) + { + /* Truncate the length to the maximum transfer size */ + + *max_buflen = APICMD_DATA_LENGTH; + } + + out->recvlen = htonl(*max_buflen); + size = flags2altflags(*flags, &flg); + out->flags = htonl(flg); + if (*max_addrlen == sizeof(struct sockaddr_in)) + { + out->fromlen = htonl(sizeof(struct altcom_sockaddr_in)); + } + else if (*max_addrlen == sizeof(struct sockaddr_in6)) + { + out->fromlen = htonl(sizeof(struct altcom_sockaddr_in6)); + } + else if (*max_addrlen == 0) + { + out->fromlen = htonl(0); + } + else + { + size = -EINVAL; + } + + if (size == 0) + { + size = sizeof(struct apicmd_recvfrom_s); + } + + *altcid = APICMDID_SOCK_RECVFROM; + + return size; +} + +static int32_t sendto_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR int32_t *sockfd = (FAR int32_t *)arg[0]; + FAR int32_t *flags = (FAR int32_t *)arg[1]; + FAR uint16_t *addrlen = (FAR uint16_t *)arg[2]; + FAR uint16_t *buflen = (FAR uint16_t *)arg[3]; + FAR struct sockaddr_storage *sa = (FAR struct sockaddr_storage *)arg[4]; + FAR uint8_t *buf = (FAR uint8_t *)arg[5]; + + FAR struct apicmd_sendto_s *out = + (FAR struct apicmd_sendto_s *)pktbuf; + int32_t flg; + struct altcom_sockaddr_storage altsa; + + if (*buflen > APICMD_DATA_LENGTH) + { + /* Truncate the length to the maximum transfer size */ + + *buflen = APICMD_DATA_LENGTH; + } + else if (*buflen < 0) + { + size = -EINVAL; + goto err_out; + } + + if (*buflen > 0 && !buf) + { + size = -EINVAL; + goto err_out; + } + + if (sa && !(*addrlen)) + { + size = -EINVAL; + goto err_out; + } + + out->sockfd = htonl(*sockfd); + size = flags2altflags(*flags, &flg); + if (size != 0) + { + goto err_out; + } + + out->flags = htonl(flg); + out->datalen = htonl(*buflen); + if (*addrlen == sizeof(struct sockaddr_in)) + { + out->tolen = htonl(sizeof(struct altcom_sockaddr_in)); + } + else if (*addrlen == sizeof(struct sockaddr_in6)) + { + out->tolen = htonl(sizeof(struct altcom_sockaddr_in6)); + } + else if (*addrlen == 0) + { + out->tolen = htonl(0); + } + else + { + size = -EINVAL; + } + + if (size == 0) + { + memset(&altsa, 0, sizeof(struct altcom_sockaddr_storage)); + sockaddr2altstorage((struct sockaddr *)sa, &altsa); + memcpy(&out->to, &altsa, *addrlen); + memcpy(out->senddata, buf, *buflen); + size = sizeof(struct apicmd_sendto_s) - sizeof(out->senddata) + + *buflen; + } + +err_out: + *altcid = APICMDID_SOCK_SENDTO; + + return size; +} + +static int32_t setsockopt_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR int32_t *sockfd = (FAR int32_t *)arg[0]; + FAR int16_t *level = (FAR int16_t *)arg[1]; + FAR int16_t *option = (FAR int16_t *)arg[2]; + FAR uint16_t *valuelen = (FAR uint16_t *)arg[3]; + FAR uint8_t *value = (FAR uint8_t *)arg[4]; + + FAR struct apicmd_setsockopt_s *out = + (FAR struct apicmd_setsockopt_s *)pktbuf; + + int setmode = 0; + + out->sockfd = htonl(*sockfd); + if (*level == SOL_SOCKET) + { + out->level = htonl(ALTCOM_SOL_SOCKET); + out->optlen = htonl(*valuelen); + + if (*option == SO_BROADCAST) + { + out->optname = htonl(ALTCOM_SO_BROADCAST); + } + else if (*option == SO_REUSEADDR) + { + out->optname = htonl(ALTCOM_SO_REUSEADDR); + } + else if (*option == SO_KEEPALIVE) + { + out->optname = htonl(ALTCOM_SO_KEEPALIVE); + } + else if (*option == SO_RCVBUF) + { + out->optname = htonl(ALTCOM_SO_RCVBUF); + } +#ifdef CONFIG_NET_SOLINGER + else if (*option == SO_LINGER) + { + out->optname = htonl(ALTCOM_SO_LINGER); + } +#endif + else + { + size = -ENOPROTOOPT; + } + } + else if (*level == IPPROTO_IP) + { + out->level = htonl(ALTCOM_IPPROTO_IP); + out->optlen = htonl(*valuelen); + + if (*option == IP_TOS) + { + out->optname = htonl(ALTCOM_IP_TOS); + } + else if (*option == IP_TTL) + { + out->optname = htonl(ALTCOM_IP_TTL); + } + else if (*option == IP_MULTICAST_TTL) + { + out->optname = htonl(ALTCOM_IP_MULTICAST_TTL); + } + else if (*option == IP_MULTICAST_LOOP) + { + out->optname = htonl(ALTCOM_IP_MULTICAST_LOOP); + } + else if (*option == IP_MULTICAST_IF) + { + out->optname = htonl(ALTCOM_IP_MULTICAST_IF); + } + else if (*option == IP_ADD_MEMBERSHIP) + { + out->optname = htonl(ALTCOM_IP_ADD_MEMBERSHIP); + } + else if (*option == IP_DROP_MEMBERSHIP) + { + out->optname = htonl(ALTCOM_IP_DROP_MEMBERSHIP); + } + else + { + size = -ENOPROTOOPT; + } + } + else if (*level == IPPROTO_TCP) + { + out->level = htonl(ALTCOM_IPPROTO_TCP); + out->optlen = htonl(*valuelen); + if (*option == TCP_NODELAY) + { + out->optname = htonl(ALTCOM_TCP_NODELAY); + } + else if (*option == TCP_KEEPIDLE) + { + out->optname = htonl(ALTCOM_TCP_KEEPIDLE); + } + else if (*option == TCP_KEEPINTVL) + { + out->optname = htonl(ALTCOM_TCP_KEEPINTVL); + } + else if (*option == TCP_KEEPCNT) + { + out->optname = htonl(ALTCOM_TCP_KEEPCNT); + } + else + { + size = -ENOPROTOOPT; + } + } + else if (*level == IPPROTO_IPV6) + { + out->level = htonl(ALTCOM_IPPROTO_IPV6); + out->optlen = htonl(*valuelen); + if (*option == IPV6_V6ONLY) + { + out->optname = htonl(ALTCOM_IPV6_V6ONLY); + } + else + { + size = -ENOPROTOOPT; + } + } + else + { + size = -ENOPROTOOPT; + } + + if (size < 0) + { + goto exit; + } + + setmode = get_so_setmode(*level, *option); + + switch (setmode) + { + case ALTCOM_SO_SETMODE_8BIT: + if (*valuelen < sizeof(int8_t)) + { + m_err("Unexpected valuelen: actual=%lu expect=%lu\n", + *valuelen, sizeof(int8_t)); + size = -EINVAL; + break; + } + + *out->optval = value[0]; + break; + case ALTCOM_SO_SETMODE_32BIT: + if (*valuelen < sizeof(int32_t)) + { + m_err("Unexpected valuelen: actual=%lu expect=%lu\n", + *valuelen, sizeof(int32_t)); + size = -EINVAL; + break; + } + + *((FAR int32_t *)out->optval) = + htonl(*((FAR int32_t *)value)); + break; + case ALTCOM_SO_SETMODE_LINGER: + if (*valuelen < sizeof(struct linger)) + { + m_err("Unexpected valuelen: actual=%lu expect=%lu\n", + *valuelen, sizeof(struct linger)); + size = -EINVAL; + break; + } + + ((FAR struct altcom_linger *)out->optval)->l_onoff = + htonl(((FAR struct linger *)value)->l_onoff); + ((FAR struct altcom_linger *)out->optval)->l_linger = + htonl(((FAR struct linger *)value)->l_linger); + break; + case ALTCOM_SO_SETMODE_INADDR: + if (*valuelen < sizeof(struct in_addr)) + { + m_err("Unexpected valuelen: actual=%lu expect=%lu\n", + *valuelen, sizeof(struct in_addr)); + size = -EINVAL; + break; + } + + ((FAR struct altcom_in_addr *)out->optval)->s_addr = + htonl(((FAR struct in_addr *)value)->s_addr); + break; + case ALTCOM_SO_SETMODE_IPMREQ: + if (*valuelen < sizeof(struct ip_mreq)) + { + m_err("Unexpected valuelen: actual=%lu expect=%lu\n", + *valuelen, sizeof(struct ip_mreq)); + size = -EINVAL; + break; + } + + ((FAR struct altcom_ip_mreq *)out->optval)->imr_multiaddr.s_addr = + htonl(((FAR struct ip_mreq *)value)->imr_multiaddr.s_addr); + ((FAR struct altcom_ip_mreq *)out->optval)->imr_interface.s_addr = + htonl(((FAR struct ip_mreq *)value)->imr_interface.s_addr); + break; + default: + size = -EINVAL; + break; + } + +exit: + if (size == 0) + { + size = sizeof(struct apicmd_setsockopt_s); + } + + *altcid = APICMDID_SOCK_SETSOCKOPT; + + return size; +} + +static int32_t sendatcmd_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR const char *cmd = (FAR const char *)arg[0]; + int cmdlen = (int)arg[1]; + + size = cmdlen - ATCMD_HEADER_LEN; + memcpy(pktbuf, cmd + ATCMD_HEADER_LEN, size); + pktbuf[size - ATCMD_FOOTER_LEN] = '\0'; + + if (altver == ALTCOM_VER1) + { + size = -ENOTSUP; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_SEND_ATCMD_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t injectimage_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + FAR uint8_t *sending_data = (uint8_t *)arg[0]; + int len = *(int *)arg[1]; + bool mode = *(bool *)arg[2]; + + if (altver == ALTCOM_VER1) + { + FAR struct apicmd_cmddat_fw_injectdeltaimg_s *out = + (FAR struct apicmd_cmddat_fw_injectdeltaimg_s *)pktbuf; + + *altcid = APICMDID_FW_INJECTDELTAIMG; + + len = (len > APICMD_FW_INJECTDATA_MAXLEN) ? + APICMD_FW_INJECTDATA_MAXLEN : len; + + out->data_len = htonl(len); + out->inject_mode = mode ? LTEFW_INJECTION_MODE_NEW + : LTEFW_INJECTION_MODE_APPEND; + memcpy(out->data, sending_data, len); + size = sizeof(struct apicmd_cmddat_fw_injectdeltaimg_s); + } + else if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_fw_injectdeltaimg_v4_s *out = + (FAR struct apicmd_cmddat_fw_injectdeltaimg_v4_s *)pktbuf; + + *altcid = APICMDID_FW_INJECTDELTAIMG_V4; + len = (len > APICMD_FW_INJECTDATA_MAXLEN_V4) ? + APICMD_FW_INJECTDATA_MAXLEN_V4 : len; + + out->data_len = htonl(len); + out->inject_mode = mode ? LTEFW_INJECTION_MODE_NEW + : LTEFW_INJECTION_MODE_APPEND; + memcpy(out->data, sending_data, len); + size = sizeof(struct apicmd_cmddat_fw_injectdeltaimg_v4_s) - 1 + len; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t getimagelen_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_FW_GETDELTAIMGLEN; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_FW_GETDELTAIMGLEN_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t execupdate_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_FW_EXECDELTAUPDATE; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_FW_EXECDELTAUPDATE_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t getupdateres_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_FW_GETUPDATERESULT; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_FW_GETUPDATERESULT_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t select_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + FAR int32_t *request = (FAR int32_t *)arg[0]; + FAR int32_t *id = (FAR int32_t *)arg[1]; + FAR int32_t *maxfds = (FAR int32_t *)arg[2]; + FAR uint16_t *used_setbit = (FAR uint16_t *)arg[3]; + FAR altcom_fd_set *readset = (FAR altcom_fd_set *)arg[4]; + FAR altcom_fd_set *writeset = (FAR altcom_fd_set *)arg[5]; + FAR altcom_fd_set *exceptset = (FAR altcom_fd_set *)arg[6]; + + FAR struct apicmd_select_s *out = + (FAR struct apicmd_select_s *)pktbuf; + + out->request = htonl(*request); + out->id = htonl(*id); + out->maxfds = htonl(*maxfds); + out->used_setbit = htons(*used_setbit); + memcpy(&out->readset, readset, sizeof(altcom_fd_set)); + memcpy(&out->writeset, writeset, sizeof(altcom_fd_set)); + memcpy(&out->exceptset, exceptset, sizeof(altcom_fd_set)); + + size = sizeof(struct apicmd_select_s); + + *altcid = APICMDID_SOCK_SELECT; + + return size; +} + +static int32_t smsinit_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + FAR struct apicmd_sms_init_req_s *out = + (FAR struct apicmd_sms_init_req_s *)pktbuf; + + *altcid = APICMDID_SMS_INIT; + + out->types = ALTCOM_SMS_MSG_TYPE_SEND | ALTCOM_SMS_MSG_TYPE_RECV | + ALTCOM_SMS_MSG_TYPE_DELIVER_REPORT; + out->storage_use = 1; /* always use storage */ + + return sizeof(struct apicmd_sms_init_req_s); +} + +static int32_t smsfin_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + *altcid = APICMDID_SMS_FIN; + + return 0; +} + +static int32_t smssend_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + int32_t size = 0; + int i; + FAR struct apicmd_sms_send_req_s *out = + (FAR struct apicmd_sms_send_req_s *)pktbuf; + FAR struct sms_send_msg_s *msg = (FAR struct sms_send_msg_s *)arg[0]; + uint16_t msglen = *((FAR uint16_t *)arg[1]); + bool en_status_report = *((FAR bool *)arg[2]); + FAR struct sms_sc_addr_s *scaddr = (FAR struct sms_sc_addr_s *)arg[3]; + uint8_t chset = *((FAR uint8_t *)arg[4]); + FAR uint8_t *dest_toa = (FAR uint8_t *)arg[5]; + + if (msglen > pktsz) + { + return -ENOBUFS; + } + + if ((msg->header.destaddrlen % 2) || (msg->header.datalen % 2) || + (msg->header.destaddrlen > (SMS_MAX_ADDRLEN * 2)) || + (msg->header.datalen > (SMS_MAX_DATALEN * 2))) + { + /* destaddrlen and datalen must be even numbers */ + + return -EINVAL; + } + + out->sc_addr.toa = scaddr->toa; + out->sc_addr.length = scaddr->addrlen; + + /* Swap sc address */ + + for (i = 0; i < (scaddr->addrlen / 2); i++) + { + out->sc_addr.address[i] = htons(scaddr->addr[i]); + } + + out->valid_indicator = ALTCOM_SMS_MSG_VALID_UD; + out->valid_indicator |= en_status_report ? ALTCOM_SMS_MSG_VALID_SRR : 0; + + out->dest_addr.toa = (dest_toa == NULL) ? 0 : *dest_toa; + out->dest_addr.length = msg->header.destaddrlen; + + /* Swap destination address */ + + for (i = 0; i < (msg->header.destaddrlen / 2); i++) + { + out->dest_addr.address[i] = htons(msg->header.destaddr[i]); + } + + switch (chset) + { + case SMS_CHSET_UCS2: + chset = ALTCOM_SMS_CHSET_UCS2; + break; + case SMS_CHSET_GSM7: + chset = ALTCOM_SMS_CHSET_GSM7; + break; + case SMS_CHSET_BINARY: + chset = ALTCOM_SMS_CHSET_BINARY; + break; + default: + return -EINVAL; + } + + out->userdata.chset = ALTCOM_SMS_CHSET_UCS2; + out->userdata.data_len = htons(msg->header.datalen); + + /* Swap data */ + + for (i = 0; i < (msg->header.datalen / 2); i++) + { + out->user_data[i] = htons(msg->data[i]); + } + + *altcid = APICMDID_SMS_SEND; + + size = sizeof(struct apicmd_sms_send_req_s) + msg->header.datalen; + + return size; +} + +static int32_t smsdelete_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + FAR struct apicmd_sms_delete_s *out = + (FAR struct apicmd_sms_delete_s *)pktbuf; + uint16_t msg_index = *(FAR uint16_t *)arg[0]; + + *altcid = APICMDID_SMS_DELETE; + + out->index = htons(msg_index); + out->types = 0; + + return sizeof(struct apicmd_sms_delete_s); +} + +static int32_t smsreportrecv_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + FAR struct apicmd_sms_res_s *out = + (FAR struct apicmd_sms_res_s *)pktbuf; + + *altcid = APICMDID_SMS_REPORT_RECV | ALTCOM_CMDID_REPLY_BIT; + + out->result = htonl(0); /* always success */ + + return sizeof(struct apicmd_sms_res_s); +} + +static int32_t logsave_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + FAR struct apicmd_cmddat_clogs_s *out = + (FAR struct apicmd_cmddat_clogs_s *)pktbuf; + size_t len = *(FAR size_t *)arg[0]; + int32_t size = sizeof(struct apicmd_cmddat_clogs_s); + + out->pathlen = len + strlen(ALTCOM_LOGSPATH); + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_CLOGS; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_CLOGS_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t loglist_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + FAR struct apicmddbg_getloglist_s *out = + (FAR struct apicmddbg_getloglist_s *)pktbuf; + size_t len = (size_t)arg[0]; + int32_t size = sizeof(struct apicmddbg_getloglist_s); + + out->listsize = LTE_LOG_LIST_SIZE; + out->pathlen = len + strlen(ALTCOM_LOGSPATH); + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_LOGLIST; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_LOGLIST_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +#ifdef CONFIG_MODEM_ALT1250_LOG_ACCESS + +static int32_t logopen_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + FAR struct apicmd_logopen_s *out = (FAR struct apicmd_logopen_s *)pktbuf; + FAR char *filename = (FAR char *)arg[0]; + int32_t size = sizeof(struct apicmd_logopen_s); + int ret; + + ret = create_logpath(filename, out->path); + if (ret < 0) + { + return ret; + } + + out->flags = htonl(ALTCOM_LOG_OPEN_FLAGS); + out->mode = htonl(0); + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_LOGOPEN; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_LOGOPEN_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t logclose_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + FAR struct apicmd_logclose_s *out = (FAR struct apicmd_logclose_s *)pktbuf; + int fd = (int)arg[0]; + int32_t size = sizeof(struct apicmd_logclose_s); + + out->fd = htonl(fd); + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_LOGCLOSE; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_LOGCLOSE_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t logread_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + FAR struct apicmd_logread_s *out = (FAR struct apicmd_logread_s *)pktbuf; + int fd = (int)arg[0]; + size_t rlen = (size_t)arg[1]; + int32_t size = sizeof(struct apicmd_logread_s); + + out->fd = htonl(fd); + out->readlen = (rlen > ALTCOM_LOG_READ_LEN_MAX) ? + htonl(ALTCOM_LOG_READ_LEN_MAX) : htonl(rlen); + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_LOGREAD; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_LOGREAD_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t loglseek_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + FAR struct apicmd_loglseek_s *out = (FAR struct apicmd_loglseek_s *)pktbuf; + int fd = (int)arg[0]; + off_t offset = *(FAR off_t *)arg[1]; + int whence = (int)arg[2]; + int32_t size = sizeof(struct apicmd_loglseek_s); + + switch (whence) + { + case SEEK_SET: + out->whence = htonl(ALTCOM_LOG_SEEK_SET); + break; + + case SEEK_CUR: + out->whence = htonl(ALTCOM_LOG_SEEK_CUR); + break; + + case SEEK_END: + out->whence = htonl(ALTCOM_LOG_SEEK_END); + break; + + default: + return -EINVAL; + break; + } + + out->fd = htonl(fd); + out->offset = htonl(offset); + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_LOGLSEEK; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_LOGLSEEK_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +static int32_t logremove_pkt_compose(FAR void **arg, + size_t arglen, uint8_t altver, FAR uint8_t *pktbuf, + const size_t pktsz, FAR uint16_t *altcid) +{ + FAR struct apicmd_logremove_s *out = + (FAR struct apicmd_logremove_s *)pktbuf; + FAR char *filename = (FAR char *)arg[0]; + int32_t size = sizeof(struct apicmd_logremove_s); + int ret; + + ret = create_logpath(filename, out->path); + if (ret < 0) + { + return ret; + } + + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_LOGREMOVE; + } + else if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_LOGREMOVE_V4; + } + else + { + size = -ENOSYS; + } + + return size; +} + +#endif /* CONFIG_MODEM_ALT1250_LOG_ACCESS */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +static int32_t errinfo_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR lte_errinfo_t *info = (FAR lte_errinfo_t *)arg[0]; + FAR struct apicmd_cmddat_errinfo_s *in = + (FAR struct apicmd_cmddat_errinfo_s *)pktbuf; + + info->err_indicator = in->indicator; + info->err_result_code = ntohl(in->err_code); + info->err_no = ntohl(in->err_no); + memcpy(info->err_string, in->err_str, LTE_ERROR_STRING_MAX_LEN); + info->err_string[LTE_ERROR_STRING_MAX_LEN - 1] = '\0'; + + return 0; +} + +static int32_t getver_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR lte_version_t *version = (FAR lte_version_t *)arg[1]; + FAR struct apicmd_cmddat_getverres_s *in = + (FAR struct apicmd_cmddat_getverres_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (*ret == 0) + { + /* Parse version information */ + + getver_parse_response(in, version); + } + + return 0; +} + +static int32_t getphone_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR uint8_t *errcause = (FAR uint8_t *)arg[1]; + FAR char *phoneno = (FAR char *)arg[2]; + FAR struct apicmd_cmddat_phonenores_s *in = + (FAR struct apicmd_cmddat_phonenores_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + *errcause = in->errcause; + if (0 == *ret) + { + if (arglen > 3) + { + FAR size_t *len = (FAR size_t *)arg[3]; + + /* Is it enough length to include Null terminate? + * The length of LTE_PHONENO_LEN includes the + * null terminator. + */ + + if (*len < strnlen((FAR const char *)in->phoneno, + LTE_PHONENO_LEN)) + { + return -ENOBUFS; + } + } + + strncpy(phoneno, (FAR const char *)in->phoneno, LTE_PHONENO_LEN); + } + + return 0; +} + +static int32_t getimsi_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR uint8_t *errcause = (FAR uint8_t *)arg[1]; + FAR char *imsi = (FAR char *)arg[2]; + FAR struct apicmd_cmddat_getimsires_s *in = + (FAR struct apicmd_cmddat_getimsires_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + *errcause = in->errcause; + if (0 == *ret) + { + if (arglen > 3) + { + FAR size_t *len = (FAR size_t *)arg[3]; + + /* Is it enough length to include Null terminate? + * The length of APICMD_IMSI_LEN includes the + * null terminator. + */ + + if (*len < strnlen((FAR const char *)in->imsi, + APICMD_IMSI_LEN)) + { + return -ENOBUFS; + } + } + + strncpy(imsi, (FAR const char *)in->imsi, APICMD_IMSI_LEN); + } + + return 0; +} + +static int32_t getimei_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR char *imei = (FAR char *)arg[1]; + FAR struct apicmd_cmddat_getimeires_s *in = + (FAR struct apicmd_cmddat_getimeires_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (0 == *ret) + { + if (arglen > 2) + { + FAR size_t *len = (FAR size_t *)arg[2]; + + /* Is it enough length to include Null terminate? + * The length of LTE_IMEI_LEN includes the + * null terminator. + */ + + if (*len < strnlen((FAR const char *)in->imei, LTE_IMEI_LEN)) + { + return -ENOBUFS; + } + } + + strncpy(imei, (FAR const char *)in->imei, LTE_IMEI_LEN); + } + + return 0; +} + +static int32_t getpinset_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR lte_getpin_t *pinset = (FAR lte_getpin_t *)arg[1]; + FAR struct apicmd_cmddat_getpinsetres_s *in = + (FAR struct apicmd_cmddat_getpinsetres_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (0 == *ret) + { + /* Parse PIN settings */ + + getpinset_parse_response(in, pinset); + } + + return 0; +} + +static int32_t setpinlock_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR uint8_t *attemptsleft = (FAR uint8_t *)arg[1]; + FAR struct apicmd_cmddat_setpinlockres_s *in = + (FAR struct apicmd_cmddat_setpinlockres_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (*ret != 0) + { + *attemptsleft = in->attemptsleft; + } + + return 0; +} + +static int32_t setpincode_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR uint8_t *attemptsleft = (FAR uint8_t *)arg[1]; + FAR struct apicmd_cmddat_setpincoderes_s *in = + (FAR struct apicmd_cmddat_setpincoderes_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (*ret != 0) + { + *attemptsleft = in->attemptsleft; + } + + return 0; +} + +static int32_t enterpin_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR uint8_t *simstat = (FAR uint8_t *)arg[1]; + FAR uint8_t *attemptsleft = (FAR uint8_t *)arg[2]; + FAR struct apicmd_cmddat_enterpinres_s *in = + (FAR struct apicmd_cmddat_enterpinres_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + *simstat = in->simstat; + *attemptsleft = in->attemptsleft; + + return 0; +} + +static int32_t getltime_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR lte_localtime_t *localtime = (FAR lte_localtime_t *)arg[1]; + FAR struct apicmd_cmddat_getltimeres_s *in = + (FAR struct apicmd_cmddat_getltimeres_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (0 == *ret) + { + /* Parse local time */ + + getltime_parse_response(in, localtime); + } + + return 0; +} + +static int32_t getoper_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR char *oper = (FAR char *)arg[1]; + + if (altver == ALTCOM_VER1) + { + FAR struct apicmd_cmddat_getoperatorres_s *in = + (FAR struct apicmd_cmddat_getoperatorres_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (0 == *ret) + { + if (arglen > 2) + { + FAR size_t *len = (FAR size_t *)arg[2]; + + /* Is it enough length to include Null terminate? + * The length of LTE_OPERATOR_LEN includes the + * null terminator. + */ + + if (*len < strnlen((FAR const char *)in->oper, + LTE_OPERATOR_LEN)) + { + return -ENOBUFS; + } + } + + strncpy(oper, (FAR const char *)in->oper, LTE_OPERATOR_LEN); + } + } + else if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_getoperatorres_v4_s *in = + (FAR struct apicmd_cmddat_getoperatorres_v4_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (0 == *ret) + { + if (arglen > 2) + { + FAR size_t *len = (FAR size_t *)arg[2]; + + /* Is it enough length to include Null terminate? + * The length of LTE_OPERATOR_LEN includes the + * null terminator. + */ + + if (*len < strnlen((FAR const char *)in->oper, + LTE_OPERATOR_LEN)) + { + return -ENOBUFS; + } + } + + strncpy(oper, (FAR const char *)in->oper, LTE_OPERATOR_LEN); + } + } + + return 0; +} + +static int32_t setrepqual_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR struct apicmd_cmddat_setrepquality_res_s *in = + (FAR struct apicmd_cmddat_setrepquality_res_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EIO; + + return 0; +} + +static int32_t setrepcell_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR struct apicmd_cmddat_setrepcellinfo_res_s *in = + (FAR struct apicmd_cmddat_setrepcellinfo_res_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EIO; + + return 0; +} + +static int32_t setrepevt_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + + if (altver == ALTCOM_VER1) + { + FAR struct apicmd_cmddat_setrepevtres_s *in = + (FAR struct apicmd_cmddat_setrepevtres_s *)pktbuf; + + *ret = (APICMD_SET_REP_EVT_RES_OK == in->result) ? 0 : -EIO; + } + else if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_setrepevtres_v4_s *in = + (FAR struct apicmd_cmddat_setrepevtres_v4_s *)pktbuf; + + *ret = (APICMD_SET_REP_EVT_RES_OK == in->result) ? 0 : -EIO; + } + + return 0; +} + +static int32_t repevt_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + int32_t ret = 0; + FAR uint8_t *flag = (FAR uint8_t *)arg[0]; + FAR uint32_t *simstat = (FAR uint32_t *)arg[1]; + FAR lte_localtime_t *ltime = (FAR lte_localtime_t *)arg[2]; + + if (altver == ALTCOM_VER1) + { + FAR struct apicmd_cmddat_repevt_s *in = + (FAR struct apicmd_cmddat_repevt_s *)pktbuf; + + switch (in->type) + { + case APICMD_REPORT_EVT_TYPE_LTIME: + { + parse_ltime(&in->u.ltime, ltime); + *flag |= ALTCOM_REPEVT_FLAG_LTIME; + } + break; + + case APICMD_REPORT_EVT_TYPE_SIMD: + { + ret = parse_simd(&in->u.simd, simstat); + if (ret == 0) + { + *flag |= ALTCOM_REPEVT_FLAG_SIMSTAT; + } + } + break; + + case APICMD_REPORT_EVT_TYPE_SIMSTATE: + { + ret = parse_simstate(&in->u.simstate, simstat); + if (ret == 0) + { + *flag |= ALTCOM_REPEVT_FLAG_SIMSTAT; + } + } + break; + + default: + { + m_err("Unsupport event type. type:%d\n", in->type); + ret = -EILSEQ; + } + break; + } + } + else if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_repevt_v4_s *in = + (FAR struct apicmd_cmddat_repevt_v4_s *)pktbuf; + + switch (ntohs(in->type)) + { + case APICMD_REPORT_EVT_TYPE_LTIME: + { + parse_ltime(&in->u.ltime, ltime); + *flag |= ALTCOM_REPEVT_FLAG_LTIME; + } + break; + + case APICMD_REPORT_EVT_TYPE_SIMD: + { + ret = parse_simd(&in->u.simd, simstat); + if (ret == 0) + { + *flag |= ALTCOM_REPEVT_FLAG_SIMSTAT; + } + } + break; + + case APICMD_REPORT_EVT_TYPE_SIMSTATE: + { + ret = parse_simstate(&in->u.simstate, simstat); + if (ret == 0) + { + *flag |= ALTCOM_REPEVT_FLAG_SIMSTAT; + } + } + break; + + default: + { + m_err("Unsupport event type. type:%d\n", + ntohs(in->type)); + ret = -EILSEQ; + } + break; + } + } + + return ret; +} + +static int32_t repqual_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR lte_quality_t *quality = (FAR lte_quality_t *)arg[0]; + int ret = 0; + + FAR struct apicmd_cmddat_quality_s *in = + (FAR struct apicmd_cmddat_quality_s *)pktbuf; + + ret = altcombs_set_quality(quality, in); + if (0 > ret) + { + return -EFAULT; + } + + return 0; +} + +static int32_t repcell_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + struct cellinfo_helper_s + { + lte_cellinfo_t info; + lte_neighbor_cell_t neighbors[LTE_NEIGHBOR_CELL_MAX]; + }; + + FAR lte_cellinfo_t *cellinfo = (FAR lte_cellinfo_t *)arg[0]; + + if (altver == ALTCOM_VER1) + { + FAR struct apicmd_cmddat_cellinfo_s *in = + (FAR struct apicmd_cmddat_cellinfo_s *)pktbuf; + + cellinfo->nr_neighbor = 0; + + altcombs_set_cellinfo(in, cellinfo); + } + else if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_cellinfo_v4_s *in = + (FAR struct apicmd_cmddat_cellinfo_v4_s *)pktbuf; + + cellinfo->nr_neighbor = LTE_NEIGHBOR_CELL_MAX; + + altcombs_set_cellinfo_v4(in, cellinfo); + } + + return 0; +} + +static int32_t getedrx_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR lte_edrx_setting_t *settings = (FAR lte_edrx_setting_t *)arg[1]; + FAR struct apicmd_cmddat_getedrxres_s *in = + (FAR struct apicmd_cmddat_getedrxres_s *)pktbuf; + FAR bool *is_getedrxevt = (FAR bool *)arg[2]; + + *is_getedrxevt = true; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (0 == *ret) + { + /* Checks and converts the eDRX value of the API command response. */ + + *ret = altcombs_convert_apicmd_edrx_value(&in->set, settings); + if (0 > *ret) + { + m_err("altcombs_convert_apicmd_edrx_value() failed: %ld\n", *ret); + *ret = -EFAULT; + } + } + + return 0; +} + +static int32_t setedrx_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR struct apicmd_cmddat_setedrxres_s *in = + (FAR struct apicmd_cmddat_setedrxres_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + + return 0; +} + +static int32_t getpsm_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR lte_psm_setting_t *settings = (FAR lte_psm_setting_t *)arg[1]; + FAR bool *is_getpsmevt = (FAR bool *)arg[2]; + + FAR struct apicmd_cmddat_getpsmres_s *in = + (FAR struct apicmd_cmddat_getpsmres_s *)pktbuf; + + *is_getpsmevt = true; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (0 == *ret) + { + /* Parse PSM settings */ + + *ret = altcombs_set_psm(&in->set, settings); + if (0 > *ret) + { + m_err("altcombs_set_psm() failed: %ld\n", *ret); + *ret = -EFAULT; + } + } + + return 0; +} + +static int32_t setpsm_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR struct apicmd_cmddat_setpsmres_s *in = + (FAR struct apicmd_cmddat_setpsmres_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + + return 0; +} + +static int32_t getce_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR lte_ce_setting_t *settings = (FAR lte_ce_setting_t *)arg[1]; + FAR struct apicmd_cmddat_getceres_s *in = + (FAR struct apicmd_cmddat_getceres_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (0 == *ret) + { + /* Parse CE settings */ + + getce_parse_response(in, settings); + } + + return 0; +} + +static int32_t setce_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR struct apicmd_cmddat_setceres_s *in = + (FAR struct apicmd_cmddat_setceres_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + + return 0; +} + +static int32_t radioon_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR struct apicmd_cmddat_radioonres_s *in = + (FAR struct apicmd_cmddat_radioonres_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + + return 0; +} + +static int32_t radiooff_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR struct apicmd_cmddat_radiooffres_s *in = + (FAR struct apicmd_cmddat_radiooffres_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + + return 0; +} + +static int32_t actpdn_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR lte_pdn_t *pdn = (FAR lte_pdn_t *)arg[1]; + + if (altver == ALTCOM_VER1) + { + FAR struct apicmd_cmddat_activatepdnres_s *in = + (FAR struct apicmd_cmddat_activatepdnres_s *)pktbuf; + + if (LTE_RESULT_OK == in->result) + { + /* Parse PDN information */ + + altcombs_set_pdninfo(&in->pdnset, pdn); + *ret = in->result; + } + else + { + *ret = (LTE_RESULT_CANCEL == in->result) ? -ECANCELED : -EPROTO; + } + } + else if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_activatepdnres_v4_s *in = + (FAR struct apicmd_cmddat_activatepdnres_v4_s *)pktbuf; + + if (LTE_RESULT_OK == in->result) + { + /* Parse PDN information */ + + altcombs_set_pdninfo_v4(&in->pdnset, pdn, NULL, NULL); + *ret = in->result; + } + else + { + *ret = (LTE_RESULT_CANCEL == in->result) ? -ECANCELED : -EPROTO; + } + } + + return 0; +} + +static int32_t deactpdn_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR struct apicmd_cmddat_deactivatepdnres_s *in = + (FAR struct apicmd_cmddat_deactivatepdnres_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + + return 0; +} + +static int32_t getnetinfo_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR lte_netinfo_t *info = (FAR lte_netinfo_t *)arg[1]; + FAR uint8_t *pdn_num = (FAR uint8_t *)arg[2]; + + if (altver == ALTCOM_VER1) + { + FAR struct apicmd_cmddat_getnetinfores_s *in = + (FAR struct apicmd_cmddat_getnetinfores_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (0 == *ret) + { + /* Parse network information */ + + getnetinfo_parse_response(in, info, *pdn_num); + } + } + else if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_getnetinfores_v4_s *in = + (FAR struct apicmd_cmddat_getnetinfores_v4_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (0 == *ret) + { + /* Parse network information */ + + getnetinfo_parse_response_v4(in, info, *pdn_num); + } + } + + return 0; +} + +static int32_t getimscap_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR bool *imscap = (FAR bool *)arg[1]; + FAR struct apicmd_cmddat_getimscapres_s *in = + (FAR struct apicmd_cmddat_getimscapres_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (0 == *ret) + { + *imscap = (in->ims_cap == APICMD_IMSCAP_ENABLE) ? + LTE_ENABLE : LTE_DISABLE; + } + + return 0; +} + +static int32_t setrepnet_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR struct apicmd_cmddat_set_repnetinfores_s *in = + (FAR struct apicmd_cmddat_set_repnetinfores_s *)pktbuf; + + *ret = (APICMD_REPNETINFO_RES_OK == in->result ? 0 : -EIO); + + return 0; +} + +static int32_t repnet_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR lte_netinfo_t *netinfo = (FAR lte_netinfo_t *)arg[0]; + FAR uint8_t *ndnsaddrs = (FAR uint8_t *)arg[1]; + FAR struct sockaddr_storage *dnsaddrs = + (FAR struct sockaddr_storage *)arg[2]; + int i = 0; + + if (altver == ALTCOM_VER1) + { + FAR struct apicmd_cmddat_rep_netinfo_s *in = + (FAR struct apicmd_cmddat_rep_netinfo_s *)pktbuf; + + netinfo->nw_stat = in->netinfo.nw_stat; + netinfo->nw_err.err_type = in->netinfo.err_info.err_type; + netinfo->nw_err.reject_cause.category = in->netinfo. + err_info.reject_cause.category; + netinfo->nw_err.reject_cause.value = in->netinfo. + err_info.reject_cause.value; + netinfo->pdn_num = in->netinfo.pdn_count; + if (0 < in->netinfo.pdn_count) + { + for (i = 0; i < in->netinfo.pdn_count; i++) + { + altcombs_set_pdninfo(&in->netinfo.pdn[i], + &netinfo->pdn_stat[i]); + } + } + + /* parse DNS address if exists */ + + if (pktsz == (sizeof(struct apicmd_cmddat_rep_netinfo_s))) + { + *ndnsaddrs = 0; + + /* parse IPv4 DNS address */ + + if (*(uint32_t *)in->dnsaddrv4 != 0) + { + FAR struct sockaddr_in *v4addr = + (FAR struct sockaddr_in *)&dnsaddrs[0]; + + v4addr->sin_family = AF_INET; + v4addr->sin_port = 0; + memcpy(&v4addr->sin_addr, in->dnsaddrv4, + sizeof(v4addr->sin_addr)); + (*ndnsaddrs)++; + } + + /* parse IPv6 DNS address */ + + if (!((*(uint32_t *)&in->dnsaddrv6[0] == 0) && + (*(uint32_t *)&in->dnsaddrv6[4] == 0) && + (*(uint32_t *)&in->dnsaddrv6[8] == 0) && + (*(uint32_t *)&in->dnsaddrv6[12] == 0))) + { + FAR struct sockaddr_in6 *v6addr = + (FAR struct sockaddr_in6 *)&dnsaddrs[*ndnsaddrs]; + + v6addr->sin6_family = AF_INET6; + v6addr->sin6_port = 0; + memcpy(&v6addr->sin6_addr, in->dnsaddrv6, + sizeof(v6addr->sin6_addr)); + (*ndnsaddrs)++; + } + } + } + else if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_rep_netinfo_v4_s *in = + (FAR struct apicmd_cmddat_rep_netinfo_v4_s *)pktbuf; + + netinfo->nw_stat = in->netinfo.nw_stat; + netinfo->nw_err.err_type = in->netinfo.err_info.err_type; + netinfo->nw_err.reject_cause.category = in->netinfo. + err_info.reject_cause.category; + netinfo->nw_err.reject_cause.value = in->netinfo. + err_info.reject_cause.value; + netinfo->pdn_num = in->netinfo.pdn_count; + if (0 < in->netinfo.pdn_count) + { + for (i = 0; i < in->netinfo.pdn_count; i++) + { + if (i == 0) + { + altcombs_set_pdninfo_v4(&in->netinfo.pdn[i], + &netinfo->pdn_stat[i], ndnsaddrs, dnsaddrs); + } + else + { + altcombs_set_pdninfo_v4(&in->netinfo.pdn[i], + &netinfo->pdn_stat[i], NULL, NULL); + } + } + } + } + + return 0; +} + +static int32_t getsiminfo_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR lte_siminfo_t *siminfo = (FAR lte_siminfo_t *)arg[1]; + FAR struct apicmd_cmddat_getsiminfo_res_s *in = + (FAR struct apicmd_cmddat_getsiminfo_res_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + + if (0 == *ret) + { + /* Parse SIM information */ + + getsiminfo_parse_response(in, siminfo); + } + + return 0; +} + +static int32_t getdedrx_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR lte_edrx_setting_t *settings = (FAR lte_edrx_setting_t *)arg[1]; + FAR struct apicmd_cmddat_getdynamicedrxres_s *in = + (FAR struct apicmd_cmddat_getdynamicedrxres_s *)pktbuf; + FAR bool *is_getdedrxevt = (FAR bool *)arg[2]; + + *is_getdedrxevt = true; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (0 == *ret) + { + /* Checks and converts the eDRX value of the API command response. */ + + *ret = altcombs_convert_apicmd_edrx_value(&in->set, settings); + if (0 > *ret) + { + m_err("altcombs_convert_apicmd_edrx_value() failed: %ld\n", *ret); + *ret = -EFAULT; + } + } + + return 0; +} + +static int32_t getdpsm_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR lte_psm_setting_t *settings = (FAR lte_psm_setting_t *)arg[1]; + FAR struct apicmd_cmddat_getdynamicpsmres_s *in = + (FAR struct apicmd_cmddat_getdynamicpsmres_s *)pktbuf; + FAR bool *is_getcpsmevt = (FAR bool *)arg[2]; + + *is_getcpsmevt = true; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (0 == *ret) + { + /* Parse PSM settings */ + + *ret = altcombs_set_psm(&in->set, settings); + if (0 > *ret) + { + m_err("altcombs_set_psm() failed: %ld\n", *ret); + *ret = -EFAULT; + } + } + + return 0; +} + +static int32_t getqual_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR lte_quality_t *quality = (FAR lte_quality_t *)arg[1]; + + if (altver == ALTCOM_VER1) + { + FAR struct apicmd_cmddat_getqualityres_s *in = + (FAR struct apicmd_cmddat_getqualityres_s *)pktbuf; + + *ret = (LTE_RESULT_OK == in->result) ? 0 : -EPROTO; + if (0 == *ret) + { + /* Parse quality information */ + + altcombs_set_quality(quality, &in->quality); + } + } + else if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_getqualityres_v4_s *in = + (FAR struct apicmd_cmddat_getqualityres_v4_s *)pktbuf; + + *ret = 0; + + /* Parse quality information */ + + altcombs_set_quality(quality, &in->quality); + } + + return 0; +} + +static int32_t actpdncancel_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR struct apicmd_cmddat_activatepdn_cancel_res_s *in = + (FAR struct apicmd_cmddat_activatepdn_cancel_res_s *)pktbuf; + + *ret = 0; + + if (LTE_RESULT_OK != in->result) + { + m_err("API command response is err.\n"); + *ret = -EIO; + } + + return 0; +} + +static int32_t getcell_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR lte_cellinfo_t *cellinfo = (FAR lte_cellinfo_t *)arg[1]; + + if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_getcellinfores_v4_s *in = + (FAR struct apicmd_cmddat_getcellinfores_v4_s *)pktbuf; + + /* Parse LTE network cell information */ + + altcombs_set_cellinfo_v4(&in->cellinfo, cellinfo); + + *ret = 0; + } + + return 0; +} + +static int32_t getrat_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + FAR lte_ratinfo_t *ratinfo = (FAR lte_ratinfo_t *)arg[1]; + + if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_getratres_s *in = + (FAR struct apicmd_cmddat_getratres_s *)pktbuf; + + *ret = ntohl(in->result); + + if (0 > *ret) + { + m_err("Modem returned an error [%ld].\n", *ret); + } + else + { + ratinfo->rat = in->rat; + ratinfo->multi_rat_support = (bool)in->rat_mode; + ratinfo->source = in->source; + } + } + + return 0; +} + +static int32_t setrat_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int *ret = (FAR int *)arg[0]; + + if (altver == ALTCOM_VER4) + { + FAR struct apicmd_cmddat_setratres_s *in = + (FAR struct apicmd_cmddat_setratres_s *)pktbuf; + + *ret = ntohl(in->result); + + if (0 > *ret) + { + m_err("Modem returned an error [%ld].\n", *ret); + } + } + + return 0; +} + +static int32_t sockcomm_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int32_t *ret = (FAR int32_t *)arg[0]; + FAR int32_t *errcode = (FAR int32_t *)arg[1]; + + FAR struct altmdmpktr_sockcomm_s *in = + (FAR struct altmdmpktr_sockcomm_s *)pktbuf; + + *ret = ntohl(in->ret_code); + *errcode = ntohl(in->err_code); + + return 0; +} + +static int32_t scokaddr_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + int32_t rc = OK; + FAR int32_t *ret = (FAR int32_t *)arg[0]; + FAR int32_t *errcode = (FAR int32_t *)arg[1]; + FAR uint32_t *addrlen = (FAR uint32_t *)arg[2]; + FAR struct sockaddr_storage *sa = (FAR struct sockaddr_storage *)arg[3]; + + FAR struct altmdmpktr_sockaddr_s *in = + (FAR struct altmdmpktr_sockaddr_s *)pktbuf; + struct altcom_sockaddr_storage altsa; + + *ret = ntohl(in->ret_code); + *errcode = ntohl(in->err_code); + + if (*ret >= 0) + { + *addrlen = ntohl(in->addrlen); + if (*addrlen == sizeof(struct altcom_sockaddr_in)) + { + *addrlen = sizeof(struct sockaddr_in); + } + else if (*addrlen == sizeof(struct altcom_sockaddr_in6)) + { + *addrlen = sizeof(struct sockaddr_in6); + } + else + { + rc = -EILSEQ; + } + + memcpy(&altsa, &in->address, sizeof(struct altcom_sockaddr_storage)); + altstorage2sockaddr(&altsa, (FAR struct sockaddr *)sa); + } + + return rc; +} + +static int32_t getsockopt_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + int32_t rc = OK; + FAR int32_t *ret = (FAR int32_t *)arg[0]; + FAR int32_t *errcode = (FAR int32_t *)arg[1]; + FAR uint32_t *optlen = (FAR uint32_t *)arg[2]; + FAR int8_t *optval = (FAR int8_t *)arg[3]; + FAR uint16_t *level = (FAR uint16_t *)arg[4]; + FAR uint16_t *option = (FAR uint16_t *)arg[5]; + + FAR struct apicmd_getsockoptres_s *in = + (FAR struct apicmd_getsockoptres_s *)pktbuf; + + int setmode = 0; + + *ret = ntohl(in->ret_code); + *errcode = ntohl(in->err_code); + + if (*ret >= 0) + { + *optlen = ntohl(in->optlen); + if (*optlen > APICMD_OPTVAL_LENGTH) + { + rc = -EILSEQ; + } + else + { + setmode = get_so_setmode(*level, *option); + + switch (setmode) + { + case ALTCOM_SO_SETMODE_8BIT: + if (*optlen < sizeof(int8_t)) + { + m_err("Unexpected optlen: actual=%lu expect=%lu\n", + *optlen, sizeof(int8_t)); + rc = -EILSEQ; + break; + } + + *optval = in->optval[0]; + break; + case ALTCOM_SO_SETMODE_32BIT: + if (*optlen < sizeof(int32_t)) + { + m_err("Unexpected optlen: actual=%lu expect=%lu\n", + *optlen, sizeof(int32_t)); + rc = -EILSEQ; + break; + } + + *((FAR int32_t *)optval) = + ntohl(*((FAR int32_t *)in->optval)); + break; + case ALTCOM_SO_SETMODE_LINGER: + if (*optlen < sizeof(struct linger)) + { + m_err("Unexpected optlen: actual=%lu expect=%lu\n", + *optlen, sizeof(struct linger)); + rc = -EILSEQ; + break; + } + + FAR struct altcom_linger *plinger; + + plinger = (FAR struct altcom_linger *)&in->optval[0]; + ((FAR struct linger *)optval)->l_onoff = + ntohl(plinger->l_onoff); + ((FAR struct linger *)optval)->l_linger = + ntohl(plinger->l_linger); + break; + case ALTCOM_SO_SETMODE_INADDR: + if (*optlen < sizeof(struct in_addr)) + { + m_err("Unexpected optlen: actual=%lu expect=%lu\n", + *optlen, sizeof(struct in_addr)); + rc = -EILSEQ; + break; + } + + FAR struct altcom_in_addr *pinaddr; + + pinaddr = (FAR struct altcom_in_addr *)&in->optval[0]; + ((FAR struct in_addr *)optval)->s_addr = + ntohl(pinaddr->s_addr); + break; + default: + break; + } + } + } + + return rc; +} + +static int32_t recvfrom_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + int32_t rc = OK; + FAR int32_t *ret = (FAR int32_t *)arg[0]; + FAR int32_t *errcode = (FAR int32_t *)arg[1]; + FAR uint32_t *fromlen = (FAR uint32_t *)arg[2]; + FAR struct sockaddr_storage *sa = (FAR struct sockaddr_storage *)arg[3]; + FAR int8_t *buf = (FAR int8_t *)arg[4]; + + FAR struct apicmd_recvfromres_s *in = + (FAR struct apicmd_recvfromres_s *)pktbuf; + struct altcom_sockaddr_storage altsa; + + *ret = ntohl(in->ret_code); + *errcode = ntohl(in->err_code); + + if (*ret >= 0) + { + *fromlen = ntohl(in->fromlen); + if (*fromlen == sizeof(struct altcom_sockaddr_in)) + { + *fromlen = sizeof(struct sockaddr_in); + } + else if (*fromlen == sizeof(struct altcom_sockaddr_in6)) + { + *fromlen = sizeof(struct sockaddr_in6); + } + else if (*fromlen != 0) + { + rc = -EILSEQ; + } + + if ((rc == OK) && (*fromlen != 0)) + { + memcpy(&altsa, &in->from, *fromlen); + altstorage2sockaddr(&altsa, (FAR struct sockaddr *)sa); + } + + if (*ret > APICMD_DATA_LENGTH) + { + rc = -EILSEQ; + } + else + { + memcpy(buf, in->recvdata, *ret); + } + } + + return rc; +} + +static int32_t select_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR int32_t *ret = (FAR int32_t *)arg[0]; + FAR int32_t *errcode = (FAR int32_t *)arg[1]; + FAR int32_t *id = (FAR int32_t *)arg[2]; + FAR altcom_fd_set *readset = (FAR altcom_fd_set *)arg[3]; + FAR altcom_fd_set *writeset = (FAR altcom_fd_set *)arg[4]; + FAR altcom_fd_set *exceptset = (FAR altcom_fd_set *)arg[5]; + + FAR struct apicmd_selectres_s *in = + (FAR struct apicmd_selectres_s *)pktbuf; + uint16_t used_setbit; + + *ret = ntohl(in->ret_code); + *errcode = ntohl(in->err_code); + + if (*ret >= 0) + { + *id = ntohl(in->id); + used_setbit = ntohs(in->used_setbit); + memset(readset, 0, sizeof(altcom_fd_set)); + memset(writeset, 0, sizeof(altcom_fd_set)); + memset(exceptset, 0, sizeof(altcom_fd_set)); + if (used_setbit & READSET_BIT) + { + memcpy(readset, &in->readset, sizeof(altcom_fd_set)); + } + + if (used_setbit & WRITESET_BIT) + { + memcpy(writeset, &in->writeset, sizeof(altcom_fd_set)); + } + + if (used_setbit & EXCEPTSET_BIT) + { + memcpy(exceptset, &in->exceptset, sizeof(altcom_fd_set)); + } + } + + return 0; +} + +static int32_t sendatcmd_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR char *respbuff = (FAR char *)arg[0]; + FAR int respbufflen = (int)arg[1]; + FAR int *resplen = (FAR int *)arg[2]; + + if (respbufflen < pktsz) + { + return -ENOBUFS; + } + + memcpy(respbuff, (FAR char *)pktbuf, pktsz); + *resplen = pktsz; + + return 0; +} + +static int32_t fwcommon_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + int32_t result_cmd; + int16_t injection_retcode; + + FAR struct apicmd_cmddat_fw_deltaupcommres_s *in = + (FAR struct apicmd_cmddat_fw_deltaupcommres_s *)pktbuf; + + /* Negative value in result_cmd means an error is occured. + * Zero indicates command successed or size of injected data + */ + + result_cmd = ntohl(in->api_result); + injection_retcode = ntohs(in->ltefw_result); + + return (injection_retcode != 0) ? -injection_retcode : result_cmd; +} + +static int32_t smscommon_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR struct apicmd_sms_res_s *in = + (FAR struct apicmd_sms_res_s *)pktbuf; + + return ntohl(in->result); +} + +static int32_t smssend_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR struct apicmd_sms_sendres_s *in = + (FAR struct apicmd_sms_sendres_s *)pktbuf; + FAR struct sms_refids_s *refid = (FAR struct sms_refids_s *)arg[0]; + uint16_t msglen = *((FAR uint16_t *)arg[1]); + int32_t sendresult = ntohl(in->result); + + if (sendresult >= 0) + { + refid->nrefid = in->mr_num; + memcpy(refid->refid, in->mr_list, sizeof(refid->refid)); + } + + return (sendresult < 0) ? sendresult : msglen; +} + +static int32_t smsreportrecv_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + int i; + FAR struct apicmd_sms_reprecv_s *in = + (FAR struct apicmd_sms_reprecv_s *)pktbuf; + FAR uint16_t *msg_index = (FAR uint16_t *)arg[0]; + FAR uint16_t *msg_sz = (FAR uint16_t *)arg[1]; + FAR uint8_t *maxnum = (FAR uint8_t *)arg[2]; + FAR uint8_t *seqnum = (FAR uint8_t *)arg[3]; + FAR struct sms_recv_msg_header_s *msgheader = + (FAR struct sms_recv_msg_header_s *)arg[4]; + + *msg_index = ntohs(in->index); + *maxnum = 0; + *seqnum = 0; + + if (in->msg.type == ALTCOM_SMS_MSG_TYPE_RECV) + { + FAR struct sms_deliver_msg_s *deliver = + (FAR struct sms_deliver_msg_s *)arg[4]; + + *msg_sz = sizeof(struct sms_deliver_msg_s) + + ntohs(in->msg.u.recv.userdata.data_len); + + if (in->msg.u.recv.valid_indicator & ALTCOM_SMS_MSG_VALID_CONCAT_HDR) + { + *maxnum = in->msg.u.recv.concat_hdr.max_num; + *seqnum = in->msg.u.recv.concat_hdr.seq_num; + } + + msgheader->msgtype = SMS_MSG_TYPE_DELIVER; + memcpy(&msgheader->send_time, &in->msg.u.recv.sc_time, + sizeof(msgheader->send_time)); + msgheader->srcaddrlen = in->msg.u.recv.src_addr.length; + if (msgheader->srcaddrlen > SMS_MAX_ADDRLEN * 2) + { + m_err("Unexpected src addrlen: %u\n", msgheader->srcaddrlen); + return -EINVAL; + } + + /* Swap source address */ + + for (i = 0; i < (msgheader->srcaddrlen / 2); i++) + { + msgheader->srcaddr[i] = ntohs(in->msg.u.recv.src_addr.address[i]); + } + + msgheader->datalen = ntohs(in->msg.u.recv.userdata.data_len); + if (msgheader->datalen > (SMS_MAX_DATALEN * 2)) + { + m_err("Unexpected datalen: %u\n", msgheader->datalen); + return -EINVAL; + } + + /* Swap data */ + + for (i = 0; i < (msgheader->datalen / 2); i++) + { + deliver->data[i] = ntohs(in->msg.u.recv.user_data[i]); + } + + m_info("[recv msg] msg size: %u\n", *msg_sz); + m_info(" maxnum: %u, seqnum: %u\n", *maxnum, *seqnum); + m_info(" msgtype: %u\n", msgheader->msgtype); + m_info(" srcaddrlen: %u\n", msgheader->srcaddrlen); + m_info(" datalen: %u\n", msgheader->datalen); + } + else if (in->msg.type == ALTCOM_SMS_MSG_TYPE_DELIVER_REPORT) + { + FAR struct sms_status_report_msg_s *report = + (FAR struct sms_status_report_msg_s *)arg[4]; + + *msg_sz = sizeof(struct sms_status_report_msg_s); + + msgheader->msgtype = SMS_MSG_TYPE_STATUS_REPORT; + memcpy(&msgheader->send_time, &in->msg.u.delivery_report.sc_time, + sizeof(msgheader->send_time)); + msgheader->srcaddrlen = 0; + memset(msgheader->srcaddr, 0, sizeof(msgheader->srcaddr)); + msgheader->datalen = sizeof(struct sms_status_report_s); + report->status_report.refid = in->msg.u.delivery_report.ref_id; + report->status_report.status = in->msg.u.delivery_report.status; + memcpy(&report->status_report.discharge_time, + &in->msg.u.delivery_report.discharge_time, + sizeof(report->status_report.discharge_time)); + + m_info("[staus report] msg size: %u\n", *msg_sz); + m_info(" msgtype: %u\n", msgheader->msgtype); + m_info(" datalen: %u\n", msgheader->datalen); + m_info(" refid: %u\n", report->status_report.refid); + m_info(" status: %u\n", report->status_report.status); + } + else + { + return -EINVAL; + } + + return 0; +} + +static int32_t urc_event_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + int32_t ret = -ENOTSUP; + uint32_t lcmdid = 0; + alt_evtbuf_inst_t *inst; + lwm2mstub_hndl_t lwm2m_urc_handler; + + if (altver == ALTCOM_VER4) + { + pktbuf[pktsz] = '\0'; + m_info("===== URC =====\n%s" + "===============\n", pktbuf); + lwm2m_urc_handler = lwm2mstub_get_handler(&pktbuf, &pktsz, &lcmdid); + *bitmap = get_event_lapibuffer(dev, lcmdid, &inst); + + if (*bitmap != 0ULL) + { + ret = lwm2m_urc_handler(pktbuf, pktsz, + inst->outparam, inst->outparamlen); + } + } + + return ret; +} + +static int32_t logsave_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR struct apicmd_cmddat_clogsres_s *out = + (FAR struct apicmd_cmddat_clogsres_s *)pktbuf; + FAR char *fname = (FAR char *)arg[0]; + size_t fnamelen = *(FAR size_t *)arg[1]; + + int32_t ret = ntohl(out->altcom_result); + + if ((ret == 0) && (fname != NULL)) + { + if (ALTCOM_PATH_LEN_MAX > out->pathlen) + { + ret = copy_logfilename(fname, fnamelen, out->path); + } + else + { + ret = -EILSEQ; + } + } + + return ret; +} + +static int32_t loglist_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR struct apicmddbg_getloglistres_s *out = + (FAR struct apicmddbg_getloglistres_s *)pktbuf; + FAR char *list = (FAR char *)arg[0]; + size_t nlists = (size_t)arg[1]; + size_t fnamelen = (size_t)arg[2]; + int32_t ret = ntohl(out->altcom_result); + int i; + + if (fnamelen != LTE_LOG_NAME_LEN) + { + return -ENOBUFS; + } + + if (ret == 0) + { + if ((out->listsize > LTE_LOG_LIST_SIZE) || + ((out->listsize != 0) && (ALTCOM_PATH_LEN_MAX < out->pathlen))) + { + return -EILSEQ; + } + + for (i = 0; i < MIN(nlists, out->listsize); i++) + { + ret = copy_logfilename(&list[i * fnamelen], fnamelen, + &out->list[i * out->pathlen]); + if (ret != OK) + { + break; + } + } + + ret = (i == MIN(nlists, out->listsize)) ? i : ret; + } + else if (ret == -EPROTO) + { + ret = 0; + } + + return ret; +} + +#ifdef CONFIG_MODEM_ALT1250_LOG_ACCESS + +static int32_t logcommon_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR struct apicmd_logcommonres_s *out = + (FAR struct apicmd_logcommonres_s *)pktbuf; + + return ntohl(out->altcom_result); +} + +static int32_t logread_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, + size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap) +{ + FAR struct apicmd_logreadres_s *out = + (FAR struct apicmd_logreadres_s *)pktbuf; + FAR void *buf = arg[0]; + size_t len = (size_t)arg[1]; + int32_t ret = ntohl(out->altcom_result); + + if (ret > 0) + { + if (ret <= len) + { + memcpy(buf, out->readdata, ret); + } + else + { + ret = -EILSEQ; + } + } + + return ret; +} + +#endif /* CONFIG_MODEM_ALT1250_LOG_ACCESS */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +compose_handler_t alt1250_composehdlr(uint32_t cmdid) +{ + int i; + compose_handler_t ret = NULL; + + for (i = 0; i < ARRAY_SZ(g_composehdlrs); i++) + { + if (g_composehdlrs[i].cmdid == cmdid) + { + ret = g_composehdlrs[i].hdlr; + } + } + + return ret; +} + +parse_handler_t alt1250_parsehdlr(uint16_t altcid, uint8_t altver) +{ + int i; + parse_handler_t ret = NULL; + + altcid &= ~ALTCOM_CMDID_REPLY_BIT; + + if (altver == ALTCOM_VER4) + { + /* Change the command ID to Version 1 */ + + altcid = convert_cid2v1(altcid); + if (altcid == APICMDID_UNKNOWN) + { + return NULL; + } + } + + for (i = 0; i < ARRAY_SZ(g_parsehdlrs); i++) + { + if (g_parsehdlrs[i].altcid == altcid) + { + ret = g_parsehdlrs[i].hdlr; + } + } + + return ret; +} diff --git a/drivers/modem/alt1250/altcom_hdlr.h b/drivers/modem/alt1250/altcom_hdlr.h new file mode 100644 index 00000000000..402dd7c6feb --- /dev/null +++ b/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 +#include + +/**************************************************************************** + * 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 */ diff --git a/drivers/modem/alt1250/altcom_lwm2m_hdlr.c b/drivers/modem/alt1250/altcom_lwm2m_hdlr.c new file mode 100644 index 00000000000..21c88ea17af --- /dev/null +++ b/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 +#include +#include +#include + +#include + +#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 +{ + FAR 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 FAR uint8_t *skip_until(FAR uint8_t *stream, FAR char *delim) +{ + for (; *stream && !strchr(delim, *stream); stream++); + for (; *stream && strchr(delim, *stream); stream++); + + if (*stream == '\0') + { + stream = NULL; + } + + return stream; +} + +/**************************************************************************** + * name: strcpy_until + ****************************************************************************/ + +static FAR char strcpy_until(char *dst, int n, char **src, char *delim) +{ + char *tmp = *src; + + if (dst) + { + dst[n - 1] = '\0'; + n--; + } + + while (*tmp && !strchr(delim, *tmp)) + { + if (dst && (n > 0)) + { + *dst++ = *tmp; + n--; + } + + tmp++; + } + + if (dst && (n > 0)) + { + *dst = '\0'; + } + + *src = tmp + 1; + + return *tmp; +} + +/**************************************************************************** + * name: parse_instance + ****************************************************************************/ + +static FAR uint8_t *parse_instance(uint8_t *pktbuf, int *seq_no, int *srv_id, + struct lwm2mstub_instance_s *inst) +{ + *seq_no = atoi((char *)pktbuf); /* for seq_no */ + pktbuf = skip_until(pktbuf, ","); + *srv_id = atoi((char *)pktbuf); /* for srv_id */ + pktbuf = skip_until(pktbuf, ","); + + /* Parse URI like /objid/objinst/resid */ + + pktbuf = skip_until(pktbuf, "/"); + inst->object_id = atoi((char *)pktbuf); + pktbuf = skip_until(pktbuf, "/"); + inst->object_inst = atoi((char *)pktbuf); + pktbuf = skip_until(pktbuf, "/"); + inst->res_id = atoi((char *)pktbuf); + + inst->res_inst = -1; + if (skip_until(pktbuf, "/") != NULL) + { + pktbuf = skip_until(pktbuf, "/"); + inst->res_inst = atoi((char *)pktbuf); + } + + pktbuf = skip_until(pktbuf, ",/\r\n"); + + return pktbuf; +} + +/**************************************************************************** + * name: read_request_hndl + ****************************************************************************/ + +static int32_t read_request_hndl(FAR uint8_t *pktbuf, size_t pktsz, + FAR void **cb_args, size_t arglen) +{ + parse_instance(pktbuf, (int *)&cb_args[0], (int *)&cb_args[1], + (struct lwm2mstub_instance_s *)(cb_args[2])); + + return 0; +} + +/**************************************************************************** + * name: write_request_hndl + ****************************************************************************/ + +static int32_t write_request_hndl(FAR uint8_t *pktbuf, size_t pktsz, + FAR void **cb_args, size_t arglen) +{ + if (!cb_args[3] && ((int)cb_args[5]) <= 0) + { + return -1; + } + + pktbuf = parse_instance(pktbuf, (int *)&cb_args[0], (int *)&cb_args[1], + (struct lwm2mstub_instance_s *)(cb_args[2])); + + if (*pktbuf == '\"') + { + pktbuf++; + } + + strcpy_until((char *)cb_args[3], (int)cb_args[5], (char **)&pktbuf, + "\",\r\n"); + + cb_args[4] = (void *)strlen((char *)cb_args[3]); + + return 0; +} + +/**************************************************************************** + * name: exec_request_hndl + ****************************************************************************/ + +static int32_t exec_request_hndl(FAR uint8_t *pktbuf, size_t pktsz, + FAR void **cb_args, size_t arglen) +{ + parse_instance(pktbuf, (int *)&cb_args[0], (int *)&cb_args[1], + (struct lwm2mstub_instance_s *)(cb_args[2])); + + return 0; +} + +/**************************************************************************** + * name: parse_observe + ****************************************************************************/ + +static uint8_t *parse_observe(uint8_t *pktbuf, int *seq_no, int *srv_id, + int tksize, char *token, + struct lwm2mstub_instance_s *inst) +{ + *seq_no = atoi((char *)pktbuf); /* for seq_no */ + pktbuf = skip_until(pktbuf, ","); + *srv_id = atoi((char *)pktbuf); /* for server id */ + pktbuf = skip_until(pktbuf, "\""); + strcpy_until(token, tksize, (char **)&pktbuf, "\""); + pktbuf = skip_until(pktbuf, ","); + pktbuf = skip_until(pktbuf, "/"); + + inst->object_id = -1; + inst->object_inst = -1; + inst->res_id = -1; + inst->res_inst = -1; + + inst->object_id = atoi((char *)pktbuf); + if (strcpy_until(NULL, 0, (char **)&pktbuf, "/\",") == '/') + { + inst->object_inst = atoi((char *)pktbuf); + if (strcpy_until(NULL, 0, (char **)&pktbuf, "/\",") == '/') + { + inst->res_id = atoi((char *)pktbuf); + if (strcpy_until(NULL, 0, (char **)&pktbuf, "/\",") == '/') + { + inst->res_inst = atoi((char *)pktbuf); + } + } + } + + return pktbuf; +} + +/**************************************************************************** + * name: start_ov_request_hndl + ****************************************************************************/ + +static int32_t start_ov_request_hndl(FAR uint8_t *pktbuf, size_t pktsz, + FAR void **cb_args, size_t arglen) +{ + struct lwm2mstub_ovcondition_s *cond + = (struct lwm2mstub_ovcondition_s *)cb_args[5]; + + parse_observe(pktbuf, + (int *)&cb_args[0], (int *)&cb_args[1], + (int)cb_args[4], (char *)cb_args[3], + (struct lwm2mstub_instance_s *)cb_args[2]); + + cond->valid_mask = 0; + + return 0; +} + +/**************************************************************************** + * name: stop_ov_request_hndl + ****************************************************************************/ + +static int32_t stop_ov_request_hndl(FAR uint8_t *pktbuf, size_t pktsz, + FAR void **cb_args, size_t arglen) +{ + parse_observe(pktbuf, + (int *)&cb_args[0], (int *)&cb_args[1], + (int)cb_args[4], (char *)cb_args[3], + (struct lwm2mstub_instance_s *)cb_args[2]); + + return 0; +} + +/**************************************************************************** + * name: fwup_srvop_handle + ****************************************************************************/ + +static int32_t fwup_srvop_handle(FAR uint8_t *pktbuf, size_t pktsz, + FAR void **cb_args, size_t arglen) +{ + uint8_t *ep; + FAR int *event = (FAR int *)&cb_args[0]; + + /* Expected unsolicited event + * %LWM2MOPEV: [,.... + * %LWM2MEV: [,.... + */ + + *event = strtol((const char *)pktbuf, (char **)&ep, 10); + if ((*event == 0) && (pktbuf == ep)) + { + return -1; + } + + return 1; +} + +/**************************************************************************** + * name: fwupdate_notice_hndl + ****************************************************************************/ + +static int32_t fwupdate_notice_hndl(FAR uint8_t *pktbuf, size_t pktsz, + FAR void **cb_args, size_t arglen) +{ + return fwup_srvop_handle(pktbuf, pktsz, cb_args, arglen); +} + +/**************************************************************************** + * name: server_op_notice_hndl + ****************************************************************************/ + +static int32_t server_op_notice_hndl(FAR uint8_t *pktbuf, size_t pktsz, + FAR void **cb_args, size_t arglen) +{ + return fwup_srvop_handle(pktbuf, pktsz, cb_args, arglen); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * name: lwm2mstub_get_handler + ****************************************************************************/ + +lwm2mstub_hndl_t lwm2mstub_get_handler(FAR uint8_t **pktbuf, size_t *pktsz, + uint32_t *lcmdid) +{ + char *head_pos; + struct urc_hdltbl_s *tbl; + size_t shift_size = 0; + + *lcmdid = 0; + tbl = urc_idhandles; + + while (tbl->head) + { + head_pos = strstr((char *)*pktbuf, tbl->head); + if (head_pos) + { + shift_size = head_pos - (char *)*pktbuf + strlen(tbl->head); + + /* Follow shift_size to advance them */ + + *pktbuf += shift_size; + *pktsz -= shift_size; + + *lcmdid = tbl->lcmdid; + return tbl->hdlr; + } + + tbl++; + } + + return NULL; +} diff --git a/drivers/modem/altair/altmdm_pm_state.h b/drivers/modem/alt1250/altcom_lwm2m_hdlr.h similarity index 61% rename from drivers/modem/altair/altmdm_pm_state.h rename to drivers/modem/alt1250/altcom_lwm2m_hdlr.h index b7f0160c5fc..5cc7bff05f3 100644 --- a/drivers/modem/altair/altmdm_pm_state.h +++ b/drivers/modem/alt1250/altcom_lwm2m_hdlr.h @@ -1,5 +1,5 @@ /**************************************************************************** - * drivers/modem/altair/altmdm_pm_state.h + * drivers/modem/alt1250/altcom_lwm2m_hdlr.h * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with @@ -18,54 +18,48 @@ * ****************************************************************************/ -#ifndef __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_STATE_H -#define __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_STATE_H - -#if defined(CONFIG_MODEM_ALTMDM) +#ifndef __DRIVERS_MODEM_ALT1250_ALTCOM_LWM2M_HDLR_H +#define __DRIVERS_MODEM_ALT1250_ALTCOM_LWM2M_HDLR_H /**************************************************************************** - * Pre-processor Definitions + * Included Files ****************************************************************************/ -#define MODEM_PM_INTERNAL_STATE_SLEEP (0) -#define MODEM_PM_INTERNAL_STATE_GOING_TO_WAKE (1) -#define MODEM_PM_INTERNAL_STATE_WAKE (2) -#define MODEM_PM_INTERNAL_STATE_GOING_TO_SLEEP (3) -#define MODEM_PM_INTERNAL_STATE_MAX (4) +#include + +#include +#include + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +typedef CODE int32_t (*lwm2mstub_hndl_t)(FAR uint8_t *, size_t, + FAR void **, size_t); /**************************************************************************** * Public Function Prototypes ****************************************************************************/ /**************************************************************************** - * Name: altmdm_pm_getstate + * Name: lwm2mstub_get_handler * * Description: - * Get current modem state. + * Get handler for lwm2m stub. + * + * Input Parameters: + * pktbuf - Pointer to the received packet. + * pktsz - Pointer to the data size after parsing the received packet. + * lcmdid - Pointer to a variable that stores the lwm2m LAPI command ID. + * + * Returned Value: + * If a lwm2m handler associated with the received packet is found, the + * function pointer of the handler is returned. If not found, returns NULL. * ****************************************************************************/ -uint32_t altmdm_pm_getstate(void); +lwm2mstub_hndl_t lwm2mstub_get_handler(FAR uint8_t **pktbuf, + FAR size_t *pktsz, + uint32_t *lcmdid); -/**************************************************************************** - * Name: altmdm_pm_getinternalstate - * - * Description: - * Get internal modem state. - * - ****************************************************************************/ - -uint32_t altmdm_pm_getinternalstate(void); - -/**************************************************************************** - * Name: altmdm_pm_setinternalstate - * - * Description: - * Set internal modem state. - * - ****************************************************************************/ - -void altmdm_pm_setinternalstate(uint32_t state); - -#endif -#endif /* __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_STATE_H */ +#endif /* __DRIVERS_MODEM_ALT1250_ALTCOM_LWM2M_HDLR_H */ diff --git a/drivers/modem/alt1250/altcom_pkt.c b/drivers/modem/alt1250/altcom_pkt.c new file mode 100644 index 00000000000..38ae6367da4 --- /dev/null +++ b/drivers/modem/alt1250/altcom_pkt.c @@ -0,0 +1,433 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_pkt.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 +#include +#include + +#include "altcom_pkt.h" + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct calculated_checksum +{ + uint16_t header_checksum; + uint16_t body_checksum; +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static uint8_t g_poweron_cmd[sizeof(struct altcom_cmdhdr_s) + + sizeof(struct altcom_cmdfooter_s)]; +static uint8_t g_seqid; +static uint16_t g_transid; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static uint16_t calc_checksum_v1(FAR uint8_t *ptr, uint16_t len) +{ + uint32_t ret = 0x00; + uint16_t calctmp = 0x00; + uint16_t i; + int is_odd = len & 0x01; + + for (i = 0; i < (len & 0xfffe); i += sizeof(uint16_t)) + { + calctmp = *((uint16_t *)(ptr + i)); + ret += ntohs(calctmp); + } + + if (is_odd) + { + ret += *(ptr + i) << 8; + } + + ret = ~((ret & 0xffff) + (ret >> 16)); + + return (uint16_t)ret; +} + +static uint16_t calc_checksum_v4(FAR uint8_t *ptr, uint16_t len) +{ + uint32_t ret = 0x00; + uint32_t calctmp = 0x00; + uint16_t i; + + /* Data accumulating */ + + for (i = 0; i < len; i++) + { + calctmp += ptr[i]; + } + + ret = ~((calctmp & 0xffff) + (calctmp >> 16)); + + return (uint16_t)ret; +} + +static inline void set_header_top(FAR struct altcom_cmdhdr_s *hdr, + uint8_t ver, uint16_t cid) +{ + hdr->magic = htonl(ALTCOM_HDR_MAGICNUMBER); + hdr->ver = ver; + hdr->seqid = g_seqid++; + hdr->cmdid = htons(cid); + hdr->transid = htons(g_transid++); + hdr->datalen = 0; +} + +static struct calculated_checksum convert_ntoh( + FAR struct altcom_cmdhdr_s *hdr) +{ + struct calculated_checksum checksum; + + hdr->cmdid = ntohs(hdr->cmdid); + hdr->transid = ntohs(hdr->transid); + hdr->datalen = ntohs(hdr->datalen); + + if (hdr->ver == ALTCOM_VER1) + { + /* Only V1 has footer */ + + hdr->v1_options = ntohs(hdr->v1_options); + hdr->v1_checksum = ntohs(hdr->v1_checksum); + + struct altcom_cmdfooter_s *footer + = (struct altcom_cmdfooter_s *)&hdr->payload[hdr->datalen]; + + checksum.body_checksum = calc_checksum_v1(&hdr->payload[0], + sizeof(struct altcom_cmdfooter_s)-2 + hdr->datalen); + + footer->reserve = ntohs(footer->reserve); + footer->checksum = ntohs(footer->checksum); + } + else + { + hdr->v4_hdr_cksum = ntohs(hdr->v4_hdr_cksum); + + checksum.body_checksum = calc_checksum_v4(&hdr->payload[0], + hdr->datalen); + + hdr->v4_data_cksum = ntohs(hdr->v4_data_cksum); + } + + return checksum; +} + +static int check_valid_pkt(FAR struct altcom_cmdhdr_s *hdr, + uint16_t body_checksum) +{ + int valid_version = ALTCOM_VERX; + + if (hdr->ver == ALTCOM_VER1) + { + struct altcom_cmdfooter_s *footer + = (struct altcom_cmdfooter_s *)&hdr->payload[hdr->datalen]; + + if (footer->checksum == body_checksum) + { + valid_version = ALTCOM_VER1; + } + else + { + m_err("[V1] cmdid: 0x%04x cmdlen: %d, " + "body checksum: 0x%04x/0x%04x\n", + hdr->cmdid, hdr->datalen, + footer->checksum, body_checksum); + } + } + else if(hdr->ver == ALTCOM_VER4) + { + if (hdr->v4_data_cksum == body_checksum) + { + valid_version = ALTCOM_VER4; + } + else + { + m_err("[V4] cmdid: 0x%04x cmdlen: %d, " + "body checksum: 0x%04x/0x%04x\n", + hdr->cmdid, hdr->datalen, + hdr->v4_data_cksum, body_checksum); + } + } + + return valid_version; +} + +static int check_valid_reply(FAR struct altcom_cmdhdr_s *hdr, + uint16_t body_checksum) +{ + int valid_version = ALTCOM_VERX; + + valid_version = check_valid_pkt(hdr, body_checksum); + if (valid_version == ALTCOM_VER1) + { + if ((hdr->cmdid == (ALTCOM_CMDID_POWER_ON_V1 | ALTCOM_CMDID_REPLY_BIT)) + && (hdr->datalen == ALTCOM_CMD_POWER_ON_REPLY_SIZE)) + { + valid_version = ALTCOM_VER1; + } + else + { + valid_version = ALTCOM_VERX; + } + } + else if(valid_version == ALTCOM_VER4) + { + if ((hdr->cmdid == (ALTCOM_CMDID_POWER_ON_V4 | ALTCOM_CMDID_REPLY_BIT)) + && (hdr->datalen == ALTCOM_CMD_POWER_ON_REPLY_SIZE)) + { + valid_version = ALTCOM_VER4; + } + else + { + valid_version = ALTCOM_VERX; + } + } + + return valid_version; +} + +static bool is_header_ok(FAR struct altcom_cmdhdr_s *hdr) +{ + uint16_t checksum; + + if (hdr->ver == ALTCOM_VER1) + { + checksum = calc_checksum_v1((uint8_t *)hdr, + sizeof(struct altcom_cmdhdr_s) - sizeof(hdr->v1_checksum)); + if (ntohs(hdr->v1_checksum) == checksum) + { + if (ntohs(hdr->datalen) + sizeof(struct altcom_cmdhdr_s) + + sizeof(struct altcom_cmdfooter_s) <= ALTCOM_RX_PKT_SIZE_MAX) + { + return true; + } + else + { + m_err("[V1] Data length exceeding the buffer length: %d\n", + ntohs(hdr->datalen)); + } + } + else + { + m_err("[V1] cmdid: 0x%04x cmdlen: %d, " + "header checksum: 0x%04x/0x%04x\n", + ntohs(hdr->cmdid), ntohs(hdr->datalen), + ntohs(hdr->v1_checksum), checksum); + } + } + else if (hdr->ver == ALTCOM_VER4) + { + checksum = calc_checksum_v4((uint8_t *)hdr, + sizeof(struct altcom_cmdhdr_s) - sizeof(hdr->v4_hdr_cksum) - + sizeof(hdr->v4_data_cksum)); + if (ntohs(hdr->v4_hdr_cksum) == checksum) + { + if (ntohs(hdr->datalen) + sizeof(struct altcom_cmdhdr_s) <= + ALTCOM_RX_PKT_SIZE_MAX) + { + return true; + } + else + { + m_err("[V4] Data length exceeding the buffer length: %d\n", + ntohs(hdr->datalen)); + } + } + else + { + m_err("[V4] cmdid: 0x%04x cmdlen: %d, " + "header checksum: 0x%04x/0x%04x\n", + ntohs(hdr->cmdid), ntohs(hdr->datalen), + ntohs(hdr->v4_hdr_cksum), checksum); + } + } + + return false; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +bool altcom_is_v1pkt_ok(struct altcom_cmdhdr_s *cmdhdr) +{ + struct calculated_checksum checksum; + + if (!is_header_ok(cmdhdr)) + { + return false; + } + + checksum = convert_ntoh(cmdhdr); + return (check_valid_reply(cmdhdr, checksum.body_checksum) == ALTCOM_VER1) + && (cmdhdr->payload[0] == LTE_RESULT_OK); +} + +bool altcom_is_v4pkt_ok(struct altcom_cmdhdr_s *cmdhdr) +{ + struct calculated_checksum checksum; + + if (!is_header_ok(cmdhdr)) + { + return false; + } + + checksum = convert_ntoh(cmdhdr); + return (check_valid_reply(cmdhdr, checksum.body_checksum) == ALTCOM_VER4) + && (cmdhdr->payload[0] == LTE_RESULT_OK); +} + +FAR void *altcom_make_poweron_cmd_v1(int *sz) +{ + struct altcom_cmdhdr_s *hdr = (struct altcom_cmdhdr_s *)g_poweron_cmd; + struct altcom_cmdfooter_s *footer + = (struct altcom_cmdfooter_s *)&hdr->payload[0]; + + set_header_top(hdr, ALTCOM_VER1, ALTCOM_CMDID_POWER_ON_V1); + hdr->v1_options = htons(ALTCOM_CMDOPT_CHECKSUM_EN); + hdr->v1_checksum = + htons(calc_checksum_v1((uint8_t *)hdr, + sizeof(struct altcom_cmdhdr_s) - 2)); + + footer->reserve = 0; + footer->checksum = + htons(calc_checksum_v1(&hdr->payload[0], + sizeof(struct altcom_cmdfooter_s) - 2)); + + /* No payload of this altcom command. + * So sending size is just header and footer size + */ + + *sz = sizeof(struct altcom_cmdhdr_s) + sizeof(struct altcom_cmdfooter_s); + + return g_poweron_cmd; +} + +FAR void *altcom_make_poweron_cmd_v4(int *sz) +{ + struct altcom_cmdhdr_s *hdr = (struct altcom_cmdhdr_s *)g_poweron_cmd; + + set_header_top(hdr, ALTCOM_VER4, ALTCOM_CMDID_POWER_ON_V4); + hdr->v4_hdr_cksum = htons(calc_checksum_v4((uint8_t *)hdr, + sizeof(struct altcom_cmdhdr_s)-4)); + hdr->v4_data_cksum = htons(calc_checksum_v4(&hdr->payload[0], 0)); + + /* No payload of this altcom command. So sending size is just header size */ + + *sz = sizeof(struct altcom_cmdhdr_s); + + return g_poweron_cmd; +} + +int altcom_is_pkt_ok(FAR uint8_t *pkt, int sz) +{ + struct calculated_checksum checksum; + int ver; + int ret = OK; + FAR struct altcom_cmdhdr_s *hdr = (FAR struct altcom_cmdhdr_s *)pkt; + int remlen; + + if (!is_header_ok(hdr)) + { + return -EPROTO; + } + + remlen = get_pktlen(hdr->ver, ntohs(hdr->datalen)) - sz; + if (remlen > 0) + { + /* Cases in which fragmented packets are received. */ + + return remlen; + } + else if (remlen < 0) + { + /* The case where the received data length becomes + * larger than the payload length set in the header. + */ + + return -EPROTO; + } + + /* Whole packets are received. So check the validity of the packets. */ + + checksum = convert_ntoh((FAR struct altcom_cmdhdr_s *)pkt); + + ver = check_valid_pkt((FAR struct altcom_cmdhdr_s *)pkt, + checksum.body_checksum); + if (ver == ALTCOM_VERX) + { + ret = -EPROTO; + } + + return ret; +} + +uint16_t altcom_make_header(FAR struct altcom_cmdhdr_s *hdr, + uint8_t ver, uint16_t cid, uint16_t sz) +{ + uint16_t tid = g_transid; + + hdr->magic = htonl(ALTCOM_HDR_MAGICNUMBER); + hdr->ver = ver; + hdr->seqid = g_seqid++; + hdr->cmdid = htons(cid); + hdr->transid = htons(g_transid++); + hdr->datalen = htons(sz); + + if (ver == ALTCOM_VER1) + { + struct altcom_cmdfooter_s *footer + = (struct altcom_cmdfooter_s *)&hdr->payload[sz]; + + hdr->v1_options = htons(ALTCOM_CMDOPT_CHECKSUM_EN); + hdr->v1_checksum = + htons(calc_checksum_v1((uint8_t *)hdr, + sizeof(struct altcom_cmdhdr_s) - 2)); + + footer->reserve = 0; + footer->checksum = + htons(calc_checksum_v1(&hdr->payload[0], + sizeof(struct altcom_cmdfooter_s) - 2 + sz)); + } + else if (ver == ALTCOM_VER4) + { + hdr->v4_hdr_cksum = htons(calc_checksum_v4((uint8_t *)hdr, + sizeof(struct altcom_cmdhdr_s)-4)); + hdr->v4_data_cksum = htons(calc_checksum_v4(&hdr->payload[0], sz)); + } + else + { + DEBUGASSERT(0); + } + + return tid; +} diff --git a/drivers/modem/alt1250/altcom_pkt.h b/drivers/modem/alt1250/altcom_pkt.h new file mode 100644 index 00000000000..531af086873 --- /dev/null +++ b/drivers/modem/alt1250/altcom_pkt.h @@ -0,0 +1,414 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_pkt.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __DRIVERS_MODEM_ALT1250_ALTCOM_PKT_H +#define __DRIVERS_MODEM_ALT1250_ALTCOM_PKT_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +#include +#include +#include +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define ALTCOM_HDR_MAGICNUMBER (0xFEEDBAC5) + +#define ALTCOM_CMDOPT_CHECKSUM_EN (1 << 0) + +#define ALTCOM_PAYLOAD_SIZE_MAX (4112) +#define ALTCOM_PAYLOAD_SIZE_MAX_V4 (3092) +#define ALTCOM_PKT_SIZE_MAX (ALTCOM_PAYLOAD_SIZE_MAX \ + + sizeof(struct altcom_cmdhdr_s) \ + + sizeof(struct altcom_cmdfooter_s)) +#define ALTCOM_RX_PKT_SIZE_MAX (ALTCOM_PAYLOAD_SIZE_MAX_V4 \ + + sizeof(struct altcom_cmdhdr_s)) + +#define LTE_RESULT_OK (0) /**< Result code on success */ +#define LTE_RESULT_ERROR (1) /**< Result code on failure */ +#define LTE_RESULT_CANCEL (2) /**< Result code on cancel */ + +#define ALTCOM_CMD_POWER_ON_REPLY_SIZE (1) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +begin_packed_struct struct altcom_cmdhdr_s +{ + uint32_t magic; + uint8_t ver; + uint8_t seqid; + uint16_t cmdid; + uint16_t transid; + uint16_t datalen; + union + { + uint16_t v1_options; + uint16_t v4_hdr_cksum; + }; + union + { + uint16_t v1_checksum; + uint16_t v4_data_cksum; + }; + uint8_t payload[0]; +} end_packed_struct; + +begin_packed_struct struct altcom_cmdfooter_s +{ + uint16_t reserve; + uint16_t checksum; +} end_packed_struct; + +begin_packed_struct struct altcom_errind_s +{ + uint8_t ver; + uint8_t seqid; + uint16_t cmdid; + uint16_t transid; + uint16_t dtlen; + union + { + uint16_t v1_options; + uint16_t v4_hdr_cksum; + }; + union + { + uint16_t v1_checksum; + uint16_t v4_data_cksum; + }; +} end_packed_struct; + +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +static inline int is_errind(uint16_t cmdid) +{ + return (cmdid == ALTCOM_CMDID_ERRIND); +} + +static inline uint16_t parse_cid(FAR struct altcom_cmdhdr_s *hdr) +{ + return hdr->cmdid; +} + +static inline uint16_t parse_tid(FAR struct altcom_cmdhdr_s *hdr) +{ + return hdr->transid; +} + +static inline uint16_t parse_cid4errind(FAR struct altcom_cmdhdr_s *hdr) +{ + FAR struct altcom_errind_s *pkt = + (FAR struct altcom_errind_s *)&hdr->payload[0]; + + return ntohl(pkt->cmdid); +} + +static inline uint16_t parse_tid4errind(FAR struct altcom_cmdhdr_s *hdr) +{ + FAR struct altcom_errind_s *pkt = + (FAR struct altcom_errind_s *)&hdr->payload[0]; + + return ntohl(pkt->transid); +} + +static inline FAR uint8_t *get_payload(FAR struct altcom_cmdhdr_s *hdr) +{ + return &hdr->payload[0]; +} + +static inline uint16_t get_payload_len(FAR struct altcom_cmdhdr_s *hdr) +{ + return hdr->datalen; +} + +static inline FAR uint8_t get_altver(FAR struct altcom_cmdhdr_s *hdr) +{ + return hdr->ver; +} + +static inline uint16_t get_pktlen(uint8_t ver, uint16_t payloadlen) +{ + if (ver == ALTCOM_VER1) + { + payloadlen += sizeof(struct altcom_cmdhdr_s) + + sizeof(struct altcom_cmdfooter_s); + } + else if (ver == ALTCOM_VER4) + { + payloadlen += sizeof(struct altcom_cmdhdr_s); + } + else + { + DEBUGASSERT(0); + } + + return payloadlen; +} + +static inline uint16_t convert_cid2v1(uint16_t cid) +{ + if ((cid >= APICMDID_SOCK_ACCEPT) && (cid <= APICMDID_SOCK_SETSOCKOPT)) + { + return cid; + } + + if ((cid >= APICMDID_SMS_INIT) && (cid <= APICMDID_SMS_DELETE)) + { + return cid; + } + + if ((cid >= APICMDID_GET_VERSION_V4) && (cid <= APICMDID_SET_PSM_V4)) + { + return (cid + 1); + } + + if ((cid >= APICMDID_RADIO_ON_V4) && (cid <= APICMDID_ACTIVATE_PDN_V4)) + { + return (cid - 0x2ec); + } + + if ((cid >= APICMDID_DEACTIVATE_PDN_V4) && + (cid <= APICMDID_REPORT_NETINFO_V4)) + { + return (cid - 0x2ed); + } + + if (cid == (APICMDID_ERRINFO_V4 & ~ALTCOM_CMDID_REPLY_BIT)) + { + return APICMDID_ERRINFO; + } + + if (cid == APICMDID_GET_SIMINFO_V4) + { + return APICMDID_GET_SIMINFO; + } + + if (cid == APICMDID_GET_QUALITY_V4) + { + return APICMDID_GET_QUALITY; + } + + if (cid == APICMDID_ACTIVATE_PDN_CANCEL_V4) + { + return APICMDID_ACTIVATE_PDN_CANCEL; + } + + if (cid == APICMDID_GET_CELLINFO_V4) + { + return APICMDID_GET_CELLINFO; + } + + if (cid == APICMDID_GET_RAT_V4) + { + return APICMDID_GET_RAT; + } + + if (cid == APICMDID_SET_RAT_V4) + { + return APICMDID_SET_RAT; + } + + if (cid == APICMDID_SEND_ATCMD_V4) + { + return APICMDID_SEND_ATCMD; + } + + if (cid == APICMDID_URC_EVENT_V4) + { + return APICMDID_URC_EVENT; + } + + if ((cid >= APICMDID_FW_INJECTDELTAIMG_V4) && + (cid <= APICMDID_FW_GETUPDATERESULT_V4)) + { + return (cid + 0xdd0); + } + + if (cid == APICMDID_TLS_CONFIG_VERIFY_CALLBACK_V4) + { + return APICMDID_TLS_CONFIG_VERIFY_CALLBACK; + } + + if (cid == APICMDID_CLOGS_V4) + { + return APICMDID_CLOGS; + } + + if (cid == APICMDID_LOGLIST_V4) + { + return APICMDID_LOGLIST; + } + +#ifdef CONFIG_MODEM_ALT1250_LOG_ACCESS + if ((cid >= APICMDID_LOGOPEN_V4) && (cid <= APICMDID_LOGLSEEK_V4)) + { + return cid + (APICMDID_LOGOPEN - APICMDID_LOGOPEN_V4); + } +#endif /* CONFIG_MODEM_ALT1250_LOG_ACCESS */ + + return APICMDID_UNKNOWN; +} + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: altcom_make_poweron_cmd_v1 + * + * Description: + * Create an ALTCOM command for POWER_ON_REQ of protocol version 1. + * + * Input Parameters: + * sz - Variable to put the length of the command created. + * + * Returned Value: + * Returns the buffer pointer of the created command. + * + ****************************************************************************/ + +FAR void *altcom_make_poweron_cmd_v1(FAR int *sz); + +/**************************************************************************** + * Name: altcom_make_poweron_cmd_v4 + * + * Description: + * Create an ALTCOM command for POWER_ON_REQ of protocol version 4. + * + * Input Parameters: + * sz - Variable to put the length of the command created. + * + * Returned Value: + * Returns the buffer pointer of the created command. + * + ****************************************************************************/ + +FAR void *altcom_make_poweron_cmd_v4(FAR int *sz); + +/**************************************************************************** + * Name: altcom_is_v1pkt_ok + * + * Description: + * Check if the POWER_ON_RES command of protocol version 1 is OK. + * + * Input Parameters: + * cmdhdr - Pointer to the received packet. + * + * Returned Value: + * Returns true if the POWER_ON_RES command of protocol version 1 is OK, + * false otherwise. + * + ****************************************************************************/ + +bool altcom_is_v1pkt_ok(FAR struct altcom_cmdhdr_s *cmdhdr); + +/**************************************************************************** + * Name: altcom_is_v4pkt_ok + * + * Description: + * Check if the POWER_ON_RES command of protocol version 4 is OK. + * + * Input Parameters: + * cmdhdr - Pointer to the received packet. + * + * Returned Value: + * Returns true if the POWER_ON_RES command of protocol version 4 is OK, + * false otherwise. + * + ****************************************************************************/ + +bool altcom_is_v4pkt_ok(FAR struct altcom_cmdhdr_s *cmdhdr); + +/**************************************************************************** + * Name: altcom_is_pkt_ok + * + * Description: + * Check the validity of the ALTCOM command received from ALT1250. + * In the case of a fragmented packet, returns the length of the remaining + * fragmented packets. + * + * Input Parameters: + * pkt - Pointer to the received packet. + * sz - Size of received packets. + * + * Returned Value: + * If the received packet is valid, 0 is returned. If the received packet + * is a fragmented packet, the length of the remaining fragmented packet is + * returned. If the received packet is not valid, a negative value is + * returned. + * + ****************************************************************************/ + +int altcom_is_pkt_ok(FAR uint8_t *pkt, int sz); + +/**************************************************************************** + * Name: altcom_set_header_top + * + * Description: + * Set the version and command ID among the ALTCOM command headers. + * + * Input Parameters: + * hdr - Pointer to ALTCOM command header. + * ver - ALTCOM protocol version. + * cid - ALTCOM command ID. + * + * Returned Value: + * None + * + ****************************************************************************/ + +void altcom_set_header_top(FAR struct altcom_cmdhdr_s *hdr, + uint8_t ver, uint16_t cid); + +/**************************************************************************** + * Name: altcom_make_header + * + * Description: + * Create ALTCOM command header. + * + * Input Parameters: + * hdr - Pointer to ALTCOM command header. + * ver - ALTCOM protocol version. + * cid - ALTCOM command ID. + * sz - Body size of the ALTCOM command. + * + * Returned Value: + * Returns the transaction ID of the ALTCOM command. + * + ****************************************************************************/ + +uint16_t altcom_make_header(FAR struct altcom_cmdhdr_s *hdr, + uint8_t ver, uint16_t cid, uint16_t sz); + +#endif /* __DRIVERS_MODEM_ALT1250_ALTCOM_PKT_H */ diff --git a/drivers/modem/alt1250/altmdm.c b/drivers/modem/alt1250/altmdm.c new file mode 100644 index 00000000000..01a05da6c40 --- /dev/null +++ b/drivers/modem/alt1250/altmdm.c @@ -0,0 +1,1743 @@ +/**************************************************************************** + * drivers/modem/alt1250/altmdm.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 + +#if defined(CONFIG_MODEM_ALT1250) + +#include +#include +#include +#include +#include +#include + +#include /* for ALTCOM_VERx */ + +#include "altmdm.h" +#include "altmdm_event.h" +#include "altmdm_spi.h" +#include "altmdm_timer.h" +#include "altcom_pkt.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define EVENT_POWERON (1 << 0) +#define EVENT_POWEROFF (1 << 1) +#define EVENT_RESET (1 << 2) +#define EVENT_WLOCK (1 << 3) +#define EVENT_TXREQ (1 << 4) +#define EVENT_RXREQ (1 << 5) +#define EVENT_TXSUSTO (1 << 6) +#define EVENT_DESTROY (1 << 7) + +#define TX_DONE (1 << 0) +#define TX_CANCEL (1 << 1) + +#define RESET_INTERVAL (50*1000) +#define TXSUS_TIMEOUT (100) +#define TIMEOUT_IDELEWTO_STATE (20) /* Sleep timer */ +#define TIMEOUT_HDR_TRX_STATE (5000) +#define TIMEOUT_BODY_TRX_STATE (5) +#define TIMEOUT_NEXT_DELAY (300) + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +typedef enum altmdm_state_e +{ + ALTMDM_STATE_POWEROFF = 0, /* Modem Power Off state */ + ALTMDM_STATE_SLEEP, /* Modem Sleep state */ + ALTMDM_STATE_SLEEPWOTX, /* Modem Sleep with Tx suspend state */ + ALTMDM_STATE_IDLE4RST, /* Idle for Reset transaction state */ + ALTMDM_STATE_IDLEWTO, /* Idle with Sleep Time Out state */ + ALTMDM_STATE_IDLEWOTO, /* Idle without Sleep Time Out state */ + ALTMDM_STATE_IDLEWOTX, /* Idle with Tx suspend */ + ALTMDM_STATE_V1SET, /* Altcom version 1 command setting state */ + ALTMDM_STATE_V4SET, /* Altcom version 4 command setting state */ + ALTMDM_STATE_SLEEPSET, /* Sleep packet setting state */ + ALTMDM_STATE_TXPREPARE, /* Normal packet setting state */ + ALTMDM_STATE_TXREQ, /* TX request signal assersion state */ + ALTMDM_STATE_HDRSREQ, /* Waiting for Slave request signal state */ + ALTMDM_STATE_HDRTRX, /* SPI Header transaction state */ + ALTMDM_STATE_SLEEPPKT, /* Sleep Packet body size adjustment + * state */ + ALTMDM_STATE_BODYSREQ, /* Waiting for Slave request signal for body + * state */ + ALTMDM_STATE_BODYTRX, /* SPI body transaction state */ + ALTMDM_STATE_GOTRX, /* Received normal body state */ + ALTMDM_STATE_GOTRST, /* Received reset pakcet body state */ + ALTMDM_STATE_GOTSLEEP, /* Received sleep packet body state */ + ALTMDM_STATE_BACKTOIDLE, /* Back to Idle state */ + ALTMDM_STATE_RETRECV, /* Return state */ + ALTMDM_STATE_FORCERST, /* Modem force reset state */ + ALTMDM_STATE_SLEEPING, /* Waiting for transition to sleep state */ + ALTMDM_STATE_DECIDEDELAY, /* Determine if there is a need to delay for + * next TRX */ + ALTMDM_STATE_DELAYNEXT, /* Delayed state for the next TRX */ + ALTMDM_STATE_SETSUSTIMER, /* Start TX suspend timer state */ + ALTMDM_STATE_SETSUSTIMERSLEEP, /* Start TX suspend timer when sleep + * state */ + ALTMDM_STATE_DESTORY, /* State to be destroyed */ +} altmdm_state_t; + +typedef enum version_phase_e +{ + VP_NO_RESET, /* Reset packet is not received */ + VP_V1 = ALTCOM_VER1, /* Confirmed Altcom version is 1 */ + VP_V4 = ALTCOM_VER4, /* Confirmed Altcom version is 4 */ + VP_UNKNOWN, /* Altcom version is unknown */ + VP_TRYV1, /* Try sending version 1 packet */ + VP_NOTV1, /* Trial of version 1 packet is fail */ + VP_TRYV4, /* Try sending version 4 packet */ +} version_phase_t; + +struct state_func_s +{ + int (*goto_next)(altmdm_state_t); + uint32_t (*wait_event)(void); + altmdm_state_t (*process_state)(uint32_t, altmdm_state_t); +#ifdef CONFIG_MODEM_ALT1250_DEBUG + const char *name; +#endif +}; + +typedef struct altmdm_dev_s +{ + sem_t lock_evt; + struct altmdm_event_s event; + sem_t lock_vp; + version_phase_t vp; + sem_t lock_counter; + int wcounter; + FAR struct spi_dev_s *spidev; + const struct alt1250_lower_s *lower; + timer_t txsus_timer; + altmdm_state_t current_state; + altmdm_spipkt_t tx_pkt; + altmdm_spipkt_t rx_pkt; + int rx_retcode; + struct altmdm_event_s txdone_event; + sem_t lock_txreq; + void *txreq_buff; + int txreq_size; + int is_destroy; + uint32_t reset_reason; +} altmdm_dev_t; + +/**************************************************************************** + * Private Function Prototypes + ****************************************************************************/ + +static int next_state_common(altmdm_state_t); + +static int next_state_poweroff(altmdm_state_t); +static int next_state_sleep(altmdm_state_t); +static int next_state_sleepwotx(altmdm_state_t); +static int next_state_idle4rst(altmdm_state_t); +static int next_state_idlewto(altmdm_state_t); +static int next_state_idlewoto(altmdm_state_t); +static int next_state_idlewotx(altmdm_state_t); +static int next_state_decidedelay(altmdm_state_t); +static int next_state_destroy(altmdm_state_t); + +static uint32_t waitevt_state_common(void); + +static uint32_t waitevt_state_poweroff(void); +static uint32_t waitevt_state_sleep(void); +static uint32_t waitevt_state_sleepwotx(void); +static uint32_t waitevt_state_idle4rst(void); +static uint32_t waitevt_state_idlewto(void); +static uint32_t waitevt_state_idlewoto(void); +static uint32_t waitevt_state_idlewotx(void); +static uint32_t waitevt_state_hdrsreq(void); +static uint32_t waitevt_state_bodysreq(void); +static uint32_t waitevt_state_sleeping(void); +static uint32_t waitevt_state_delaynext(void); + +static altmdm_state_t process_state_common(uint32_t, altmdm_state_t); + +static altmdm_state_t process_state_poweroff(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_sleep(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_sleepwotx(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_idle4rst(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_idlewto(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_idlewoto(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_idlewotx(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_v1set(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_v4set(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_sleepset(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_txprepare(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_txreq(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_hdrsreq(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_hdrtrx(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_sleeppkt(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_bodysreq(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_bodytrx(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_gotrx(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_gotrst(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_gotsleep(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_backtoidle(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_retrecv(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_forcerst(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_sleeping(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_decidedelay(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_delaynext(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_setsustimer(uint32_t, altmdm_state_t); +static altmdm_state_t process_state_setsustimersleep(uint32_t, + altmdm_state_t); + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#ifndef CONFIG_MODEM_ALT1250_DEBUG +# define TABLE_CONTENT(array_name, namea, nameb, namec) \ + [ALTMDM_STATE_##array_name] = \ + { next_state_##namea, waitevt_state_##nameb, process_state_##namec } +#else +# define TABLE_CONTENT(array_name, namea, nameb, namec) \ + [ALTMDM_STATE_##array_name] = \ + { next_state_##namea, waitevt_state_##nameb, process_state_##namec, \ + #array_name } + +static char *g_vp_name[] = +{ + "NO_RESET", "V1 ", "", "", + "V4 ", "UNKNOWN ", "TRYV1 ", "NOTV1 ", + "TRYV4 " +}; +#endif + +/* State functions instance table */ + +static const struct state_func_s g_state_func[] = +{ + TABLE_CONTENT(POWEROFF, poweroff, poweroff, poweroff), + TABLE_CONTENT(SLEEP, sleep, sleep, sleep), + TABLE_CONTENT(SLEEPWOTX, sleepwotx, sleepwotx, sleepwotx), + TABLE_CONTENT(IDLE4RST, idle4rst, idle4rst, idle4rst), + TABLE_CONTENT(IDLEWTO, idlewto, idlewto, idlewto), + TABLE_CONTENT(IDLEWOTO, idlewoto, idlewoto, idlewoto), + TABLE_CONTENT(IDLEWOTX, idlewotx, idlewotx, idlewotx), + TABLE_CONTENT(V1SET, common, common, v1set), + TABLE_CONTENT(V4SET, common, common, v4set), + TABLE_CONTENT(SLEEPSET, common, common, sleepset), + TABLE_CONTENT(TXPREPARE, common, common, txprepare), + TABLE_CONTENT(TXREQ, common, common, txreq), + TABLE_CONTENT(HDRSREQ, common, hdrsreq, hdrsreq), + TABLE_CONTENT(HDRTRX, common, common, hdrtrx), + TABLE_CONTENT(SLEEPPKT, common, common, sleeppkt), + TABLE_CONTENT(BODYSREQ, common, bodysreq, bodysreq), + TABLE_CONTENT(BODYTRX, common, common, bodytrx), + TABLE_CONTENT(GOTRX, common, common, gotrx), + TABLE_CONTENT(GOTRST, common, common, gotrst), + TABLE_CONTENT(GOTSLEEP, common, common, gotsleep), + TABLE_CONTENT(BACKTOIDLE, common, common, backtoidle), + TABLE_CONTENT(RETRECV, common, common, retrecv), + TABLE_CONTENT(FORCERST, common, common, forcerst), + TABLE_CONTENT(SLEEPING, common, sleeping, sleeping), + TABLE_CONTENT(DECIDEDELAY, decidedelay, common, decidedelay), + TABLE_CONTENT(DELAYNEXT, common, delaynext, delaynext), + TABLE_CONTENT(SETSUSTIMER, common, common, setsustimer), + TABLE_CONTENT(SETSUSTIMERSLEEP, common, common, setsustimersleep), + TABLE_CONTENT(DESTORY, destroy, common, common), +}; + +static struct altmdm_dev_s g_altmdm_dev; + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#ifdef CONFIG_MODEM_ALT1250_DEBUG +static void dump_current_all_status(altmdm_dev_t *dev, uint32_t evt, + altmdm_state_t next, int is_exit) +{ + m_info("state[%s => %s], vp[%s], event out[%08lx]:cur[%08lx], " + "wcount=%2d, txreq_buf=%s, txreq_sz=%4d, " + "tx_hdr=%08lx, rx_hdr=%08lx, exit=%s\n", + g_state_func[dev->current_state].name, g_state_func[next].name, + g_vp_name[dev->vp], evt, dev->event.event, dev->wcounter, + dev->txreq_buff == NULL ? "No-req " : "Request", dev->txreq_size, + dev->tx_pkt.header, dev->rx_pkt.header, is_exit ? "Yes" : "No "); +} +#else +# define dump_current_all_status(...) +#endif + +static int sready_isr(int irq, FAR void *context, FAR void *arg) +{ + altmdm_event_set(&g_altmdm_dev.event, EVENT_RXREQ); + + return 0; +} + +static void txsustimer_handler(int signo, FAR siginfo_t *info, + FAR void *uctx) +{ + FAR struct altmdm_dev_s *priv = + (FAR struct altmdm_dev_s *)(info->si_value.sival_ptr); + + altmdm_event_set(&priv->event, EVENT_TXSUSTO); +} + +/**************************************************************************** + * get wakelock count function + ****************************************************************************/ + +static int get_wlock_count(void) +{ + int cnt; + + nxsem_wait_uninterruptible(&g_altmdm_dev.lock_counter); + cnt = g_altmdm_dev.wcounter; + nxsem_post(&g_altmdm_dev.lock_counter); + + return cnt; +} + +/**************************************************************************** + * Version Phase access functions + ****************************************************************************/ + +static enum version_phase_e get_vp(void) +{ + enum version_phase_e vp; + + nxsem_wait_uninterruptible(&g_altmdm_dev.lock_vp); + vp = g_altmdm_dev.vp; + nxsem_post(&g_altmdm_dev.lock_vp); + + return vp; +} + +static void set_vp(enum version_phase_e vp) +{ + nxsem_wait_uninterruptible(&g_altmdm_dev.lock_vp); + g_altmdm_dev.vp = vp; + nxsem_post(&g_altmdm_dev.lock_vp); +} + +static bool is_vp_valid(void) +{ + enum version_phase_e vp; + vp = get_vp(); + return (vp == VP_V1 || vp == VP_V4); +} + +static bool is_vp_noreset(void) +{ + return (get_vp() == VP_NO_RESET); +} + +/**************************************************************************** + * return code setting function + ****************************************************************************/ + +static void set_return_code(int code) +{ + g_altmdm_dev.rx_retcode = code; +} + +/**************************************************************************** + * reset reason setting/getting functions + ****************************************************************************/ + +static void set_reset_reason(uint32_t reason) +{ + g_altmdm_dev.reset_reason = reason; +} + +static uint32_t get_reset_reason(void) +{ + return g_altmdm_dev.reset_reason; +} + +/**************************************************************************** + * tx done function + ****************************************************************************/ + +static void tx_done(uint32_t result) +{ + nxsem_wait_uninterruptible(&g_altmdm_dev.lock_txreq); + g_altmdm_dev.txreq_buff = NULL; + g_altmdm_dev.txreq_size = 0; + altmdm_event_clear(&g_altmdm_dev.event, EVENT_TXREQ); + altmdm_event_set(&g_altmdm_dev.txdone_event, result); + nxsem_post(&g_altmdm_dev.lock_txreq); +} + +/**************************************************************************** + * converts unit of timer function + ****************************************************************************/ + +static void usec2timespec(useconds_t usec, FAR struct timespec *timespec) +{ + time_t sec; + + sec = usec / 1000000; + timespec->tv_sec = sec; + timespec->tv_nsec = (usec - (sec * 1000000)) * 1000; +} + +static void process_before_poweroff(void) +{ + uint32_t allevt = (uint32_t)(-1); + + set_vp(VP_NO_RESET); + altmdm_timer_restart(g_altmdm_dev.txsus_timer, 0, 0); + + /* Cancel tx request. */ + + tx_done(TX_CANCEL); + + /* clear event without EVENT_POWERON */ + + altmdm_event_clear(&g_altmdm_dev.event, (allevt & ~(EVENT_POWERON))); + g_altmdm_dev.lower->irqenable(false); + g_altmdm_dev.lower->set_wakeup(false); + g_altmdm_dev.lower->set_mready(false); +} + +/**************************************************************************** + * force reset function + ****************************************************************************/ + +static void force_reset(void) +{ + if (is_vp_valid()) + { + set_reset_reason(LTE_RESTART_MODEM_INITIATED); + } + + process_before_poweroff(); + g_altmdm_dev.lower->reset(); + g_altmdm_dev.lower->irqenable(true); +} + +/**************************************************************************** + * State common functions + ****************************************************************************/ + +static int next_state_common(altmdm_state_t state) +{ + return 0; +} + +static uint32_t waitevt_state_common(void) +{ + return 0; +} + +static altmdm_state_t process_state_common(uint32_t event, + altmdm_state_t state) +{ + return state; +} + +/**************************************************************************** + * On POWEROFF state + ****************************************************************************/ + +static int next_state_poweroff(altmdm_state_t state) +{ + process_before_poweroff(); + g_altmdm_dev.lower->poweroff(); + + return 0; +} + +static uint32_t waitevt_state_poweroff(void) +{ + return altmdm_event_wait(&g_altmdm_dev.event, + EVENT_POWERON | EVENT_DESTROY, false, 0); +} + +static altmdm_state_t process_state_poweroff(uint32_t event, + altmdm_state_t state) +{ + struct timespec interval; + + if (event & EVENT_DESTROY) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_DESTROY); + state = ALTMDM_STATE_DESTORY; + } + else if (event & EVENT_POWERON) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_POWERON); + usec2timespec(RESET_INTERVAL, &interval); + nxsig_nanosleep(&interval, NULL); + g_altmdm_dev.spidev = g_altmdm_dev.lower->poweron(); + g_altmdm_dev.lower->set_mready(false); + g_altmdm_dev.lower->set_wakeup(false); + g_altmdm_dev.lower->irqenable(true); + set_reset_reason(LTE_RESTART_USER_INITIATED); + state = ALTMDM_STATE_SLEEP; + } + + return state; +} + +/**************************************************************************** + * SLEEP state + ****************************************************************************/ + +static int next_state_sleep(altmdm_state_t state) +{ + g_altmdm_dev.lower->set_wakeup(false); + + return 0; +} + +static uint32_t waitevt_state_sleep(void) +{ + uint32_t event; + + if (!is_vp_valid()) + { + return 0; + } + + event = altmdm_event_wait(&g_altmdm_dev.event, + EVENT_TXREQ | EVENT_RXREQ | EVENT_WLOCK | EVENT_POWEROFF | EVENT_RESET | + EVENT_DESTROY, false, 0); + + return event; +} + +static altmdm_state_t process_state_sleep(uint32_t event, + altmdm_state_t state) +{ + if (event & EVENT_DESTROY) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_DESTROY); + state = ALTMDM_STATE_DESTORY; + } + else if (event & EVENT_POWEROFF) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_POWEROFF); + state = ALTMDM_STATE_POWEROFF; + } + else if (event & EVENT_RESET) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_RESET); + state = ALTMDM_STATE_FORCERST; + } + else if (!is_vp_valid()) + { + state = ALTMDM_STATE_IDLE4RST; + } + else if (event & (EVENT_TXREQ | EVENT_RXREQ)) + { + state = ALTMDM_STATE_IDLEWTO; + } + else if (event & EVENT_WLOCK) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_WLOCK); + if (get_wlock_count() != 0) + { + state = ALTMDM_STATE_IDLEWOTO; + } + } + + return state; +} + +/**************************************************************************** + * SLEEPWOTX state + ****************************************************************************/ + +static int next_state_sleepwotx(altmdm_state_t state) +{ + g_altmdm_dev.lower->set_wakeup(false); + + return 0; +} + +static uint32_t waitevt_state_sleepwotx(void) +{ + uint32_t event; + + event = altmdm_event_wait(&g_altmdm_dev.event, + EVENT_RXREQ | EVENT_TXSUSTO | EVENT_WLOCK | EVENT_POWEROFF | + EVENT_RESET | EVENT_DESTROY, false, 0); + + return event; +} + +static altmdm_state_t process_state_sleepwotx(uint32_t event, + altmdm_state_t state) +{ + if (event & EVENT_DESTROY) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_DESTROY); + state = ALTMDM_STATE_DESTORY; + } + else if (event & EVENT_POWEROFF) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_POWEROFF); + state = ALTMDM_STATE_POWEROFF; + } + else if (event & EVENT_RESET) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_RESET); + state = ALTMDM_STATE_FORCERST; + } + else if (event & EVENT_RXREQ) + { + state = ALTMDM_STATE_IDLEWOTX; + } + else if (event & EVENT_WLOCK) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_WLOCK); + if (get_wlock_count() != 0) + { + state = ALTMDM_STATE_IDLEWOTX; + } + } + else if (event & EVENT_TXSUSTO) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_TXSUSTO); + state = ALTMDM_STATE_SLEEP; + } + + return state; +} + +/**************************************************************************** + * IDLE4RST state + ****************************************************************************/ + +static int next_state_idle4rst(altmdm_state_t state) +{ + /* clear TX buffer */ + + altmdm_set_spipkt_txbuffer(&g_altmdm_dev.tx_pkt, NULL, 0); + + g_altmdm_dev.lower->set_wakeup(true); + + return 0; +} + +static uint32_t waitevt_state_idle4rst(void) +{ + enum version_phase_e vp; + vp = get_vp(); + + if (vp == VP_UNKNOWN) + { + return 0; + } + else if (vp == VP_NOTV1) + { + return 0; + } + + return altmdm_event_wait(&g_altmdm_dev.event, + EVENT_RXREQ | EVENT_POWEROFF | EVENT_RESET | EVENT_DESTROY, false, 0); +} + +static altmdm_state_t process_state_idle4rst(uint32_t event, + altmdm_state_t state) +{ + enum version_phase_e vp; + vp = get_vp(); + + if (event & EVENT_DESTROY) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_DESTROY); + state = ALTMDM_STATE_DESTORY; + } + else if (event & EVENT_POWEROFF) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_POWEROFF); + state = ALTMDM_STATE_POWEROFF; + } + else if (event & EVENT_RESET) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_RESET); + state = ALTMDM_STATE_FORCERST; + } + else if (vp == VP_UNKNOWN) + { + state = ALTMDM_STATE_V1SET; + } + else if (vp == VP_NOTV1) + { + state = ALTMDM_STATE_V4SET; + } + else if (event & EVENT_RXREQ) + { + state = ALTMDM_STATE_HDRSREQ; + } + + return state; +} + +/**************************************************************************** + * IDLEWTO state + ****************************************************************************/ + +static int next_state_idlewto(altmdm_state_t state) +{ + /* clear TX buffer */ + + altmdm_set_spipkt_txbuffer(&g_altmdm_dev.tx_pkt, NULL, 0); + + g_altmdm_dev.lower->set_wakeup(true); + + return 0; +} + +static uint32_t waitevt_state_idlewto(void) +{ + return altmdm_event_wait(&g_altmdm_dev.event, + EVENT_TXREQ | EVENT_RXREQ | EVENT_WLOCK | + EVENT_POWEROFF | EVENT_RESET | EVENT_DESTROY, + false, TIMEOUT_IDELEWTO_STATE); +} + +static altmdm_state_t process_state_idlewto(uint32_t event, + altmdm_state_t state) +{ + if (event & EVENT_DESTROY) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_DESTROY); + state = ALTMDM_STATE_DESTORY; + } + else if (event & EVENT_POWEROFF) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_POWEROFF); + state = ALTMDM_STATE_POWEROFF; + } + else if (event & EVENT_RESET) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_RESET); + state = ALTMDM_STATE_FORCERST; + } + else if (event & EVENT_TXREQ) + { + state = ALTMDM_STATE_TXPREPARE; + } + else if (event & EVENT_RXREQ) + { + state = ALTMDM_STATE_HDRSREQ; + } + else if (event & EVENT_WLOCK) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_WLOCK); + if (get_wlock_count() != 0) + { + state = ALTMDM_STATE_IDLEWOTO; + } + } + else /* Time out case */ + { + state = ALTMDM_STATE_SLEEPSET; + } + + return state; +} + +/**************************************************************************** + * IDLEWOTO state + ****************************************************************************/ + +static int next_state_idlewoto(altmdm_state_t state) +{ + /* clear TX buffer */ + + altmdm_set_spipkt_txbuffer(&g_altmdm_dev.tx_pkt, NULL, 0); + + g_altmdm_dev.lower->set_wakeup(true); + + return 0; +} + +static uint32_t waitevt_state_idlewoto(void) +{ + return altmdm_event_wait(&g_altmdm_dev.event, + EVENT_TXREQ | EVENT_RXREQ | EVENT_WLOCK | EVENT_POWEROFF | EVENT_RESET | + EVENT_DESTROY, false, 0); +} + +static altmdm_state_t process_state_idlewoto(uint32_t event, + altmdm_state_t state) +{ + if (event & EVENT_DESTROY) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_DESTROY); + state = ALTMDM_STATE_DESTORY; + } + else if (event & EVENT_POWEROFF) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_POWEROFF); + state = ALTMDM_STATE_POWEROFF; + } + else if (event & EVENT_RESET) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_RESET); + state = ALTMDM_STATE_FORCERST; + } + else if (event & EVENT_TXREQ) + { + state = ALTMDM_STATE_TXPREPARE; + } + else if (event & EVENT_RXREQ) + { + state = ALTMDM_STATE_HDRSREQ; + } + else if (event & EVENT_WLOCK) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_WLOCK); + if (get_wlock_count() == 0) + { + state = ALTMDM_STATE_IDLEWTO; + } + } + + return state; +} + +/**************************************************************************** + * IDLEWOTX state + ****************************************************************************/ + +static int next_state_idlewotx(altmdm_state_t state) +{ + /* clear TX buffer */ + + altmdm_set_spipkt_txbuffer(&g_altmdm_dev.tx_pkt, NULL, 0); + + g_altmdm_dev.lower->set_wakeup(true); + + return 0; +} + +static uint32_t waitevt_state_idlewotx(void) +{ + return altmdm_event_wait(&g_altmdm_dev.event, + EVENT_RXREQ | EVENT_TXSUSTO | EVENT_POWEROFF | EVENT_RESET | + EVENT_DESTROY, false, 0); +} + +static altmdm_state_t process_state_idlewotx(uint32_t event, + altmdm_state_t state) +{ + if (event & EVENT_DESTROY) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_DESTROY); + state = ALTMDM_STATE_DESTORY; + } + else if (event & EVENT_POWEROFF) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_POWEROFF); + state = ALTMDM_STATE_POWEROFF; + } + else if (event & EVENT_RESET) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_RESET); + state = ALTMDM_STATE_FORCERST; + } + else if (event & EVENT_RXREQ) + { + state = ALTMDM_STATE_HDRSREQ; + } + else if (event & EVENT_TXSUSTO) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_TXSUSTO); + + if (!is_vp_valid()) + { + state = ALTMDM_STATE_IDLE4RST; + } + else if (get_wlock_count() == 0) + { + state = ALTMDM_STATE_IDLEWTO; + } + else + { + state = ALTMDM_STATE_IDLEWOTO; + } + } + + return state; +} + +/**************************************************************************** + * V1SET state + ****************************************************************************/ + +static altmdm_state_t process_state_v1set(uint32_t event, + altmdm_state_t state) +{ + int len; + void *pkt; + + pkt = altcom_make_poweron_cmd_v1(&len); + set_vp(VP_TRYV1); + altmdm_set_spipkt_txbuffer(&g_altmdm_dev.tx_pkt, pkt, len); + + return ALTMDM_STATE_TXREQ; +} + +/**************************************************************************** + * V4SET state + ****************************************************************************/ + +static altmdm_state_t process_state_v4set(uint32_t event, + altmdm_state_t state) +{ + int len; + void *pkt; + + pkt = altcom_make_poweron_cmd_v4(&len); + set_vp(VP_TRYV4); + altmdm_set_spipkt_txbuffer(&g_altmdm_dev.tx_pkt, pkt, len); + + return ALTMDM_STATE_TXREQ; +} + +/**************************************************************************** + * SLEEPSET state + ****************************************************************************/ + +static altmdm_state_t process_state_sleepset(uint32_t event, + altmdm_state_t state) +{ + altmdm_set_sleeppkt(&g_altmdm_dev.tx_pkt); + + return ALTMDM_STATE_TXREQ; +} + +/**************************************************************************** + * TXPREPARE state + ****************************************************************************/ + +static altmdm_state_t process_state_txprepare(uint32_t event, + altmdm_state_t state) +{ + void *buff; + int len; + + nxsem_wait_uninterruptible(&g_altmdm_dev.lock_txreq); + buff = g_altmdm_dev.txreq_buff; + len = g_altmdm_dev.txreq_size; + nxsem_post(&g_altmdm_dev.lock_txreq); + + altmdm_set_spipkt_txbuffer(&g_altmdm_dev.tx_pkt, buff, len); + + return ALTMDM_STATE_TXREQ; +} + +/**************************************************************************** + * TXREQ state + ****************************************************************************/ + +static altmdm_state_t process_state_txreq(uint32_t event, + altmdm_state_t state) +{ + g_altmdm_dev.lower->set_mready(true); + + return ALTMDM_STATE_HDRSREQ; +} + +/**************************************************************************** + * HDRSREQ state + ****************************************************************************/ + +static uint32_t waitevt_state_hdrsreq(void) +{ + return altmdm_event_wait(&g_altmdm_dev.event, + EVENT_RXREQ | EVENT_POWEROFF | EVENT_DESTROY, + false, TIMEOUT_HDR_TRX_STATE); +} + +static altmdm_state_t process_state_hdrsreq(uint32_t event, + altmdm_state_t state) +{ + if (event & EVENT_DESTROY) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_DESTROY); + state = ALTMDM_STATE_DESTORY; + } + else if (event & EVENT_POWEROFF) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_POWEROFF); + state = ALTMDM_STATE_POWEROFF; + } + else if (event & EVENT_RXREQ) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_RXREQ); + state = ALTMDM_STATE_HDRTRX; + } + else /* Time out case */ + { + if (is_vp_noreset()) + { + state = ALTMDM_STATE_DECIDEDELAY; + } + else + { + m_err("[altmdm] Time out happened. Current State is %d\n", state); + state = ALTMDM_STATE_FORCERST; + } + } + + return state; +} + +/**************************************************************************** + * HDRTRX state + ****************************************************************************/ + +static altmdm_state_t process_state_hdrtrx(uint32_t event, + altmdm_state_t state) +{ + altmdm_do_hdr_transaction(g_altmdm_dev.spidev, g_altmdm_dev.lower, + &g_altmdm_dev.tx_pkt, &g_altmdm_dev.rx_pkt); + + if (!altmdm_is_valid_spipkt_header(&g_altmdm_dev.rx_pkt)) + { + if (is_vp_noreset()) + { + state = ALTMDM_STATE_DECIDEDELAY; + } + else + { + m_err("[altmdm] Header error. Current State is %d\n", state); + state = ALTMDM_STATE_FORCERST; + } + } + else if (is_sleep_pkt(&g_altmdm_dev.tx_pkt)) + { + state = ALTMDM_STATE_SLEEPPKT; + } + else if ((pkt_total_size(&g_altmdm_dev.tx_pkt) == 0) && + (pkt_total_size(&g_altmdm_dev.rx_pkt) == 0)) + { + state = ALTMDM_STATE_DECIDEDELAY; + } + else + { + state = ALTMDM_STATE_BODYSREQ; + } + + return state; +} + +/**************************************************************************** + * SLEEPPKT state + ****************************************************************************/ + +static altmdm_state_t process_state_sleeppkt(uint32_t event, + altmdm_state_t state) +{ + altmdm_overwrite_body_size(&g_altmdm_dev.rx_pkt, 4); + + return ALTMDM_STATE_BODYSREQ; +} + +/**************************************************************************** + * BODYSREQ state + ****************************************************************************/ + +static uint32_t waitevt_state_bodysreq(void) +{ + return altmdm_event_wait(&g_altmdm_dev.event, + EVENT_RXREQ | EVENT_POWEROFF | EVENT_DESTROY, + false, TIMEOUT_BODY_TRX_STATE); +} + +static altmdm_state_t process_state_bodysreq(uint32_t event, + altmdm_state_t state) +{ + if (event & EVENT_DESTROY) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_DESTROY); + state = ALTMDM_STATE_DESTORY; + } + else if (event & EVENT_POWEROFF) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_POWEROFF); + state = ALTMDM_STATE_POWEROFF; + } + else if (event & EVENT_RXREQ) + { + altmdm_event_clear(&g_altmdm_dev.event, EVENT_RXREQ); + state = ALTMDM_STATE_BODYTRX; + } + else /* Time out case */ + { + if (is_vp_noreset()) + { + state = ALTMDM_STATE_DECIDEDELAY; + } + else + { + m_err("[altmdm] Timeout happened. Current State is %d\n", state); + state = ALTMDM_STATE_FORCERST; + } + } + + return state; +} + +/**************************************************************************** + * BODYTRX state + ****************************************************************************/ + +static altmdm_state_t process_state_bodytrx(uint32_t event, + altmdm_state_t state) +{ + altmdm_do_body_transaction(g_altmdm_dev.spidev, g_altmdm_dev.lower, + &g_altmdm_dev.tx_pkt, &g_altmdm_dev.rx_pkt); + + g_altmdm_dev.lower->set_mready(false); + + if (is_reset_pkt(&g_altmdm_dev.rx_pkt)) + { + state = ALTMDM_STATE_GOTRST; + } + else if (is_sleep_pkt(&g_altmdm_dev.tx_pkt)) + { + state = ALTMDM_STATE_GOTSLEEP; + } + else if (pkt_total_size(&g_altmdm_dev.rx_pkt) != 0) + { + state = ALTMDM_STATE_GOTRX; + } + else + { + state = ALTMDM_STATE_DECIDEDELAY; + } + + if (has_sendrequest(&g_altmdm_dev.tx_pkt)) + { + if (is_reset_pkt(&g_altmdm_dev.rx_pkt)) + { + tx_done(TX_CANCEL); + } + else if (!is_buffer_full(&g_altmdm_dev.rx_pkt)) + { + tx_done(TX_DONE); + } + } + + if (!is_buffer_full(&g_altmdm_dev.rx_pkt)) + { + altmdm_timer_restart(g_altmdm_dev.txsus_timer, 0, 0); + } + + return state; +} + +/**************************************************************************** + * GOTRX state + ****************************************************************************/ + +static altmdm_state_t process_state_gotrx(uint32_t event, + altmdm_state_t state) +{ + enum version_phase_e vp; + void *rcv_data; + + state = ALTMDM_STATE_DECIDEDELAY; + + if (is_vp_valid()) + { + set_return_code(pkt_actual_size(&g_altmdm_dev.rx_pkt)); + state = ALTMDM_STATE_RETRECV; + } + else + { + rcv_data = get_pkt_buffer(&g_altmdm_dev.rx_pkt); + vp = get_vp(); + if (vp == VP_TRYV1) + { + if (altcom_is_v1pkt_ok((struct altcom_cmdhdr_s *)rcv_data)) + { + set_vp(VP_V1); + set_return_code(ALTMDM_RETURN_RESET_V1); + state = ALTMDM_STATE_RETRECV; + } + else + { + set_vp(VP_NOTV1); + } + } + else if ((vp == VP_TRYV4) + && altcom_is_v4pkt_ok((struct altcom_cmdhdr_s *)rcv_data)) + { + set_vp(VP_V4); + set_return_code(ALTMDM_RETURN_RESET_V4); + state = ALTMDM_STATE_RETRECV; + } + } + + return state; +} + +/**************************************************************************** + * GOTRST state + ****************************************************************************/ + +static altmdm_state_t process_state_gotrst(uint32_t event, + altmdm_state_t state) +{ + if (is_vp_noreset()) + { + set_return_code(ALTMDM_RETURN_RESET_PKT); + set_vp(VP_UNKNOWN); + state = ALTMDM_STATE_RETRECV; + } + else + { + m_err("[altmdm] Reset pkt received. Current State is %d\n", state); + state = ALTMDM_STATE_FORCERST; + } + + return state; +} + +/**************************************************************************** + * GOTSLEEP state + ****************************************************************************/ + +static altmdm_state_t process_state_gotsleep(uint32_t event, + altmdm_state_t state) +{ + if (altmdm_is_sleeppkt_ok(&g_altmdm_dev.rx_pkt)) + { + state = ALTMDM_STATE_SLEEPING; + } + else + { + state = ALTMDM_STATE_DECIDEDELAY; + } + + return state; +} + +/**************************************************************************** + * BACKTOIDLE state + ****************************************************************************/ + +static altmdm_state_t process_state_backtoidle(uint32_t event, + altmdm_state_t state) +{ + if (is_buffer_full(&g_altmdm_dev.rx_pkt)) + { + if (altmdm_timer_is_running(g_altmdm_dev.txsus_timer)) + { + state = ALTMDM_STATE_IDLEWOTX; + } + else + { + state = ALTMDM_STATE_SETSUSTIMER; + } + } + else if (!is_vp_valid()) + { + state = ALTMDM_STATE_IDLE4RST; + } + else if (get_wlock_count() != 0) + { + state = ALTMDM_STATE_IDLEWOTO; + } + else + { + state = ALTMDM_STATE_IDLEWTO; + } + + return state; +} + +/**************************************************************************** + * RETRECV state + ****************************************************************************/ + +static altmdm_state_t process_state_retrecv(uint32_t event, + altmdm_state_t state) +{ + return ALTMDM_STATE_DECIDEDELAY; +} + +/**************************************************************************** + * FORCERST state + ****************************************************************************/ + +static altmdm_state_t process_state_forcerst(uint32_t event, + altmdm_state_t state) +{ + force_reset(); + + return ALTMDM_STATE_BACKTOIDLE; +} + +/**************************************************************************** + * SLEEPING state + ****************************************************************************/ + +static uint32_t waitevt_state_sleeping(void) +{ + up_udelay(TIMEOUT_NEXT_DELAY); + + return 0; +} + +static altmdm_state_t process_state_sleeping(uint32_t event, + altmdm_state_t state) +{ + if (is_buffer_full(&g_altmdm_dev.rx_pkt)) + { + if (altmdm_timer_is_running(g_altmdm_dev.txsus_timer)) + { + state = ALTMDM_STATE_SLEEPWOTX; + } + else + { + state = ALTMDM_STATE_SETSUSTIMERSLEEP; + } + } + else + { + state = ALTMDM_STATE_SLEEP; + } + + return state; +} + +/**************************************************************************** + * DECIDEDELAY state + ****************************************************************************/ + +static int next_state_decidedelay(altmdm_state_t state) +{ + return (state == ALTMDM_STATE_RETRECV); +} + +static altmdm_state_t process_state_decidedelay(uint32_t event, + altmdm_state_t state) +{ + if (has_sendrequest(&g_altmdm_dev.tx_pkt) || + is_sleep_pkt(&g_altmdm_dev.tx_pkt)) + { + state = ALTMDM_STATE_DELAYNEXT; + } + else + { + state = ALTMDM_STATE_BACKTOIDLE; + } + + return state; +} + +/**************************************************************************** + * DELAYNEXT state + ****************************************************************************/ + +static uint32_t waitevt_state_delaynext(void) +{ + up_udelay(TIMEOUT_NEXT_DELAY); + + return 0; +} + +static altmdm_state_t process_state_delaynext(uint32_t event, + altmdm_state_t state) +{ + state = ALTMDM_STATE_BACKTOIDLE; + + return state; +} + +/**************************************************************************** + * SETSUSTIMER state + ****************************************************************************/ + +static altmdm_state_t process_state_setsustimer(uint32_t event, + altmdm_state_t state) +{ + altmdm_timer_restart(g_altmdm_dev.txsus_timer, + TXSUS_TIMEOUT, 0); + + return ALTMDM_STATE_IDLEWOTX; +} + +/**************************************************************************** + * SETSUSTIMERSLEEP state + ****************************************************************************/ + +static altmdm_state_t process_state_setsustimersleep(uint32_t event, + altmdm_state_t state) +{ + altmdm_timer_restart(g_altmdm_dev.txsus_timer, + TXSUS_TIMEOUT, 0); + + return ALTMDM_STATE_SLEEPWOTX; +} + +/**************************************************************************** + * DESTORY state + ****************************************************************************/ + +static int next_state_destroy(altmdm_state_t state) +{ + next_state_poweroff(state); + altmdm_event_clear(&g_altmdm_dev.event, (uint32_t)(-1)); + altmdm_timer_stop(g_altmdm_dev.txsus_timer); + set_return_code(ALTMDM_RETURN_EXIT); + + return 1; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int altmdm_init(FAR struct spi_dev_s *spidev, + FAR const struct alt1250_lower_s *lower) +{ + altmdm_event_init(&g_altmdm_dev.event); + altmdm_event_init(&g_altmdm_dev.txdone_event); + + nxsem_init(&g_altmdm_dev.lock_evt, 0, 1); + nxsem_init(&g_altmdm_dev.lock_vp, 0, 1); + nxsem_init(&g_altmdm_dev.lock_counter, 0, 1); + nxsem_init(&g_altmdm_dev.lock_txreq, 0, 1); + + altmdm_spipkt_init(&g_altmdm_dev.tx_pkt); + altmdm_spipkt_init(&g_altmdm_dev.rx_pkt); + + g_altmdm_dev.spidev = spidev; + g_altmdm_dev.lower = lower; + + g_altmdm_dev.txsus_timer = altmdm_timer_start(0, 0, txsustimer_handler, + &g_altmdm_dev); + g_altmdm_dev.wcounter = 0; + g_altmdm_dev.rx_retcode = 0; + g_altmdm_dev.txreq_buff = NULL; + g_altmdm_dev.txreq_size = 0; + + g_altmdm_dev.current_state = ALTMDM_STATE_POWEROFF; + g_altmdm_dev.vp = VP_NO_RESET; + + lower->irqattach(sready_isr); + + next_state_poweroff(g_altmdm_dev.current_state); + + return 0; +} + +int altmdm_fin(void) +{ + int ret = OK; + uint32_t evt; + + nxsem_wait_uninterruptible(&g_altmdm_dev.lock_evt); + + evt = altmdm_event_refer(&g_altmdm_dev.event); + + /* Is already accepted DESTROY request? */ + + if (evt & EVENT_DESTROY) + { + ret = -EALREADY; + } + + /* Is in DESTROY state? */ + + if (g_altmdm_dev.current_state == ALTMDM_STATE_DESTORY) + { + ret = -EALREADY; + } + + if (ret == OK) + { + altmdm_event_set(&g_altmdm_dev.event, EVENT_DESTROY); + } + + nxsem_post(&g_altmdm_dev.lock_evt); + + return ret; +} + +int altmdm_poweron(void) +{ + int ret = OK; + uint32_t evt; + + nxsem_wait_uninterruptible(&g_altmdm_dev.lock_evt); + + evt = altmdm_event_refer(&g_altmdm_dev.event); + + /* Is already accepted DESTROY request? */ + + if (evt & EVENT_DESTROY) + { + ret = -EOPNOTSUPP; + } + + /* Is already accepted EVENT_POWERON request? */ + + else if (evt & EVENT_POWERON) + { + ret = -EALREADY; + } + + /* Is in POWERON state? */ + + if ((g_altmdm_dev.current_state != ALTMDM_STATE_POWEROFF) && + (g_altmdm_dev.current_state != ALTMDM_STATE_DESTORY)) + { + if (!(evt & EVENT_POWEROFF)) + { + ret = -EALREADY; + } + } + + if (ret == OK) + { + altmdm_event_set(&g_altmdm_dev.event, EVENT_POWERON); + } + + nxsem_post(&g_altmdm_dev.lock_evt); + + return ret; +} + +int altmdm_poweroff(void) +{ + int ret = OK; + uint32_t evt; + + nxsem_wait_uninterruptible(&g_altmdm_dev.lock_evt); + + evt = altmdm_event_refer(&g_altmdm_dev.event); + + /* Is already accepted DESTROY request? */ + + if (evt & EVENT_DESTROY) + { + ret = -EOPNOTSUPP; + } + + /* Is already accepted POWEROFF request? */ + + else if (evt & EVENT_POWEROFF) + { + ret = -EALREADY; + } + + /* Is in POWEROFF state? */ + + if ((g_altmdm_dev.current_state == ALTMDM_STATE_POWEROFF) || + (g_altmdm_dev.current_state == ALTMDM_STATE_DESTORY)) + { + if (!(evt & EVENT_POWERON)) + { + ret = -EALREADY; + } + } + + if (ret == OK) + { + altmdm_event_set(&g_altmdm_dev.event, EVENT_POWEROFF); + } + + nxsem_post(&g_altmdm_dev.lock_evt); + + return ret; +} + +int altmdm_reset(void) +{ + nxsem_wait_uninterruptible(&g_altmdm_dev.lock_evt); + + altmdm_event_set(&g_altmdm_dev.event, EVENT_RESET); + + nxsem_post(&g_altmdm_dev.lock_evt); + + return 0; +} + +int altmdm_read(FAR uint8_t *buff, int sz) +{ + int is_exit = 0; + uint32_t event = 0; + altmdm_state_t next_state = ALTMDM_STATE_POWEROFF; + + altmdm_set_spipkt_rxbuffer(&g_altmdm_dev.rx_pkt, buff, sz); + + dump_current_all_status(&g_altmdm_dev, event, next_state, is_exit); + + /* State machine loop */ + + while (!is_exit) + { + /* Waiting events */ + + event = g_state_func[g_altmdm_dev.current_state].wait_event(); + + /* altmdm_fin(), altmdm_poweron(), and altmdm_poweroff() check + * the event flag and decide whether or not to send the event. + * Since this event flag checking process and the process to clear + * the event flag will cause resource conflicts, so added this function + * for exclusivity. + */ + + nxsem_wait_uninterruptible(&g_altmdm_dev.lock_evt); + + /* Process on the state */ + + next_state = g_state_func[g_altmdm_dev.current_state].process_state( + event, g_altmdm_dev.current_state); + + /* Going to next state */ + + if (next_state != g_altmdm_dev.current_state) + { + is_exit = g_state_func[next_state].goto_next( + g_altmdm_dev.current_state); + } + + dump_current_all_status(&g_altmdm_dev, event, next_state, is_exit); + + g_altmdm_dev.current_state = next_state; + + nxsem_post(&g_altmdm_dev.lock_evt); + } + + return g_altmdm_dev.rx_retcode; +} + +int altmdm_write(FAR uint8_t *buff, int sz) +{ + bool should_wait = true; + uint32_t ret; + + sz = (sz > get_spipayload_maxsize()) ? get_spipayload_maxsize() : sz; + + do + { + if (!is_vp_valid()) + { + return ALTMDM_RETURN_NOTREADY; + } + + nxsem_wait_uninterruptible(&g_altmdm_dev.lock_txreq); + if (g_altmdm_dev.txreq_buff == NULL) + { + g_altmdm_dev.txreq_buff = buff; + g_altmdm_dev.txreq_size = sz; + should_wait = false; + altmdm_event_set(&g_altmdm_dev.event, EVENT_TXREQ); + altmdm_event_clear(&g_altmdm_dev.txdone_event, (uint32_t)-1); + } + + nxsem_post(&g_altmdm_dev.lock_txreq); + + if (should_wait) + { + ret = altmdm_event_wait(&g_altmdm_dev.txdone_event, + TX_DONE | TX_CANCEL, true, 0); + if (ret & TX_CANCEL) + { + return ALTMDM_RETURN_CANCELED; + } + } + } + while (should_wait); + + ret = altmdm_event_wait(&g_altmdm_dev.txdone_event, + TX_DONE | TX_CANCEL, true, 0); + + if (ret & TX_DONE) + { + return sz; + } + else + { + return ALTMDM_RETURN_CANCELED; + } +} + +int altmdm_take_wlock(void) +{ + int cnt; + + nxsem_wait_uninterruptible(&g_altmdm_dev.lock_counter); + cnt = ++g_altmdm_dev.wcounter; + nxsem_post(&g_altmdm_dev.lock_counter); + + altmdm_event_set(&g_altmdm_dev.event, EVENT_WLOCK); + + return cnt; +} + +int altmdm_give_wlock(void) +{ + int cnt; + + nxsem_wait_uninterruptible(&g_altmdm_dev.lock_counter); + if (g_altmdm_dev.wcounter != 0) + { + g_altmdm_dev.wcounter--; + } + + cnt = g_altmdm_dev.wcounter; + nxsem_post(&g_altmdm_dev.lock_counter); + + if (cnt == 0) + { + altmdm_event_set(&g_altmdm_dev.event, EVENT_WLOCK); + } + + return cnt; +} + +uint32_t altmdm_get_reset_reason(void) +{ + return get_reset_reason(); +} + +uint8_t altmdm_get_protoversion(void) +{ + enum version_phase_e vp; + + nxsem_wait_uninterruptible(&g_altmdm_dev.lock_vp); + vp = g_altmdm_dev.vp; + vp = ((vp == VP_V1) || (vp == VP_V4)) ? vp : ALTCOM_VERX; + nxsem_post(&g_altmdm_dev.lock_vp); + + return (uint8_t)vp; +} + +#endif diff --git a/drivers/modem/alt1250/altmdm.h b/drivers/modem/alt1250/altmdm.h new file mode 100644 index 00000000000..b97140f05e8 --- /dev/null +++ b/drivers/modem/alt1250/altmdm.h @@ -0,0 +1,240 @@ +/**************************************************************************** + * drivers/modem/alt1250/altmdm.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __DRIVERS_MODEM_ALT1250_ALTMDM_H +#define __DRIVERS_MODEM_ALT1250_ALTMDM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define ALTMDM_RETURN_RESET_V1 (-1) +#define ALTMDM_RETURN_NOTREADY (-2) +#define ALTMDM_RETURN_CANCELED (-3) +#define ALTMDM_RETURN_RESET_V4 (-4) +#define ALTMDM_RETURN_RESET_PKT (-5) +#define ALTMDM_RETURN_EXIT (-6) + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: altmdm_init + * + * Description: + * Initialize the ALTMDM driver. + * + * Input Parameters: + * spidev - An SPI instance that communicates with the ALT1250. + * lower - An instance of the lower interface. + * + * Returned Value: + * Returns 0 on success. + * When an error occurs, a negative value is returned. + * + ****************************************************************************/ + +int altmdm_init(FAR struct spi_dev_s *spidev, + FAR const struct alt1250_lower_s *lower); + +/**************************************************************************** + * Name: altmdm_fin + * + * Description: + * Finalize the ALTMDM driver. + * + * Input Parameters: + * None + * + * Returned Value: + * Returns 0 on success. + * When an error occurs, a negative value is returned. + * + ****************************************************************************/ + +int altmdm_fin(void); + +/**************************************************************************** + * Name: altmdm_read + * + * Description: + * Read an SPI packet sent from the ALT1250. + * + * Input Parameters: + * buff - A buffer for reading SPI packets. + * sz - Buffer size. + * + * Returned Value: + * Returns the size of the read SPI packet. Otherwise, it returns a + * negative value. See the macro prefixed with ALTMDM_RETURN_ as defined + * in this file. + * + ****************************************************************************/ + +int altmdm_read(FAR uint8_t *buff, int sz); + +/**************************************************************************** + * Name: altmdm_write + * + * Description: + * Write an SPI packet to the ALT1250. + * + * Input Parameters: + * buff - A buffer for sending SPI packets. + * sz - Buffer size. + * + * Returned Value: + * Returns the size of the write SPI packet. Otherwise, it returns a + * negative value. See the macro prefixed with ALTMDM_RETURN_ as defined + * in this file. + * + ****************************************************************************/ + +int altmdm_write(FAR uint8_t *buff, int sz); + +/**************************************************************************** + * Name: altmdm_take_wlock + * + * Description: + * Take a wakelock. The ALT1250 will not be able to sleep until + * it is released with altmdm_take_wloc(). + * + * Input Parameters: + * None + * + * Returned Value: + * Returns the count of wakelocks currently acquired. + * + ****************************************************************************/ + +int altmdm_take_wlock(void); + +/**************************************************************************** + * Name: altmdm_give_wlock + * + * Description: + * Give a wakelock. If the wakelock count is 0, the ALT1250 can sleep. + * + * Input Parameters: + * None + * + * Returned Value: + * Returns the count of wakelocks currently acquired. + * + ****************************************************************************/ + +int altmdm_give_wlock(void); + +/**************************************************************************** + * Name: altmdm_poweron + * + * Description: + * Turn on the power of the ALT1250. + * + * Input Parameters: + * None + * + * Returned Value: + * Returns 0 on success. + * When an error occurs, a negative value is returned. + * + ****************************************************************************/ + +int altmdm_poweron(void); + +/**************************************************************************** + * Name: altmdm_poweroff + * + * Description: + * Turn off the power of the ALT1250. + * + * Input Parameters: + * None + * + * Returned Value: + * Returns 0 on success. + * When an error occurs, a negative value is returned. + * + ****************************************************************************/ + +int altmdm_poweroff(void); + +/**************************************************************************** + * Name: altmdm_reset + * + * Description: + * Reset the ALT1250. + * + * Input Parameters: + * None + * + * Returned Value: + * Returns 0 on success. + * When an error occurs, a negative value is returned. + * + ****************************************************************************/ + +int altmdm_reset(void); + +/**************************************************************************** + * Name: altmdm_get_reset_reason + * + * Description: + * Returns whether the reset was initiated by the user or ALT1250. + * + * Input Parameters: + * None + * + * Returned Value: + * Returns LTE_RESTART_USER_INITIATED if it was reset by the user + * or LTE_RESTART_MODEM_INITIATED by the ALT1250. + * + ****************************************************************************/ + +uint32_t altmdm_get_reset_reason(void); + +/**************************************************************************** + * Name: altmdm_get_protoversion + * + * Description: + * Returns the protocol version of the ALTCOM command. + * + * Input Parameters: + * None + * + * Returned Value: + * Returns the protocol version of the ALTCOM command. ALTCOM_VERX means + * that the ALTCOM version check sequence has not been completed or is not + * supported. + * + ****************************************************************************/ + +uint8_t altmdm_get_protoversion(void); + +#endif /* __DRIVERS_MODEM_ALT1250_ALTMDM_H */ diff --git a/drivers/modem/alt1250/altmdm_event.c b/drivers/modem/alt1250/altmdm_event.c new file mode 100644 index 00000000000..a1123bbfc00 --- /dev/null +++ b/drivers/modem/alt1250/altmdm_event.c @@ -0,0 +1,209 @@ +/**************************************************************************** + * drivers/modem/alt1250/altmdm_event.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 + +#include +#include +#include +#include + +#include "altmdm_event.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int set_expiretime(int expire_time, FAR struct timespec *set_time) +{ + struct timespec curr_time; + + /* Get current time. */ + + if (clock_gettime(CLOCK_REALTIME, &curr_time) != OK) + { + return ERROR; + } + + set_time->tv_sec = expire_time / 1000; + set_time->tv_nsec = + (expire_time - (set_time->tv_sec * 1000)) * 1000 * 1000; + + set_time->tv_sec += curr_time.tv_sec; + set_time->tv_nsec += curr_time.tv_nsec; + + /* Check more than 1 sec. */ + + if (set_time->tv_nsec >= (1000 * 1000 * 1000)) + { + set_time->tv_sec += 1; + set_time->tv_nsec -= (1000 * 1000 * 1000); + } + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int altmdm_event_init(FAR struct altmdm_event_s *evt) +{ + int ret; + + evt->event = 0; + ret = nxsem_init(&evt->sem, 0, 0); + + return ret; +} + +int altmdm_event_destroy(FAR struct altmdm_event_s *evt) +{ + int ret; + + ret = nxsem_destroy(&evt->sem); + + return ret; +} + +uint32_t altmdm_event_wait(FAR struct altmdm_event_s *evt, + uint32_t event, bool with_clear, int timeout_ms) +{ + int ret; + struct timespec abs_time; + irqstate_t flags; + uint32_t ptn; + + /* Check argument. */ + + if (evt == NULL) + { + return 0; + } + + if (timeout_ms > 0) + { + if (set_expiretime(timeout_ms, &abs_time) != OK) + { + return 0; + } + } + + while (1) + { + flags = enter_critical_section(); + + ptn = (evt->event & event); + if (ptn != 0) + { + /* Clear read event. */ + + if (with_clear) + { + evt->event = (evt->event & ~ptn); + } + + /* Clear the semaphore posted by altmdm_sys_setflag. */ + + while (1) + { + if (nxsem_trywait(&evt->sem) < 0) + { + break; + } + } + + leave_critical_section(flags); + + /* Go out while(1) as expected event is happened */ + + break; + } + + leave_critical_section(flags); + + /* Wait for any event is occured related on the semaphore.. */ + + if (timeout_ms > 0) + { + /* Wait with timeout. */ + + ret = nxsem_timedwait_uninterruptible(&evt->sem, &abs_time); + } + else + { + /* Wait it forever. */ + + ret = nxsem_wait_uninterruptible(&evt->sem); + } + + /* Error check */ + + if (ret < 0) + { + ptn = 0; + break; + } + } + + /* end of while(1) */ + + return ptn; +} + +int altmdm_event_set(FAR struct altmdm_event_s *evt, uint32_t event) +{ + int ret; + irqstate_t flags; + + flags = enter_critical_section(); + evt->event = (evt->event | event); + leave_critical_section(flags); + ret = nxsem_post(&evt->sem); + + return ret; +} + +int altmdm_event_clear(FAR struct altmdm_event_s *evt, uint32_t event) +{ + irqstate_t flags; + + flags = enter_critical_section(); + evt->event = (evt->event & ~event); + leave_critical_section(flags); + + return OK; +} + +uint32_t altmdm_event_refer(FAR struct altmdm_event_s *evt) +{ + uint32_t event; + irqstate_t flags; + + flags = enter_critical_section(); + event = evt->event; + leave_critical_section(flags); + + return event; +} diff --git a/drivers/modem/alt1250/altmdm_event.h b/drivers/modem/alt1250/altmdm_event.h new file mode 100644 index 00000000000..de672baae4e --- /dev/null +++ b/drivers/modem/alt1250/altmdm_event.h @@ -0,0 +1,156 @@ +/**************************************************************************** + * drivers/modem/alt1250/altmdm_event.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __DRIVERS_MODEM_ALT1250_ALTMDM_EVENT_H +#define __DRIVERS_MODEM_ALT1250_ALTMDM_EVENT_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct altmdm_event_s +{ + sem_t sem; + uint32_t event; +}; + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: altmdm_event_init + * + * Description: + * Initialize the event flag. + * + * Input Parameters: + * evt - An instance pointer to the event flag. + * + * Returned Value: + * Returns 0 on success. + * When an error occurs, a negative value is returned. + * + ****************************************************************************/ + +int altmdm_event_init(FAR struct altmdm_event_s *evt); + +/**************************************************************************** + * Name: altmdm_event_destroy + * + * Description: + * Destroy the event flag. + * + * Input Parameters: + * evt - An instance pointer to the event flag. + * + * Returned Value: + * Returns 0 on success. + * When an error occurs, a negative value is returned. + * + ****************************************************************************/ + +int altmdm_event_destroy(FAR struct altmdm_event_s *evt); + +/**************************************************************************** + * Name: altmdm_event_wait + * + * Description: + * Wait for the specified event. + * + * Input Parameters: + * evt - An instance pointer to the event flag. + * event - A bitmap that means an event to wait for. + * with_clear - A flag to clear the event flag when an event is received. + * timeout_ms - Time-out value to wait for an event. 0 means infinite wait. + * + * Returned Value: + * Returns the received event. When an error occurs, + * a negative value is returned. + * + ****************************************************************************/ + +uint32_t altmdm_event_wait(FAR struct altmdm_event_s *evt, + uint32_t event, bool with_clear, int timeout_ms); + +/**************************************************************************** + * Name: altmdm_event_set + * + * Description: + * Send event. + * + * Input Parameters: + * evt - An instance pointer to the event flag. + * event - Bitmap of the event to send. + * + * Returned Value: + * Returns 0 on success. + * When an error occurs, a negative value is returned. + * + ****************************************************************************/ + +int altmdm_event_set(FAR struct altmdm_event_s *evt, uint32_t event); + +/**************************************************************************** + * Name: altmdm_event_clear + * + * Description: + * Clear event. + * + * Input Parameters: + * evt - An instance pointer to the event flag. + * event - Bitmap of the event to clear. + * + * Returned Value: + * Returns 0 on success. + * When an error occurs, a negative value is returned. + * + ****************************************************************************/ + +int altmdm_event_clear(FAR struct altmdm_event_s *evt, uint32_t event); + +/**************************************************************************** + * Name: altmdm_event_refer + * + * Description: + * Get which event is being received. + * + * Input Parameters: + * evt - An instance pointer to the event flag. + * + * Returned Value: + * Returns the received event. When an error occurs, + * a negative value is returned. + * + ****************************************************************************/ + +uint32_t altmdm_event_refer(FAR struct altmdm_event_s *evt); + +#endif /* __DRIVERS_MODEM_ALT1250_ALTMDM_EVENT_H */ diff --git a/drivers/modem/alt1250/altmdm_spi.c b/drivers/modem/alt1250/altmdm_spi.c new file mode 100644 index 00000000000..11132c1d5dd --- /dev/null +++ b/drivers/modem/alt1250/altmdm_spi.c @@ -0,0 +1,144 @@ +/**************************************************************************** + * drivers/modem/alt1250/altmdm_spi.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 + +#include +#include +#include +#include + +#include + +#include "altmdm_spi.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void altmdm_spipkt_init(FAR altmdm_spipkt_t *pkt) +{ + pkt->header = 0; + pkt->buffer = NULL; + pkt->buff_size = 0; +} + +void altmdm_set_spipkt_rxbuffer(FAR altmdm_spipkt_t *pkt, FAR void *buf, + uint16_t sz) +{ + pkt->buffer = buf; + pkt->buff_size = sz; +} + +void altmdm_set_spipkt_txbuffer(FAR altmdm_spipkt_t *pkt, FAR void *buf, + uint16_t sz) +{ + uint16_t total_sz; + + if (sz <= ALTSPI_MAX_PKTSIZE) + { + sz &= ALTSPI_PKT_SIZEMASK; + total_sz = (sz + (ALTSPI_PKT_WORDSIZE - 1)) & + ~(ALTSPI_PKT_WORDSIZE - 1); + pkt->header = (total_sz << ALTSPI_PKT_TOTALSIZE_POS) + sz; + pkt->buffer = buf; + pkt->buff_size = sz; + } +} + +void altmdm_overwrite_body_size(FAR altmdm_spipkt_t *pkt, uint16_t sz) +{ + uint16_t total_sz; + + if (sz <= ALTSPI_MAX_PKTSIZE) + { + sz &= ALTSPI_PKT_SIZEMASK; + total_sz = (sz + (ALTSPI_PKT_WORDSIZE - 1)) & + ~(ALTSPI_PKT_WORDSIZE - 1); + pkt->header = (pkt->header & ALTSPI_STATUSMASK) | + ((total_sz << ALTSPI_PKT_TOTALSIZE_POS) + sz); + } +} + +void altmdm_set_sleeppkt(FAR altmdm_spipkt_t *pkt) +{ + altmdm_set_spipkt_txbuffer(pkt, NULL, 0); + pkt->header |= ALTSPI_SLEEP_BIT; +} + +bool altmdm_is_valid_spipkt_header(FAR altmdm_spipkt_t *pkt) +{ + uint16_t actual_size; + uint16_t total_size; + + actual_size = pkt_actual_size(pkt); + total_size = pkt_total_size(pkt); + + return ((actual_size <= ALTSPI_MAX_PKTSIZE) && + (actual_size <= pkt->buff_size) && + (((actual_size + (ALTSPI_PKT_WORDSIZE - 1)) & ~(ALTSPI_PKT_WORDSIZE - 1)) + == total_size)); +} + +bool altmdm_is_sleeppkt_ok(FAR altmdm_spipkt_t *pkt) +{ + return (strncmp(pkt->buffer, "OKOK", 4) == 0); +} + +void altmdm_do_hdr_transaction(FAR struct spi_dev_s *spidev, + FAR const struct alt1250_lower_s *lower, FAR altmdm_spipkt_t *tx_pkt, + FAR altmdm_spipkt_t *rx_pkt) +{ + /* Alt1250 is network endian, so swap tx header value. */ + + tx_pkt->header = htonl(tx_pkt->header); + + SPI_EXCHANGE(spidev, &tx_pkt->header, &rx_pkt->header, ALTSPI_PKT_HDRSIZE); + + /* Get correct endian values after exchanged */ + + rx_pkt->header = ntohl(rx_pkt->header); + tx_pkt->header = ntohl(tx_pkt->header); + + m_info("Header TRX done. rx: 0x%08lx, tx: 0x%08lx\n", + rx_pkt->header, tx_pkt->header); +} + +void altmdm_do_body_transaction(FAR struct spi_dev_s *spidev, + FAR const struct alt1250_lower_s *lower, FAR altmdm_spipkt_t *tx_pkt, + FAR altmdm_spipkt_t *rx_pkt) +{ + size_t exchange_size; + + /* Larger size is exchange size */ + + exchange_size = pkt_total_size(tx_pkt) > pkt_total_size(rx_pkt) + ? pkt_total_size(tx_pkt) : pkt_total_size(rx_pkt); + + SPI_EXCHANGE(spidev, tx_pkt->buffer, rx_pkt->buffer, exchange_size); + + m_info("Body TRX done. ex size: %d, rx size: %d/%d, tx size: %d/%d\n", + exchange_size, pkt_actual_size(rx_pkt), pkt_total_size(rx_pkt), + pkt_actual_size(tx_pkt), pkt_total_size(tx_pkt)); +} diff --git a/drivers/modem/alt1250/altmdm_spi.h b/drivers/modem/alt1250/altmdm_spi.h new file mode 100644 index 00000000000..9f704040bc6 --- /dev/null +++ b/drivers/modem/alt1250/altmdm_spi.h @@ -0,0 +1,280 @@ +/**************************************************************************** + * drivers/modem/alt1250/altmdm_spi.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __DRIVERS_MODEM_ALT1250_ALTMDM_SPI_H +#define __DRIVERS_MODEM_ALT1250_ALTMDM_SPI_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define ALTSPI_PKT_STATUS_POS (28) + +#define ALTSPI_SLEEP_BIT (1 << 28) +#define ALTSPI_RESET_BIT (1 << 30) +#define ALTSPI_BUFFFULL_BIT (1 << 31) +#define ALTSPI_STATUSMASK (0x0f << ALTSPI_PKT_STATUS_POS) + +#define ALTSPI_PKT_TOTALSIZE_POS (14) +#define ALTSPI_PKT_SIZEMASK ((1 << 14) - 1) + +#define ALTSPI_PKT_WORDSIZE (4) +#define ALTSPI_PKT_HDRSIZE ALTSPI_PKT_WORDSIZE + +#define ALTSPI_MAX_PKTSIZE (2064) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +typedef struct altmdm_spipkt_s +{ + uint32_t header; /* Buffer for SPI protocol headers to be exchanged with + * the ALT1250. */ + void *buffer; /* Buffer for SPI protocol body to be exchanged with + * the ALT1250. */ + int buff_size; /* Buffer size of the SPI protocol body. Maximum size + * is ALTSPI_MAX_PKTSIZE. */ +} altmdm_spipkt_t; + +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +static inline FAR void *get_pkt_buffer(FAR altmdm_spipkt_t *pkt) +{ + return pkt->buffer; +} + +static inline int get_pkt_size(FAR altmdm_spipkt_t *pkt) +{ + return pkt->buff_size; +} + +static inline int get_spipayload_maxsize(void) +{ + return ALTSPI_MAX_PKTSIZE; +} + +static inline uint16_t pkt_total_size(FAR altmdm_spipkt_t *pkt) +{ + return (uint16_t) + ((pkt->header >> ALTSPI_PKT_TOTALSIZE_POS) & ALTSPI_PKT_SIZEMASK); +} + +static inline uint16_t pkt_actual_size(FAR altmdm_spipkt_t *pkt) +{ + return (uint16_t)(pkt->header & ALTSPI_PKT_SIZEMASK); +} + +static inline int is_sleep_pkt(FAR altmdm_spipkt_t *pkt) +{ + return (pkt->header & ALTSPI_SLEEP_BIT); +} + +static inline int is_reset_pkt(FAR altmdm_spipkt_t *pkt) +{ + return (pkt->header & ALTSPI_RESET_BIT); +} + +static inline int has_sendrequest(FAR altmdm_spipkt_t *pkt) +{ + return (pkt->buffer != NULL); +} + +static inline int is_buffer_full(FAR altmdm_spipkt_t *pkt) +{ + return (pkt->header & ALTSPI_BUFFFULL_BIT); +} + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: altmdm_spipkt_init + * + * Description: + * Initialize SPI packet structure. + * + * Input Parameters: + * pkt - Pointer to SPI packet structure. + * + * Returned Value: + * None + * + ****************************************************************************/ + +void altmdm_spipkt_init(FAR altmdm_spipkt_t *pkt); + +/**************************************************************************** + * Name: altmdm_set_spipkt_rxbuffer + * + * Description: + * Sets parameters of the SPI packet structure for reception. + * + * Input Parameters: + * pkt - Pointer to SPI packet structure for reception. + * buf - Buffer for SPI protocol body reception. + * sz - Buffer size for SPI protocol body reception. + * + * Returned Value: + * None + * + ****************************************************************************/ + +void altmdm_set_spipkt_rxbuffer(FAR altmdm_spipkt_t *pkt, FAR void *buf, + uint16_t sz); + +/**************************************************************************** + * Name: altmdm_set_spipkt_txbuffer + * + * Description: + * Set the parameters of the SPI packet structure for sending. + * + * Input Parameters: + * pkt - Pointer to SPI packet structure for sending. + * buf - Buffer for SPI protocol body sending. + * sz - Buffer size for SPI protocol body sending. + * + * Returned Value: + * None + * + ****************************************************************************/ + +void altmdm_set_spipkt_txbuffer(FAR altmdm_spipkt_t *pkt, FAR void *buf, + uint16_t sz); + +/**************************************************************************** + * Name: altmdm_overwrite_body_size + * + * Description: + * Overwrites the body size of the SPI packet structure. + * + * Input Parameters: + * pkt - Pointer to SPI packet structure. + * sz - Buffer size for SPI protocol body sending. + * + * Returned Value: + * None + * + ****************************************************************************/ + +void altmdm_overwrite_body_size(FAR altmdm_spipkt_t *pkt, uint16_t sz); + +/**************************************************************************** + * Name: altmdm_set_sleeppkt + * + * Description: + * Set sleep packet parameters to SPI packet structure. + * + * Input Parameters: + * pkt - Pointer to SPI packet structure. + * + * Returned Value: + * None + * + ****************************************************************************/ + +void altmdm_set_sleeppkt(FAR altmdm_spipkt_t *pkt); + +/**************************************************************************** + * Name: altmdm_is_valid_spipkt_header + * + * Description: + * Checks if the header received from ALT1250 is valid. + * + * Input Parameters: + * pkt - Pointer to SPI packet structure for reception. + * + * Returned Value: + * Returns true if the header is valid, false otherwise. + * + ****************************************************************************/ + +bool altmdm_is_valid_spipkt_header(FAR altmdm_spipkt_t *pkt); + +/**************************************************************************** + * Name: altmdm_is_sleeppkt_ok + * + * Description: + * Checks if the sleep packet received from ALT1250 is OK. + * + * Input Parameters: + * pkt - Pointer to SPI packet structure for reception. + * + * Returned Value: + * Returns true if the contents of the sleep packet are OK, + * false otherwise. + * + ****************************************************************************/ + +bool altmdm_is_sleeppkt_ok(FAR altmdm_spipkt_t *pkt); + +/**************************************************************************** + * Name: altmdm_do_hdr_transaction + * + * Description: + * Initiates a transaction for the SPI protocol header. + * + * Input Parameters: + * spidev - An SPI instance that communicates with the ALT1250. + * lower - An instance of the lower interface. + * tx_pkt - Pointer to SPI packet structure for sending. + * rx_pkt - Pointer to SPI packet structure for reception. + * + * Returned Value: + * None + * + ****************************************************************************/ + +void altmdm_do_hdr_transaction(FAR struct spi_dev_s *spidev, + FAR const struct alt1250_lower_s *lower, FAR altmdm_spipkt_t *tx_pkt, + FAR altmdm_spipkt_t *rx_pkt); + +/**************************************************************************** + * Name: altmdm_do_body_transaction + * + * Description: + * Initiates a transaction for the SPI protocol body. + * + * Input Parameters: + * spidev - An SPI instance that communicates with the ALT1250. + * lower - An instance of the lower interface. + * tx_pkt - Pointer to SPI packet structure for sending. + * rx_pkt - Pointer to SPI packet structure for reception. + * + * Returned Value: + * None + * + ****************************************************************************/ + +void altmdm_do_body_transaction(FAR struct spi_dev_s *spidev, + FAR const struct alt1250_lower_s *lower, FAR altmdm_spipkt_t *tx_pkt, + FAR altmdm_spipkt_t *rx_pkt); + +#endif /* __DRIVERS_MODEM_ALT1250_ALTMDM_SPI_H */ diff --git a/drivers/modem/alt1250/altmdm_timer.c b/drivers/modem/alt1250/altmdm_timer.c new file mode 100644 index 00000000000..ffa338b681d --- /dev/null +++ b/drivers/modem/alt1250/altmdm_timer.c @@ -0,0 +1,153 @@ +/**************************************************************************** + * drivers/modem/alt1250/altmdm_timer.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 + +#include +#include +#include +#include +#include + +#include "altmdm_timer.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define MY_TIMER_SIGNAL SIGUSR1 + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int set_signal(int signal_no, FAR _sa_sigaction_t handler) +{ + int ret; + sigset_t mask; + struct sigaction sa; + + sigemptyset(&mask); + nxsig_addset(&mask, signal_no); + + ret = nxsig_procmask(SIG_UNBLOCK, &mask, NULL); + if (ret != OK) + { + return ERROR; + } + + sa.sa_sigaction = handler; + sa.sa_flags = SA_SIGINFO; + sigfillset(&sa.sa_mask); + nxsig_delset(&sa.sa_mask, signal_no); + + ret = nxsig_action(signal_no, &sa, NULL, false); + if (ret != OK) + { + return ERROR; + } + + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +timer_t altmdm_timer_start(int first_ms, int interval_ms, + FAR _sa_sigaction_t handler, FAR void *ptr_param) +{ + int ret; + struct sigevent sev; + struct itimerspec timer; + timer_t timerid; + + if (set_signal(MY_TIMER_SIGNAL, handler) != OK) + { + return NULL; + } + + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = MY_TIMER_SIGNAL; + sev.sigev_value.sival_int = 0; + sev.sigev_value.sival_ptr = ptr_param; + + ret = timer_create(CLOCK_REALTIME, &sev, &timerid); + if (ret != OK) + { + return NULL; + } + + timer.it_value.tv_sec = first_ms / 1000; + timer.it_value.tv_nsec = (first_ms % 1000) * 1000 * 1000; + timer.it_interval.tv_sec = interval_ms / 1000; + timer.it_interval.tv_nsec = (interval_ms % 1000) * 1000 * 1000; + + ret = timer_settime(timerid, 0, &timer, NULL); + if (ret != OK) + { + return NULL; + } + + return timerid; +} + +int altmdm_timer_restart(timer_t timerid, int first_ms, int interval_ms) +{ + int ret; + struct itimerspec timer; + + timer.it_value.tv_sec = first_ms / 1000; + timer.it_value.tv_nsec = (first_ms % 1000) * 1000 * 1000; + timer.it_interval.tv_sec = interval_ms / 1000; + timer.it_interval.tv_nsec = (interval_ms % 1000) * 1000 * 1000; + + ret = timer_settime(timerid, 0, &timer, NULL); + if (ret != OK) + { + return ret; + } + + return ret; +} + +int altmdm_timer_is_running(timer_t timerid) +{ + struct itimerspec timer; + + timer_gettime(timerid, &timer); + + return (timer.it_value.tv_sec != 0 || timer.it_value.tv_nsec != 0); +} + +void altmdm_timer_stop(timer_t timerid) +{ + sigset_t mask; + + timer_delete(timerid); + + sigfillset(&mask); + nxsig_procmask(SIG_SETMASK, &mask, NULL); +} + diff --git a/drivers/modem/alt1250/altmdm_timer.h b/drivers/modem/alt1250/altmdm_timer.h new file mode 100644 index 00000000000..0d69de64e52 --- /dev/null +++ b/drivers/modem/alt1250/altmdm_timer.h @@ -0,0 +1,111 @@ +/**************************************************************************** + * drivers/modem/alt1250/altmdm_timer.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 __DEVICES_MODEM_ALT1250_ALTMDM_TIMER_H +#define __DEVICES_MODEM_ALT1250_ALTMDM_TIMER_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: altmdm_timer_start + * + * Description: + * Starts the timer with the specified timeout period. When the timeout + * occurs, the function specified in the handler is executed. + * + * Input Parameters: + * first_ms - The time until next expiration. + * interval_ms - The reload value of the timer. + * handler - Function pointer to be called when the timer expires. + * ptr_param - The value set in info->si_value.sival_ptr. + * info is the second argument of the handler. + * + * Returned Value: + * If the altmdm_timer_start() succeeds, timer instance will be returned. + * If an error occurs, the NULL will be returned. + * + ****************************************************************************/ + +timer_t altmdm_timer_start(int first_ms, int interval_ms, + FAR _sa_sigaction_t handler, FAR void *ptr_param); + +/**************************************************************************** + * Name: altmdm_timer_restart + * + * Description: + * Restarts the timer with the specified timeout period. + * + * Input Parameters: + * timerid - timer instatce created by altmdm_timer_start(). + * first_ms - The time until next expiration. + * interval_ms - The reload value of the timer. + * + * Returned Value: + * If the altmdm_timer_restart() succeeds, the value 0 (OK) will be + * returned. If an error occurs, the value -1 (ERROR) will be returned. + * + ****************************************************************************/ + +int altmdm_timer_restart(timer_t timerid, int first_ms, int interval_ms); + +/**************************************************************************** + * Name: altmdm_timer_is_running + * + * Description: + * Check whether the timer is running or not. + * + * Input Parameters: + * timerid - timer instatce created by altmdm_timer_start(). + * + * Returned Value: + * Return 1 if the timer is running, 0 otherwise. + * + ****************************************************************************/ + +int altmdm_timer_is_running(timer_t timerid); + +/**************************************************************************** + * Name: altmdm_timer_stop + * + * Description: + * Stops the timer. + * + * Input Parameters: + * timerid - timer instatce created by altmdm_timer_start(). + * + * Returned Value: + * None + * + ****************************************************************************/ + +void altmdm_timer_stop(timer_t timerid); + +#endif /* __DEVICES_MODEM_ALT1250_ALTMDM_TIMER_H */ diff --git a/drivers/modem/altair/Kconfig b/drivers/modem/altair/Kconfig deleted file mode 100644 index 77f85cd7eca..00000000000 --- a/drivers/modem/altair/Kconfig +++ /dev/null @@ -1,51 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# - -menuconfig MODEM_ALTMDM - bool "Altair modem support" - default n - select SPI - ---help--- - Enable driver for the Altair modem. - -if MODEM_ALTMDM - -config MODEM_ALTMDM_XFER_TASK_PRIORITY - int "transfer task priority" - default 170 - range 1 255 - -config MODEM_ALTMDM_DEBUG - bool "Enable debug mode for Altair modem driver" - default n - depends on MODEM_ALTMDM - ---help--- - Allow the Altair modem driver print debug information. - -config MODEM_ALTMDM_KEEP_WAKE_STATE - bool "Configuration to keep wake state of modem" - default n - depends on MODEM_ALTMDM - ---help--- - none - -config MODEM_ALTMDM_MAX_PACKET_SIZE - int "Max size to be transfer in bytes" - default 2064 - depends on MODEM_ALTMDM - ---help--- - none - -config MODEM_ALTMDM_SLEEP_TIMER_VAL - int "Modem sleep timer" - default 20 - depends on MODEM_ALTMDM - ---help--- - Modem sleep timer in milliseconds. - Modem may sleep if there is no data to be transferred - during specified time. Values smaller than 20 milliseconds - can not be specified. - -endif diff --git a/drivers/modem/altair/altmdm.c b/drivers/modem/altair/altmdm.c deleted file mode 100644 index d0dc862a308..00000000000 --- a/drivers/modem/altair/altmdm.c +++ /dev/null @@ -1,427 +0,0 @@ -/**************************************************************************** - * drivers/modem/altair/altmdm.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 - -#include -#include -#include -#include -#include -#include "altmdm_dev.h" -#include "altmdm_spi.h" -#include "altmdm_pm.h" -#include "altmdm_sys.h" - -#if defined(CONFIG_MODEM_ALTMDM) - -/**************************************************************************** - * Private Function Prototypes - ****************************************************************************/ - -/* Character driver methods. */ - -static ssize_t altmdm_read(FAR struct file *filep, FAR char *buffer, - size_t len); -static ssize_t altmdm_write(FAR struct file *filep, FAR const char *buffer, - size_t len); -static int altmdm_ioctl(FAR struct file *filep, int cmd, unsigned long arg); - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -/* This the vtable that supports the character driver interface. */ - -static const struct file_operations g_altmdmfops = -{ - NULL, /* open */ - NULL, /* close */ - altmdm_read, /* read */ - altmdm_write, /* write */ - NULL, /* seek */ - altmdm_ioctl, /* ioctl */ - NULL /* poll */ -#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS - , NULL /* unlink */ -#endif -}; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: is_poweron - * - * Description: - * Check ALTMDM power on. - * - ****************************************************************************/ - -static int is_poweron(FAR struct altmdm_dev_s *priv) -{ - int poweron; - - altmdm_sys_lock(&priv->lock); - - poweron = priv->poweron; - - altmdm_sys_unlock(&priv->lock); - - return poweron; -} - -/**************************************************************************** - * Name: altmdm_initialize - * - * Description: - * Initialize ALTMDM driver. - * - ****************************************************************************/ - -static int altmdm_initialize(FAR struct altmdm_dev_s *priv) -{ - int ret; - - ret = altmdm_sys_initlock(&priv->lock); - if (ret == ERROR) - { - m_err("altmdm_sys_initlock() failed:%d\n", ret); - } - - priv->poweron = 0; - - /* Initialize ALTMDM SPI driver. */ - - ret = altmdm_spi_init(priv); - - return ret; -} - -/**************************************************************************** - * Name: altmdm_uninitialize - * - * Description: - * Uninitialize ALTMDM driver. - * - ****************************************************************************/ - -static int altmdm_uninitialize(FAR struct altmdm_dev_s *priv) -{ - int ret; - - /* Uninitialize ALTMDM SPI driver */ - - altmdm_spi_uninit(priv); - - ret = altmdm_sys_deletelock(&priv->lock); - if (ret == ERROR) - { - m_err("altmdm_sys_deletelock() failed:%d\n", ret); - } - - return ret; -} - -/**************************************************************************** - * Name: altmdm_read - * - * Description: - * Standard character driver read method. - * - ****************************************************************************/ - -static ssize_t altmdm_read(FAR struct file *filep, - FAR char *buffer, - size_t len) -{ - FAR struct inode *inode = filep->f_inode; - FAR struct altmdm_dev_s *priv = inode->i_private; - ssize_t rsize = -EPERM; - - rsize = altmdm_spi_read(priv, buffer, len); - - return rsize; -} - -/**************************************************************************** - * Name: altmdm_write - * - * Description: - * Standard character driver write method. - * - ****************************************************************************/ - -static ssize_t altmdm_write(FAR struct file *filep, FAR const char *buffer, - size_t len) -{ - FAR struct inode *inode = filep->f_inode; - FAR struct altmdm_dev_s *priv = inode->i_private; - ssize_t wsize = -EPERM; - - if (is_poweron(priv)) - { - wsize = altmdm_spi_write(priv, buffer, len); - } - - return wsize; -} - -/**************************************************************************** - * Name: altmdm_ioctl - * - * Description: - * Standard character driver ioctl method. - * - ****************************************************************************/ - -static int altmdm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) -{ - FAR struct inode *inode = filep->f_inode; - FAR struct altmdm_dev_s *priv = inode->i_private; - int ret = -EPERM; - - switch (cmd) - { - case MODEM_IOC_POWERON: /* Power on ALTMDM. */ - { - altmdm_sys_lock(&priv->lock); - - if (!priv->poweron) - { - altmdm_pm_poweron(priv); - - priv->poweron = 1; - - ret = altmdm_spi_enable(priv); - } - else - { - ret = -EBUSY; - } - - altmdm_sys_unlock(&priv->lock); - } - break; - - case MODEM_IOC_POWEROFF: /* Power off ALTMDM. */ - { - altmdm_sys_lock(&priv->lock); - - if (priv->poweron) - { - ret = altmdm_spi_disable(priv); - - altmdm_pm_poweroff(priv); - - priv->poweron = 0; - } - else - { - ret = -EBUSY; - } - - altmdm_sys_unlock(&priv->lock); - } - break; - - case MODEM_IOC_READABORT: /* Abort the read process. */ - { - ret = altmdm_spi_readabort(priv); - } - break; - - case MODEM_IOC_SLEEP: /* Make ALTMDM sleep. */ - { - if (is_poweron(priv)) - { - ret = altmdm_spi_sleepmodem(priv); - } - } - break; - - case MODEM_IOC_PM_REGISTERCB: /* Register callback function. */ - { - ret = altmdm_pm_registercb(MODEM_PM_CB_TYPE_NORMAL, - (altmdm_pm_cbfunc_t) arg); - } - break; - - case MODEM_IOC_PM_DEREGISTERCB: /* Deregister callback function. */ - { - ret = altmdm_pm_deregistercb(MODEM_PM_CB_TYPE_NORMAL); - } - break; - - case MODEM_IOC_PM_ERR_REGISTERCB: /* Register error callback function. */ - { - ret = altmdm_pm_registercb(MODEM_PM_CB_TYPE_ERROR, - (altmdm_pm_cbfunc_t) arg); - } - break; - - case MODEM_IOC_PM_ERR_DEREGISTERCB: /* Deregister error callback - function. - */ - { - ret = altmdm_pm_deregistercb(MODEM_PM_CB_TYPE_ERROR); - } - break; - - case MODEM_IOC_PM_GETSTATE: /* Get ALTMDM power management state. */ - { - *(uint32_t *) arg = altmdm_pm_getstate(); - ret = 0; - } - break; - - case MODEM_IOC_PM_INITWAKELOCK: /* Initialize wakelock resource. */ - { - ret = altmdm_pm_initwakelock((struct altmdm_pm_wakelock_s *)arg); - } - break; - - case MODEM_IOC_PM_ACQUIREWAKELOCK: /* Acquire wakelock. */ - { - ret = altmdm_pm_acquirewakelock((struct altmdm_pm_wakelock_s *)arg); - } - break; - - case MODEM_IOC_PM_RELEASEWAKELOCK: /* Release wakelock. */ - { - ret = altmdm_pm_releasewakelock((struct altmdm_pm_wakelock_s *)arg); - } - break; - - case MODEM_IOC_PM_GETNUMOFWAKELOCK: /* Get number of wakelocks. */ - { - ret = altmdm_pm_getnumofwakelock((struct altmdm_pm_wakelock_s *)arg); - } - break; - - case MODEM_IOC_PM_GETWAKELOCKSTATE: /* Get wakelock state. */ - { - ret = altmdm_pm_getwakelockstate(); - } - break; - - default: - m_err("Unrecognized cmd: 0x%08x\n", cmd); - ret = -ENOTTY; - break; - } - - return ret; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: altmdm_register - * - * Description: - * Register the ALTMDM character device as 'devpath'. - * - * Input Parameters: - * devpath - The full path to the driver to register. E.g., "/dev/altmdm". - * dev - An instance of the SPI interface to use to communicate with - * ALTMDM. - * - * Returned Value: - * Not NULL on success; NULL on failure. - * - ****************************************************************************/ - -FAR void *altmdm_register(FAR const char *devpath, FAR struct spi_dev_s *dev, - FAR const struct altmdm_lower_s *lower) -{ - FAR struct altmdm_dev_s *priv; - int ret; - int size = sizeof(struct altmdm_dev_s); - - priv = (FAR struct altmdm_dev_s *)kmm_malloc(size); - if (!priv) - { - m_err("Failed to allocate instance.\n"); - return NULL; - } - - priv->spi = dev; - priv->path = strdup(devpath); - priv->lower = lower; - - ret = altmdm_initialize(priv); - if (ret < 0) - { - m_err("Failed to initialize ALTMDM driver.\n"); - kmm_free(priv); - return NULL; - } - - ret = register_driver(devpath, &g_altmdmfops, 0666, priv); - if (ret < 0) - { - m_err("Failed to register driver: %d\n", ret); - kmm_free(priv); - return NULL; - } - - return (FAR void *)priv; -} - -/**************************************************************************** - * Name: altmdm_unregister - * - * Description: - * Unregister the ALTMDM character device. - * - * Input Parameters: - * handle - The pointer that getting from altmdm_register. - * - * Returned Value: - * None. - * - ****************************************************************************/ - -void altmdm_unregister(FAR void *handle) -{ - FAR struct altmdm_dev_s *priv; - - if (handle) - { - priv = (FAR struct altmdm_dev_s *)handle; - - altmdm_uninitialize(priv); - - unregister_driver(priv->path); - - kmm_free(priv->path); - kmm_free(priv); - } -} - -#endif diff --git a/drivers/modem/altair/altmdm_dev.h b/drivers/modem/altair/altmdm_dev.h deleted file mode 100644 index da85ccbf08c..00000000000 --- a/drivers/modem/altair/altmdm_dev.h +++ /dev/null @@ -1,176 +0,0 @@ -/**************************************************************************** - * drivers/modem/altair/altmdm_dev.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_ALTAIR_ALTMDM_DEV_H -#define __DRIVERS_MODEM_ALTAIR_ALTMDM_DEV_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include "altmdm_spi.h" -#include "altmdm_sys.h" - -#if defined(CONFIG_MODEM_ALTMDM) - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct altmdm_dev_s -{ - FAR char *path; /* Registration path */ - FAR struct spi_dev_s *spi; - struct altmdm_spi_dev_s spidev; - struct altmdm_sys_lock_s lock; - int poweron; - FAR const struct altmdm_lower_s *lower; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: altmdm_spi_init - * - * Description: - * Initialize ALTMDM driver. - * - ****************************************************************************/ - -int altmdm_spi_init(FAR struct altmdm_dev_s *priv); - -/**************************************************************************** - * Name: altmdm_spi_uninit - * - * Description: - * Uninitialize ALTMDM driver. - * - ****************************************************************************/ - -int altmdm_spi_uninit(FAR struct altmdm_dev_s *priv); - -/**************************************************************************** - * Name: altmdm_spi_enable - * - * Description: - * Enable ALTMDM SPI driver. - * - ****************************************************************************/ - -int altmdm_spi_enable(FAR struct altmdm_dev_s *priv); - -/**************************************************************************** - * Name: altmdm_spi_disable - * - * Description: - * Disable ALTMDM SPI driver. - * - ****************************************************************************/ - -int altmdm_spi_disable(FAR struct altmdm_dev_s *priv); - -/**************************************************************************** - * Name: altmdm_spi_read - * - * Description: - * ALTMDM SPI driver read method. - * - ****************************************************************************/ - -ssize_t altmdm_spi_read(FAR struct altmdm_dev_s *priv, - FAR const char *buffer, size_t readlen); - -/**************************************************************************** - * Name: altmdm_spi_write - * - * Description: - * ALTMDM SPI driver write method. - * - ****************************************************************************/ - -ssize_t altmdm_spi_write(FAR struct altmdm_dev_s *priv, - FAR const char *buffer, size_t witelen); - -/**************************************************************************** - * Name: altmdm_spi_readabort - * - * Description: - * Abort the read process. - * - ****************************************************************************/ - -int altmdm_spi_readabort(FAR struct altmdm_dev_s *priv); - -/**************************************************************************** - * Name: altmdm_spi_sleepmodem - * - * Description: - * Make ALTMDM sleep. - * - ****************************************************************************/ - -int altmdm_spi_sleepmodem(FAR struct altmdm_dev_s *priv); - -/**************************************************************************** - * Name: altmdm_spi_setreceiverready - * - * Description: - * Set receiver ready notification. - * - ****************************************************************************/ - -int altmdm_spi_setreceiverready(FAR struct altmdm_dev_s *priv); - -/**************************************************************************** - * Name: altmdm_spi_isreceiverready - * - * Description: - * Check already notified or not by altmdm_spi_setreceiverready. - * - ****************************************************************************/ - -int altmdm_spi_isreceiverready(FAR struct altmdm_dev_s *priv); - -/**************************************************************************** - * Name: altmdm_spi_clearreceiverready - * - * Description: - * Clear receiver ready notification. - * - ****************************************************************************/ - -int altmdm_spi_clearreceiverready(FAR struct altmdm_dev_s *priv); - -/**************************************************************************** - * Name: altmdm_spi_gpioreadyisr - * - * Description: - * Interrupt handler for SLAVE_REQUEST GPIO line. - * - ****************************************************************************/ - -int altmdm_spi_gpioreadyisr(int irq, FAR void *context, FAR void *arg); - -#endif -#endif /* __DRIVERS_MODEM_ALTAIR_ALTMDM_DEV_H */ diff --git a/drivers/modem/altair/altmdm_pm.c b/drivers/modem/altair/altmdm_pm.c deleted file mode 100644 index 9fd72688561..00000000000 --- a/drivers/modem/altair/altmdm_pm.c +++ /dev/null @@ -1,775 +0,0 @@ -/**************************************************************************** - * drivers/modem/altair/altmdm_pm.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 - -#include -#include -#include - -#include -#include -#include - -#include "altmdm_sys.h" -#include "altmdm_pm.h" -#include "altmdm_pm_state.h" - -#if defined(CONFIG_MODEM_ALTMDM) - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Timeout is counted in units of millisecond. */ - -# define D2H_UP_EVENT_TIMEOUT (5*1000) - -# define GPIO_LOW (false) -# define GPIO_HIGH (true) - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct altmdm_dev_s *g_privdata = NULL; -static bool g_is_initdone = false; -static altmdm_pm_cbfunc_t g_pm_callback = NULL; -static altmdm_pm_cbfunc_t g_pm_errcallback = NULL; -static sq_queue_t g_wakelock; -static uint32_t g_boot_stat = MODEM_PM_ERR_RESET_BOOTSTAT_NONE; - -/**************************************************************************** - * Name: set_mreq_gpio - * - * Description: - * Control Master-request GPIO line. - * - ****************************************************************************/ - -static int set_mreq_gpio(FAR struct altmdm_dev_s *priv, bool value) -{ - DEBUGASSERT(priv && priv->lower); - priv->lower->master_request(value); - - return 0; -} - -/**************************************************************************** - * Name: set_h2d_gpio - * - * Description: - * Control Host to Device GPIO line. - * - ****************************************************************************/ - -static int set_h2d_gpio(FAR struct altmdm_dev_s *priv, bool value) -{ - DEBUGASSERT(priv && priv->lower); - priv->lower->wakeup(value); - - return 0; -} - -/**************************************************************************** - * Name: set_mreq_down - * - * Description: - * Deassert Master-request GPIO line. - * - ****************************************************************************/ - -static int set_mreq_down(FAR struct altmdm_dev_s *priv) -{ - return set_mreq_gpio(priv, GPIO_LOW); -} - -/**************************************************************************** - * Name: set_mreq_up - * - * Description: - * Assert Master-request GPIO line. - * - ****************************************************************************/ - -static int set_mreq_up(FAR struct altmdm_dev_s *priv) -{ - return set_mreq_gpio(priv, GPIO_HIGH); -} - -/**************************************************************************** - * Name: set_h2d_down - * - * Description: - * Deassert Host to Device GPIO line. - * - ****************************************************************************/ - -static int set_h2d_down(FAR struct altmdm_dev_s *priv) -{ - return set_h2d_gpio(priv, GPIO_LOW); -} - -/**************************************************************************** - * Name: set_h2d_up - * - * Description: - * Assert Host to Device GPIO line. - * - ****************************************************************************/ - -static int set_h2d_up(FAR struct altmdm_dev_s *priv) -{ - return set_h2d_gpio(priv, GPIO_HIGH); -} - -/**************************************************************************** - * Name: exe_callback - * - * Description: - * Execute callback of modem power manager. - * - ****************************************************************************/ - -static int exe_callback(uint32_t type, uint32_t cb_event) -{ - altmdm_pm_cbfunc_t lcallback = NULL; - - if (type == MODEM_PM_CB_TYPE_ERROR) - { - lcallback = g_pm_errcallback; - } - else - { - lcallback = g_pm_callback; - } - - if (lcallback == NULL) - { - return -EPERM; - } - - lcallback(cb_event); - - return 0; -} - -/**************************************************************************** - * Name: sleep_modem_itself - * - * Description: - * The modem slept on itself, it transitions to the sleep state. - * - ****************************************************************************/ - -static int sleep_modem_itself(FAR struct altmdm_dev_s *priv) -{ - set_h2d_down(priv); - - /* Transitions to the sleep state. */ - - altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_SLEEP); - - /* Perform processing at the time of state transition. */ - - exe_callback(MODEM_PM_CB_TYPE_NORMAL, MODEM_PM_CB_SLEEP); - - return 0; -} - -/**************************************************************************** - * Name: modem_sleep_procedure - * - * Description: - * Make the modem transition to sleep. - * - ****************************************************************************/ - -static int modem_sleep_procedure(FAR struct altmdm_dev_s *priv) -{ - int ret; - - ret = set_h2d_down(priv); - if (ret == 0) - { - /* Transitions to the sleep state. */ - - altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_SLEEP); - - /* Perform processing at the time of state transition. */ - - exe_callback(MODEM_PM_CB_TYPE_NORMAL, MODEM_PM_CB_SLEEP); - } - - return ret; -} - -/**************************************************************************** - * Name: modem_wakeup_procedure - * - * Description: - * Make the modem transition to wakeup. - * - ****************************************************************************/ - -static int modem_wakeup_procedure(FAR struct altmdm_dev_s *priv, - CODE int (*wait_fn)(FAR struct altmdm_dev_s *priv, uint32_t timeout_ms)) -{ - int ret = 0; - - if (MODEM_PM_INTERNAL_STATE_WAKE == altmdm_pm_getinternalstate()) - { - return MODEM_PM_WAKEUP_ALREADY; - } - - altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_GOING_TO_WAKE); - - ret = set_h2d_up(priv); - if (ret == 0) - { - if (wait_fn) - { - set_mreq_up(priv); - - ret = wait_fn(priv, D2H_UP_EVENT_TIMEOUT); - if (ret != 0) - { - m_err("ERR:%04d device is not up.\n", __LINE__); - - /* Do rollback. */ - - set_mreq_down(priv); - - set_h2d_down(priv); - - altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_SLEEP); - - ret = MODEM_PM_WAKEUP_FAIL; - } - else - { - /* Transitions to the wake state. */ - - altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_WAKE); - - /* Perform processing at the time of state transition. */ - - exe_callback(MODEM_PM_CB_TYPE_NORMAL, MODEM_PM_CB_WAKE); - - ret = MODEM_PM_WAKEUP_DONE; - } - } - else - { - /* Transitions to the wake state. */ - - altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_WAKE); - - /* Perform processing at the time of state transition. */ - - exe_callback(MODEM_PM_CB_TYPE_NORMAL, MODEM_PM_CB_WAKE); - - ret = MODEM_PM_WAKEUP_DONE; - } - } - - return ret; -} - -/**************************************************************************** - * Name: sleep_is_possible - * - * Description: - * Check if the modem can sleep. - * - ****************************************************************************/ - -static int sleep_is_possible(FAR struct altmdm_dev_s *priv) -{ -# ifdef CONFIG_MODEM_ALTMDM_KEEP_WAKE_STATE - return -EPERM; -# else - int num_of_lock; - uint32_t pm_state; - - pm_state = altmdm_pm_getinternalstate(); - if (pm_state != MODEM_PM_INTERNAL_STATE_WAKE) - { - return -EBUSY; - } - - num_of_lock = altmdm_pm_getwakelockstate(); - if (num_of_lock) - { - return -EBUSY; - } - - if (g_boot_stat != MODEM_PM_ERR_RESET_BOOTSTAT_DONE) - { - return -EBUSY; - } - - return 0; -# endif -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: altmdm_pm_init - * - * Description: - * Initialize the ALTMDM power manager driver. - * - ****************************************************************************/ - -int altmdm_pm_init(FAR struct altmdm_dev_s *priv) -{ - if (g_is_initdone) - { - return -EPERM; - } - - g_is_initdone = true; - - g_privdata = priv; - - altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_SLEEP); - - sq_init(&g_wakelock); - - return 0; -} - -/**************************************************************************** - * Name: altmdm_pm_uninit - * - * Description: - * Uninitialize the ALTMDM power manager driver. - * - ****************************************************************************/ - -int altmdm_pm_uninit(FAR struct altmdm_dev_s *priv) -{ - if (!g_is_initdone) - { - return -EPERM; - } - - g_is_initdone = false; - - altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_SLEEP); - - sq_init(&g_wakelock); - - return 0; -} - -/**************************************************************************** - * Name: altmdm_pm_wakeup - * - * Description: - * Make modem wake up. - * - ****************************************************************************/ - -int altmdm_pm_wakeup(FAR struct altmdm_dev_s *priv, - CODE int (*wait_fn)(FAR struct altmdm_dev_s *priv, uint32_t timeout_ms)) -{ - int ret = MODEM_PM_WAKEUP_FAIL; - - if (!g_is_initdone) - { - return -EPERM; - } - - ret = modem_wakeup_procedure(priv, wait_fn); - - return ret; -} - -/**************************************************************************** - * Name: altmdm_pm_notify_reset - * - * Description: - * Notify reset has done. - * - ****************************************************************************/ - -int altmdm_pm_notify_reset(FAR struct altmdm_dev_s *priv) -{ - if (!g_is_initdone) - { - return -EPERM; - } - - if (MODEM_PM_ERR_RESET_BOOTSTAT_NONE != g_boot_stat) - { - exe_callback(MODEM_PM_CB_TYPE_ERROR, g_boot_stat); - } - else - { - m_err("ERR:%04d Unexpected boot stat:%d.\n", - __LINE__, g_boot_stat); - } - - return 0; -} - -/**************************************************************************** - * Name: altmdm_pm_registercb - * - * Description: - * Register callback for ALTMDM power manager driver. - * - ****************************************************************************/ - -int altmdm_pm_registercb(uint32_t type, altmdm_pm_cbfunc_t cb) -{ - if (!g_is_initdone) - { - return -EPERM; - } - - if (type == MODEM_PM_CB_TYPE_ERROR) - { - if (g_pm_errcallback == NULL) - { - g_pm_errcallback = cb; - } - } - else - { - if (g_pm_callback == NULL) - { - g_pm_callback = cb; - } - } - - return 0; -} - -/**************************************************************************** - * Name: altmdm_pm_deregistercb - * - * Description: - * Deregister callback for ALTMDM power manager driver. - * - ****************************************************************************/ - -int altmdm_pm_deregistercb(uint32_t type) -{ - altmdm_pm_cbfunc_t *lcallback = NULL; - - if (!g_is_initdone) - { - return -EPERM; - } - - if (type == MODEM_PM_CB_TYPE_ERROR) - { - lcallback = &g_pm_errcallback; - } - else - { - lcallback = &g_pm_callback; - } - - if (*lcallback == NULL) - { - return -EPERM; - } - - *lcallback = NULL; - - return 0; -} - -/**************************************************************************** - * Name: altmdm_pm_sleepmodem - * - * Description: - * Make modem sleep. - * - ****************************************************************************/ - -int altmdm_pm_sleepmodem(FAR struct altmdm_dev_s *priv) -{ - int ret; - - if (!g_is_initdone) - { - return -EPERM; - } - - altmdm_pm_setinternalstate(MODEM_PM_INTERNAL_STATE_GOING_TO_SLEEP); - ret = modem_sleep_procedure(priv); - - return ret; -} - -/**************************************************************************** - * Name: altmdm_pm_cansleep - * - * Description: - * Check if modem can sleep. - * - ****************************************************************************/ - -int altmdm_pm_cansleep(FAR struct altmdm_dev_s *priv) -{ - int ret; - - if (!g_is_initdone) - { - return -EPERM; - } - - ret = sleep_is_possible(priv); - if (ret == 0) - { - m_info("possible to sleep.\n"); - ret = 1; - } - else - { - m_info("impossible to sleep.\n"); - ret = 0; - } - - return ret; -} - -/**************************************************************************** - * Name: altmdm_pm_initwakelock - * - * Description: - * Initialize the modem wakelock resource. - * - ****************************************************************************/ - -int altmdm_pm_initwakelock(FAR struct altmdm_pm_wakelock_s *lock) -{ - if (!g_is_initdone) - { - return -EPERM; - } - - if (!lock) - { - return -EINVAL; - } - - memset(lock, 0, sizeof(struct altmdm_pm_wakelock_s)); - - return 0; -} - -/**************************************************************************** - * Name: altmdm_pm_acquirewakelock - * - * Description: - * Acquire the modem wakelock. - * - ****************************************************************************/ - -int altmdm_pm_acquirewakelock(FAR struct altmdm_pm_wakelock_s *lock) -{ - irqstate_t flags; - - if (!g_is_initdone) - { - return -EPERM; - } - - if (!lock) - { - return -EINVAL; - } - - flags = enter_critical_section(); - - if (lock->count == 0) - { - sq_addlast((FAR sq_entry_t *) & lock->queue, &g_wakelock); - } - - lock->count++; - - leave_critical_section(flags); - - return 0; -} - -/**************************************************************************** - * Name: altmdm_pm_releasewakelock - * - * Description: - * Release the modem wakelock. - * - ****************************************************************************/ - -int altmdm_pm_releasewakelock(FAR struct altmdm_pm_wakelock_s *lock) -{ - irqstate_t flags; - - if (!g_is_initdone) - { - return -EPERM; - } - - if (!lock && (lock->count < 1)) - { - return -EINVAL; - } - - flags = enter_critical_section(); - - lock->count--; - - if (lock->count == 0) - { - sq_rem((FAR sq_entry_t *) & lock->queue, &g_wakelock); - } - - leave_critical_section(flags); - - return 0; -} - -/**************************************************************************** - * Name: altmdm_pm_getnumofwakelock - * - * Description: - * Get the lock count of the specified wakelock. - * - ****************************************************************************/ - -int altmdm_pm_getnumofwakelock(FAR struct altmdm_pm_wakelock_s *lock) -{ - if (!g_is_initdone) - { - return -EPERM; - } - - if (!lock) - { - return -EINVAL; - } - - return lock->count; -} - -/**************************************************************************** - * Name: altmdm_pm_getwakelockstate - * - * Description: - * Get the wakelock status. If the return value is 0, it means that it is - * not locked. Otherwise it means that someone is locking. - * - ****************************************************************************/ - -int altmdm_pm_getwakelockstate(void) -{ - int num; - irqstate_t flags; - - if (!g_is_initdone) - { - return -EPERM; - } - - flags = enter_critical_section(); - - num = sq_count(&g_wakelock); - - leave_critical_section(flags); - - return num; -} - -/**************************************************************************** - * Name: altmdm_pm_poweron - * - * Description: - * Modem power on. - * - ****************************************************************************/ - -int altmdm_pm_poweron(FAR struct altmdm_dev_s *priv) -{ - if (!g_is_initdone) - { - return -EPERM; - } - - priv->lower->poweron(); - - return 0; -} - -/**************************************************************************** - * Name: altmdm_pm_poweroff - * - * Description: - * Modem power off. - * - ****************************************************************************/ - -int altmdm_pm_poweroff(FAR struct altmdm_dev_s *priv) -{ - if (!g_is_initdone) - { - return -EPERM; - } - - priv->lower->poweroff(); - sleep_modem_itself(priv); - - return 0; -} - -/**************************************************************************** - * Name: altmdm_pm_set_bootstatus - * - * Description: - * Set boot status. - * - ****************************************************************************/ - -int altmdm_pm_set_bootstatus(FAR struct altmdm_dev_s *priv, uint32_t status) -{ - if (!g_is_initdone) - { - return -EPERM; - } - - g_boot_stat = status; - - return 0; -} - -#endif diff --git a/drivers/modem/altair/altmdm_pm.h b/drivers/modem/altair/altmdm_pm.h deleted file mode 100644 index d76b4161d5c..00000000000 --- a/drivers/modem/altair/altmdm_pm.h +++ /dev/null @@ -1,212 +0,0 @@ -/**************************************************************************** - * drivers/modem/altair/altmdm_pm.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_ALTAIR_ALTMDM_PM_H -#define __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include "altmdm_dev.h" -#include "altmdm_sys.h" -#include "altmdm_pm_state.h" - -#if defined(CONFIG_MODEM_ALTMDM) - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MODEM_PM_WAKEUP_DONE (0) -#define MODEM_PM_WAKEUP_ALREADY (1) -#define MODEM_PM_WAKEUP_FAIL (2) - -#define MODEM_PM_CB_SLEEP (0) -#define MODEM_PM_CB_WAKE (1) - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: altmdm_pm_init - * - * Description: - * Initialize the ALTMDM power manager driver. - * - ****************************************************************************/ - -int altmdm_pm_init(FAR struct altmdm_dev_s *priv); - -/**************************************************************************** - * Name: altmdm_pm_uninit - * - * Description: - * Uninitialize the ALTMDM power manager driver. - * - ****************************************************************************/ - -int altmdm_pm_uninit(FAR struct altmdm_dev_s *priv); - -/**************************************************************************** - * Name: altmdm_pm_wakeup - * - * Description: - * Make modem wake up. - * - ****************************************************************************/ - -int altmdm_pm_wakeup(FAR struct altmdm_dev_s *priv, - CODE int (*wait_fn)(FAR struct altmdm_dev_s *priv, uint32_t timeout_ms)); - -/**************************************************************************** - * Name: altmdm_pm_notify_reset - * - * Description: - * Notify reset has done. - * - ****************************************************************************/ - -int altmdm_pm_notify_reset(FAR struct altmdm_dev_s *priv); - -/**************************************************************************** - * Name: altmdm_pm_registercb - * - * Description: - * Register callback for ALTMDM power manager driver. - * - ****************************************************************************/ - -int altmdm_pm_registercb(uint32_t type, altmdm_pm_cbfunc_t cb); - -/**************************************************************************** - * Name: altmdm_pm_deregistercb - * - * Description: - * Deregister callback for ALTMDM power manager driver. - * - ****************************************************************************/ - -int altmdm_pm_deregistercb(uint32_t type); - -/**************************************************************************** - * Name: altmdm_pm_sleepmodem - * - * Description: - * Make modem sleep. - * - ****************************************************************************/ - -int altmdm_pm_sleepmodem(FAR struct altmdm_dev_s *priv); - -/**************************************************************************** - * Name: altmdm_pm_cansleep - * - * Description: - * Check if modem can sleep. - * - ****************************************************************************/ - -int altmdm_pm_cansleep(FAR struct altmdm_dev_s *priv); - -/**************************************************************************** - * Name: altmdm_pm_initwakelock - * - * Description: - * Initialize the modem wakelock resource. - * - ****************************************************************************/ - -int altmdm_pm_initwakelock(FAR struct altmdm_pm_wakelock_s *lock); - -/**************************************************************************** - * Name: altmdm_pm_acquirewakelock - * - * Description: - * Acquire the modem wakelock. - * - ****************************************************************************/ - -int altmdm_pm_acquirewakelock(FAR struct altmdm_pm_wakelock_s *lock); - -/**************************************************************************** - * Name: altmdm_pm_releasewakelock - * - * Description: - * Release the modem wakelock. - * - ****************************************************************************/ - -int altmdm_pm_releasewakelock(FAR struct altmdm_pm_wakelock_s *lock); - -/**************************************************************************** - * Name: altmdm_pm_getnumofwakelock - * - * Description: - * Get the lock count of the specified wakelock. - * - ****************************************************************************/ - -int altmdm_pm_getnumofwakelock(FAR struct altmdm_pm_wakelock_s *lock); - -/**************************************************************************** - * Name: altmdm_pm_getwakelockstate - * - * Description: - * Get the wakelock status. If the return value is 0, it means that it is - * not locked. Otherwise it means that someone is locking. - * - ****************************************************************************/ - -int altmdm_pm_getwakelockstate(void); - -/**************************************************************************** - * Name: altmdm_pm_poweron - * - * Description: - * Modem power on. - * - ****************************************************************************/ - -int altmdm_pm_poweron(FAR struct altmdm_dev_s *priv); - -/**************************************************************************** - * Name: altmdm_pm_poweroff - * - * Description: - * Modem power off. - * - ****************************************************************************/ - -int altmdm_pm_poweroff(FAR struct altmdm_dev_s *priv); - -/**************************************************************************** - * Name: altmdm_pm_set_bootstatus - * - * Description: - * Set boot status. - * - ****************************************************************************/ - -int altmdm_pm_set_bootstatus(FAR struct altmdm_dev_s *priv, uint32_t status); - -#endif -#endif /* __DRIVERS_MODEM_ALTAIR_ALTMDM_PM_H */ diff --git a/drivers/modem/altair/altmdm_pm_state.c b/drivers/modem/altair/altmdm_pm_state.c deleted file mode 100644 index 9962b44b389..00000000000 --- a/drivers/modem/altair/altmdm_pm_state.c +++ /dev/null @@ -1,139 +0,0 @@ -/**************************************************************************** - * drivers/modem/altair/altmdm_pm_state.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 - -#include -#include "altmdm_pm_state.h" - -#if defined(CONFIG_MODEM_ALTMDM) - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static uint32_t g_stateofmodem; - -#ifdef CONFIG_MODEM_PM_PUTSTATE -static char *g_putstring[MODEM_PM_INTERNAL_STATE_MAX] = -{ - "SLEEP", - "GOING_TO_WAKE", - "WAKE", - "GOING_TO_SLEEP" -}; -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: altmdm_pm_getstate - * - * Description: - * Get current modem state. - * - ****************************************************************************/ - -uint32_t altmdm_pm_getstate(void) -{ - uint32_t get_state; - uint32_t internal_state; - - internal_state = altmdm_pm_getinternalstate(); - - switch (internal_state) - { - case MODEM_PM_INTERNAL_STATE_SLEEP: - case MODEM_PM_INTERNAL_STATE_GOING_TO_WAKE: - get_state = MODEM_PM_STATE_SLEEP; - break; - - case MODEM_PM_INTERNAL_STATE_WAKE: - case MODEM_PM_INTERNAL_STATE_GOING_TO_SLEEP: - get_state = MODEM_PM_STATE_WAKE; - break; - - default: - get_state = MODEM_PM_STATE_WAKE; - break; - } - - return get_state; -} - -/**************************************************************************** - * Name: altmdm_pm_getinternalstate - * - * Description: - * Get internal modem state. - * - ****************************************************************************/ - -uint32_t altmdm_pm_getinternalstate(void) -{ - uint32_t get_state; - irqstate_t flags; - - flags = enter_critical_section(); - - get_state = g_stateofmodem; - - leave_critical_section(flags); - - return get_state; -} - -/**************************************************************************** - * Name: altmdm_pm_setinternalstate - * - * Description: - * Set internal modem state. - * - ****************************************************************************/ - -void altmdm_pm_setinternalstate(uint32_t state) -{ - irqstate_t flags; -#ifdef CONFIG_MODEM_PM_PUTSTATE - uint32_t prev_state; -#endif - - if (state < MODEM_PM_INTERNAL_STATE_MAX) - { - flags = enter_critical_section(); -#ifdef CONFIG_MODEM_PM_PUTSTATE - prev_state = g_stateofmodem; -#endif - g_stateofmodem = state; - - leave_critical_section(flags); -#ifdef CONFIG_MODEM_PM_PUTSTATE - m_err("MODEM State [%d:%s]-->[%d:%s]\n", - prev_state, g_putstring[prev_state], state, g_putstring[state]); -#endif - } -} -#endif diff --git a/drivers/modem/altair/altmdm_spi.c b/drivers/modem/altair/altmdm_spi.c deleted file mode 100644 index 7e261d25c25..00000000000 --- a/drivers/modem/altair/altmdm_spi.c +++ /dev/null @@ -1,2337 +0,0 @@ -/**************************************************************************** - * drivers/modem/altair/altmdm_spi.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 -#include -#include - -#include -#include -#include -#include - -#include "altmdm_sys.h" -#include "altmdm_pm.h" -#include "altmdm_pm_state.h" - -#if defined(CONFIG_MODEM_ALTMDM) - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define EVENT_BIT(b) (1<<(b)) -#define EVENT_NONE (0) -#define EVENT_TXREQ EVENT_BIT(0) -#define EVENT_RXREQ EVENT_BIT(1) -#define EVENT_CANCEL EVENT_BIT(2) -#define EVENT_EXIT EVENT_BIT(3) -#define EVENT_RXRDY EVENT_BIT(4) -#define EVENT_RXBUFRDY EVENT_BIT(5) -#define EVENT_TX_DONE EVENT_BIT(6) -#define EVENT_RX_DONE EVENT_BIT(7) -#define EVENT_SLEEPREQ EVENT_BIT(8) -#define EVENT_SLEEP_DONE EVENT_BIT(9) -#define EVENT_SV_TIMER_EXP EVENT_BIT(10) -#define EVENT_XFERRDY EVENT_BIT(11) -#define EVENT_REQMASK (EVENT_TXREQ | EVENT_RXREQ | EVENT_SLEEPREQ | \ - EVENT_SV_TIMER_EXP) -#define EVENT_TRANS_WAIT (EVENT_TXREQ | EVENT_RXREQ | EVENT_RXBUFRDY | \ - EVENT_SLEEPREQ | EVENT_SV_TIMER_EXP | EVENT_EXIT) -#if defined(CONFIG_MODEM_ALTMDM_XFER_TASK_PRIORITY) -# define XFER_TASK_PRI (CONFIG_MODEM_ALTMDM_XFER_TASK_PRIORITY) -#else -# define XFER_TASK_PRI (170) -#endif - -#define XFER_TASK_STKSIZE (1536) -#define XFER_TASK_NAME "altmdm_xfer_task" -#if defined(CONFIG_MODEM_ALTMDM_MAX_PACKET_SIZE) -# if ((CONFIG_MODEM_ALTMDM_MAX_PACKET_SIZE & 0x3) != 0) -# error MODEM_ALTMDM_MAX_PACKET_SIZE must be aligned 0x4 (4B) -# endif -# define MAX_PKT_SIZE (CONFIG_MODEM_ALTMDM_MAX_PACKET_SIZE) -#else -# define MAX_PKT_SIZE (2064) -#endif -#define UNIT_SIZE (4) -#define RX_ENABLE (0) -#define RX_DISABLE (1) -#define SLEEP_OK (0) -#define SLEEP_NG (-EBUSY) - -/* Timeout is counted in units of millisecond. */ - -#define WAIT_RXREQ_TIMEOUT (5) -#define WAIT_RXREQ_HEADER_TIMEOUT (5 * 1000) -#define WAIT_XFERRDY_TIMEOUT (25 * 1000) -#if defined(CONFIG_MODEM_ALTMDM_SLEEP_TIMER_VAL) -# if (CONFIG_MODEM_ALTMDM_SLEEP_TIMER_VAL < 20) -# error MODEM_ALTMDM_SLEEP_TIMER_VAL too small -# endif -# define SV_TIMER_TIMOUT_VAL (CONFIG_MODEM_ALTMDM_SLEEP_TIMER_VAL) -#else -# define SV_TIMER_TIMOUT_VAL (20) -#endif -#define WRITE_WAIT_TIMEOUT (ALTMDM_SYS_FLAG_TMOFEVR) -#define SREQ_WAIT_TIMEOUT (ALTMDM_SYS_FLAG_TMOFEVR) -#define YIELD_TASK_NOBUFF (100 * 1000) /* microsecond */ - -/* Defines for transfer mode */ - -#define MODE_RXDATA (0) /* Data receive mode. */ -#define MODE_TXDATA (1) /* Data send mode. */ -#define MODE_TRXDATA (2) /* Data send and receive mode. */ -#define MODE_RXDATANOBUFF (3) /* Data receive mode when there is no - * receiving buffer. - */ -#define MODE_TRXDATANOBUFF (4) /* Data send and receive mode when - * there is no receiving buffer. - */ -#define MODE_RXINVALID (5) /* Data receive mode when receiving - * header is wrong. - */ -#define MODE_TRXHEADERFAILTXREQ (6) /* Data send and receive mode when - * header transfer fails. Send request - * triggered. - */ -#define MODE_TRXHEADERFAILRXREQ (7) /* Data receive mode when header - * transfer fails. Receive request - * triggered. - */ -#define MODE_RXRESET (8) /* Reset packet receive mode. */ -#define MODE_TRXRESET (9) /* Data send and reset packet receive - * mode. - */ - -/* Defines for transfer result code */ - -#define TRANS_OK (1) /* OK. */ -#define TRANS_OK_RXDATANOBUFF (-1) /* OK when MODE_RXDATANOBUFF mode. */ -#define TRANS_OK_TRXDATANORXBUFF (-2) /* OK when MODE_TRXDATANOBUFF mode. */ -#define TRANS_RXINVALID (-3) /* NG when MODE_RXINVALID mode. */ -#define TRANS_WAITRCVRTMO (-4) /* NG when receiver ready timeout. */ -#define TRANS_OK_RCVBUFFUL (-5) /* OK when receiver is buffer full. */ - -#define RESET_BOOTSTAT_BOOTING (0) /* Boot stat: booting */ -#define RESET_BOOTSTAT_UPDATING (1) /* Boot stat: updating */ - -#define STAT_INF_GET_BOOTSTAT (1 << 1) /* Status info: Get bootstatus bit */ -#define STAT_INF_RESET (1 << 2) /* Status info: Reset bit */ -#define STAT_INF_BUFFFULL (1 << 3) /* Status info: Buffer full bit */ - -#define STAT_INF_IS_RESET(info) ((info & STAT_INF_RESET) >> 2) -#define STAT_INF_IS_BUFF_FULL(info) ((info & STAT_INF_BUFFFULL) >> 3) - -/**************************************************************************** - * Private Data - ****************************************************************************/ - -static struct altmdm_dev_s *g_privdata = NULL; - -/**************************************************************************** - * Private Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: svtimer_handler - * - * Description: - * Timeout handler for supervisory timer. - * - ****************************************************************************/ - -static void svtimer_handler(int signo, FAR siginfo_t * info, - FAR void *ucontext) -{ - FAR struct altmdm_dev_s *priv = - (FAR struct altmdm_dev_s *)(info->si_value.sival_ptr); - struct altmdm_sys_flagstate_s flag_status; - - altmdm_sys_referflag(&priv->spidev.xfer_flag, &flag_status); - if (!(flag_status.flag_pattern & EVENT_SV_TIMER_EXP)) - { - altmdm_sys_setflag(&priv->spidev.xfer_flag, EVENT_SV_TIMER_EXP); - } -} - -/**************************************************************************** - * Name: init_svtimer - * - * Description: - * Initialize supervisory timer. - * - ****************************************************************************/ - -static int init_svtimer(FAR struct altmdm_dev_s *priv) -{ - priv->spidev.sleep_param.sv_timerid = NULL; - - return 0; -} - -/**************************************************************************** - * Name: delete_svtimer - * - * Description: - * Delete supervisory timer. - * - ****************************************************************************/ - -static int delete_svtimer(FAR struct altmdm_dev_s *priv) -{ - altmdm_sys_stoptimer(priv->spidev.sleep_param.sv_timerid); - priv->spidev.sleep_param.sv_timerid = NULL; - - return 0; -} - -/**************************************************************************** - * Name: start_svtimer - * - * Description: - * Start supervisory timer. - * - ****************************************************************************/ - -static int start_svtimer(FAR struct altmdm_dev_s *priv) -{ - timer_t timerid; - - timerid = altmdm_sys_starttimer(SV_TIMER_TIMOUT_VAL, SV_TIMER_TIMOUT_VAL, - svtimer_handler, 0, priv); - if (timerid == NULL) - { - return -1; - } - - priv->spidev.sleep_param.sv_timerid = timerid; - - return 0; -} - -/**************************************************************************** - * Name: stop_svtimer - * - * Description: - * Stop supervisory timer. - * - ****************************************************************************/ - -static int stop_svtimer(FAR struct altmdm_dev_s *priv) -{ - altmdm_sys_stoptimer(priv->spidev.sleep_param.sv_timerid); - priv->spidev.sleep_param.sv_timerid = NULL; - - return 0; -} - -/**************************************************************************** - * Name: do_dmaxfer - * - * Description: - * Execute DMA transfer. - * - ****************************************************************************/ - -static int do_dmaxfer(FAR struct altmdm_dev_s *priv, FAR void *tx_buffer, - FAR void *rx_buffer, size_t dma_size) -{ - SPI_EXCHANGE(priv->spi, tx_buffer, rx_buffer, dma_size); - - return 0; -} - -/**************************************************************************** - * Name: get_dmasize - * - * Description: - * Get the data size used for DMA transfer. - * - ****************************************************************************/ - -static int get_dmasize(FAR struct altmdm_dev_s *priv, int data_size) -{ - return data_size; -} - -/**************************************************************************** - * Name: wait_receiverready - * - * Description: - * Wait until receiver is ready. - * - ****************************************************************************/ - -static int wait_receiverready(FAR struct altmdm_dev_s *priv, - uint32_t timeout_ms) -{ - int ret; - uint32_t ptn; - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - ret = altmdm_sys_waitflag(&spidev->xfer_flag, EVENT_RXREQ, - ALTMDM_SYS_FLAG_WMODEOR, &ptn, - timeout_ms); - if (ret != 0) - { - m_err("receiver ready timeout.\n"); - return TRANS_WAITRCVRTMO; - } - - return 0; -} - -/**************************************************************************** - * Name: wait_xferready - * - * Description: - * Wait until xfer is ready. - * - ****************************************************************************/ - -static int wait_xferready(FAR struct altmdm_dev_s *priv) -{ - int ret; - uint32_t ptn; - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - ret = altmdm_sys_waitflag(&spidev->xferready_flag, EVENT_XFERRDY, - ALTMDM_SYS_FLAG_WMODEOR, &ptn, - WAIT_XFERRDY_TIMEOUT); - if (ret != 0) - { - m_err("xfer ready timeout.\n"); - - /* Make it ready to transfer. - * It is assumed that modem does not implement reset packet. - */ - - if (!spidev->is_xferready) - { - spidev->is_xferready = true; - m_info("ready to xfer\n"); - } - - return -1; - } - - return 0; -} - -/**************************************************************************** - * Name: notify_xferready - * - * Description: - * Notify xfer is ready. - * - ****************************************************************************/ - -static int notify_xferready(FAR struct altmdm_dev_s *priv) -{ - int ret; - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - ret = altmdm_sys_setflag(&spidev->xferready_flag, EVENT_XFERRDY); - - return ret; -} - -/**************************************************************************** - * Name: init_rxbuffer - * - * Description: - * Initialize the receive buffer used for data transfer. - * - ****************************************************************************/ - -static void init_rxbuffer(FAR struct altmdm_dev_s *priv, - FAR struct altmdm_spi_rxbuff_s **rxbuff, - uint32_t unit_size) -{ - FAR struct altmdm_spi_rxbuff_s *l_buff = NULL; - - l_buff = (FAR struct altmdm_spi_rxbuff_s *)kmm_malloc - (sizeof(struct altmdm_spi_rxbuff_s)); - if (l_buff == NULL) - { - m_err("cannot allocate memory for received buffer\n"); - } - else - { - memset(l_buff, 0x00, sizeof(struct altmdm_spi_rxbuff_s)); - - l_buff->buff_addr = (char *)kmm_malloc(unit_size); - if (l_buff->buff_addr == NULL) - { - m_err("cannot allocate memory for received buffer\n"); - kmm_free(l_buff); - l_buff = NULL; - } - else - { - l_buff->buff_size = unit_size; - } - } - - *rxbuff = l_buff; -} - -/**************************************************************************** - * Name: uninit_rxbuffer - * - * Description: - * Uninitialize the receive buffer used for data transfer. - * - ****************************************************************************/ - -static void uninit_rxbuffer(FAR struct altmdm_dev_s *priv, - FAR struct altmdm_spi_rxbuff_s *rxbuff) -{ - if (rxbuff != NULL) - { - if (rxbuff->buff_addr != NULL) - { - kmm_free(rxbuff->buff_addr); - } - - kmm_free(rxbuff); - } -} - -/**************************************************************************** - * Name: alloc_rxbuffer - * - * Description: - * Get the allocated receive buffer. - * - ****************************************************************************/ - -static void alloc_rxbuffer(FAR struct altmdm_dev_s *priv, - FAR struct altmdm_spi_rxbuff_s **rxbuff, - uint32_t size) -{ - if (priv->spidev.rxbuffinfo.free_buff == NULL) - { - m_err("cannot allocate free rx buffer\n"); - } - else - { - *rxbuff = priv->spidev.rxbuffinfo.free_buff; - priv->spidev.rxbuffinfo.free_buff = NULL; - } -} - -/**************************************************************************** - * Name: free_rxbuffer - * - * Description: - * Release allocated receive buffer. - * - ****************************************************************************/ - -static void free_rxbuffer(FAR struct altmdm_dev_s *priv, - FAR struct altmdm_spi_rxbuff_s *rxbuff) -{ - if (priv->spidev.rxbuffinfo.free_buff != NULL) - { - m_err("cannot free rx buffer\n"); - } - else - { - priv->spidev.rxbuffinfo.free_buff = rxbuff; - } -} - -/**************************************************************************** - * Name: create_rxbufffifo - * - * Description: - * Create receiving FIFO. This fifo is used when copying to the buffer - * specified by the user. - * - ****************************************************************************/ - -static void create_rxbufffifo(FAR struct altmdm_dev_s *priv) -{ - FAR struct altmdm_spi_rxbufffifo_s *fifo = &priv->spidev.rxbuffinfo.fifo; - - init_rxbuffer(priv, &priv->spidev.rxbuffinfo.free_buff, MAX_PKT_SIZE); - - fifo->head = NULL; - fifo->tail = NULL; - - altmdm_sys_initcsem(&fifo->csem); -} - -/**************************************************************************** - * Name: destroy_rxbufffifo - * - * Description: - * Destroy receiving FIFO. - * - ****************************************************************************/ - -static void destroy_rxbufffifo(FAR struct altmdm_dev_s *priv) -{ - FAR struct altmdm_spi_rxbufffifo_s *fifo = &priv->spidev.rxbuffinfo.fifo; - - uninit_rxbuffer(priv, priv->spidev.rxbuffinfo.free_buff); - - altmdm_sys_deletecsem(&fifo->csem); -} - -/**************************************************************************** - * Name: put_rxbufffifo - * - * Description: - * Put date into the receiving FIFO. - * - ****************************************************************************/ - -static void put_rxbufffifo(FAR struct altmdm_dev_s *priv, - FAR struct altmdm_spi_rxbuff_s *rxbuff) -{ - FAR struct altmdm_spi_rxbufffifo_s *fifo = &priv->spidev.rxbuffinfo.fifo; - irqstate_t flags; - - flags = enter_critical_section(); - - if (fifo->head == NULL) - { - fifo->head = rxbuff; - fifo->tail = rxbuff; - rxbuff->next = NULL; - } - else - { - fifo->tail->next = rxbuff; - fifo->tail = rxbuff; - rxbuff->next = NULL; - } - - leave_critical_section(flags); - - altmdm_sys_postcsem(&fifo->csem); -} - -/**************************************************************************** - * Name: get_rxbufffifo - * - * Description: - * Get date from the receiving FIFO. If the FIFO is empty, - * it is kept waiting until data is put in the FIFO. - * - ****************************************************************************/ - -static void get_rxbufffifo(FAR struct altmdm_dev_s *priv, - FAR struct altmdm_spi_rxbuff_s **rxbuff) -{ - FAR struct altmdm_spi_rxbufffifo_s *fifo = &priv->spidev.rxbuffinfo.fifo; - irqstate_t flags; - - *rxbuff = NULL; - - altmdm_sys_waitcsem(&fifo->csem); - - flags = enter_critical_section(); - - if (fifo->head != NULL) - { - *rxbuff = fifo->head; - fifo->head = fifo->head->next; - } - - leave_critical_section(flags); -} - -/**************************************************************************** - * Name: abort_get_rxbufffifo - * - * Description: - * If waiting for data to be put in the FIFO, then abort it. - * - ****************************************************************************/ - -static void abort_get_rxbufffifo(FAR struct altmdm_dev_s *priv) -{ - int val; - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - FAR struct altmdm_spi_rxbufffifo_s *fifo = &priv->spidev.rxbuffinfo.fifo; - - if (!altmdm_sys_getcsemvalue(&fifo->csem, &val)) - { - if (val < 0) - { - spidev->rx_param.rxabort = true; - altmdm_sys_postcsem(&fifo->csem); - } - } -} - -/**************************************************************************** - * Name: clear_txheader - * - * Description: - * Clear the header for transmission. - * - ****************************************************************************/ - -static void clear_txheader(FAR struct altmdm_dev_s *priv) -{ - memset(&priv->spidev.tx_param.header, 0x00, - sizeof(struct altmdm_spi_xferhdr_s)); -} - -/**************************************************************************** - * Name: clear_rxheader - * - * Description: - * Clear the header for reception. - * - ****************************************************************************/ - -static void clear_rxheader(FAR struct altmdm_dev_s *priv) -{ - memset(&priv->spidev.rx_param.header, 0x00, - sizeof(struct altmdm_spi_xferhdr_s)); -} - -/**************************************************************************** - * Name: set_txheader_datasize - * - * Description: - * Set transmission data size in the header. - * - ****************************************************************************/ - -static void set_txheader_datasize(FAR struct altmdm_dev_s *priv, - int total_size, int actual_size) -{ - FAR struct altmdm_spi_xferhdr_s *tx_header = &priv->spidev.tx_param.header; - - tx_header->header[0] = - (tx_header->header[0] & 0xf0) + ((total_size >> 10) & 0x0000000f); - tx_header->header[1] = (total_size >> 2) & 0x000000ff; - tx_header->header[2] = - ((total_size & 0x00000003) << 6) + ((actual_size >> 8) & 0x0000003f); - tx_header->header[3] = (actual_size & 0x000000ff); -} - -/**************************************************************************** - * Name: set_txheader_possibleofrx - * - * Description: - * Set flag in the header. The flag indicates that master can receive data. - * - ****************************************************************************/ - -static void set_txheader_possibleofrx(FAR struct altmdm_dev_s *priv, - bool possible) -{ - FAR struct altmdm_spi_xferhdr_s *tx_header = &priv->spidev.tx_param.header; - - if (!possible) - { - tx_header->header[0] = 0x80 + (tx_header->header[0] & 0x7f); - } - else - { - tx_header->header[0] = 0x00 + (tx_header->header[0] & 0x7f); - } -} - -/**************************************************************************** - * Name: set_txheader_sleepreq - * - * Description: - * Set flag in the header. The flag indicates that sleep request. - * - ****************************************************************************/ - -static void set_txheader_sleepreq(FAR struct altmdm_dev_s *priv) -{ - FAR struct altmdm_spi_xferhdr_s *tx_header = &priv->spidev.tx_param.header; - - tx_header->header[0] = 0x10 + (tx_header->header[0] & 0xef); -} - -/**************************************************************************** - * Name: show_txheader - * - * Description: - * Show header for transmission. - * - ****************************************************************************/ - -static void show_txheader(FAR struct altmdm_dev_s *priv) -{ -#ifdef MODEM_ALTMDM_DEBUG - FAR struct altmdm_spi_xferhdr_s *tx_header = &priv->spidev.tx_param.header; - - m_info("[TXHDR]=%02x,%02x,%02x,%02x\n", - tx_header->header[0], tx_header->header[1], - tx_header->header[2], tx_header->header[3]); -#endif -} - -/**************************************************************************** - * Name: parse_rxheader - * - * Description: - * Parse header for receiving. - * - ****************************************************************************/ - -static void parse_rxheader(FAR struct altmdm_dev_s *priv, - FAR int32_t *total_size, FAR int32_t *actual_size, - FAR int *is_reset, FAR int32_t *is_bufful) -{ - FAR struct altmdm_spi_xferhdr_s *rx_header = &priv->spidev.rx_param.header; - - m_info("[RXHDR]%02x,%02x,%02x,%02x\n", - rx_header->header[0], rx_header->header[1], - rx_header->header[2], rx_header->header[3]); - - *total_size = ((rx_header->header[0] & 0x0f) << 10) + - ((rx_header->header[1] & 0xff) << 2) + (rx_header->header[2] >> 6); - *actual_size = ((rx_header->header[2] & 0x3f) << 8) + - (rx_header->header[3] & 0xff); - - priv->spidev.rx_param.status_info = (rx_header->header[0] & 0xf0) >> 4; - - *is_reset = STAT_INF_IS_RESET(priv->spidev.rx_param.status_info); - *is_bufful = STAT_INF_IS_BUFF_FULL(priv->spidev.rx_param.status_info); - - m_info("t=%d a=%d r=%d b=%d\n", - *total_size, *actual_size, *is_reset, *is_bufful); - - return; -} - -/**************************************************************************** - * Name: verify_rxheader - * - * Description: - * Verify header for receiving. - * - ****************************************************************************/ - -static int verify_rxheader(FAR struct altmdm_dev_s *priv, - int total_size, int actual_size) -{ - int calc_total_size; - - if ((total_size == 0) || (actual_size == 0)) - { - return -1; - } - - if ((total_size > MAX_PKT_SIZE) || (actual_size > MAX_PKT_SIZE)) - { - return -1; - } - - if (total_size % UNIT_SIZE) - { - return -1; - } - - if (total_size != actual_size) - { - calc_total_size = ((actual_size / UNIT_SIZE) + 1) * UNIT_SIZE; - - if (total_size != calc_total_size) - { - return -1; - } - } - - return 0; -} - -/**************************************************************************** - * Name: do_xferheader - * - * Description: - * Execute header transfer. - * - ****************************************************************************/ - -static int do_xferheader(FAR struct altmdm_dev_s *priv, - uint32_t is_rxreq, uint32_t is_txreq, - uint32_t is_sleepreq, uint32_t is_rcvrready) -{ - int ret; - int dma_xfer_size; - struct altmdm_spi_dev_s *spidev = &priv->spidev; - bool possibleofrx = true; - - /* Make transfer header */ - - clear_txheader(priv); - - if ((is_sleepreq) || (is_txreq)) - { - DEBUGASSERT(priv->lower); - priv->lower->master_request(true); - - if (is_sleepreq) - { - set_txheader_sleepreq(priv); - } - else - { - set_txheader_datasize(priv, spidev->tx_param.total_size, - spidev->tx_param.actual_size); - } - } - - if (!is_sleepreq) - { - alloc_rxbuffer(priv, &spidev->rx_param.rxbuff, MAX_PKT_SIZE); - if (spidev->rx_param.rxbuff == NULL) - { - possibleofrx = false; - } - - set_txheader_possibleofrx(priv, possibleofrx); - } - - show_txheader(priv); - - /* Wait for Receiver Ready to receive. */ - - if ((!is_rxreq) && (!is_rcvrready)) - { - ret = wait_receiverready(priv, WAIT_RXREQ_HEADER_TIMEOUT); - if (ret < 0) - { - goto trans_header_error; - } - } - - /* Get DMA transfer size */ - - dma_xfer_size = get_dmasize(priv, sizeof(struct altmdm_spi_xferhdr_s)); - - ret = do_dmaxfer(priv, (FAR void *)&spidev->tx_param.header, - (FAR void *)&spidev->rx_param.header, dma_xfer_size); - if (ret < 0) - { - goto trans_header_error; - } - - return ret; - -trans_header_error: - m_err("ERR:%04d Transfer Header Failed. ret = %d.\n", __LINE__, ret); - - /* Clear Header */ - - clear_rxheader(priv); - set_txheader_datasize(priv, 0, 0); - - return ret; -} - -/**************************************************************************** - * Name: do_receivedata - * - * Description: - * Executes the receive only transfer mode. - * - ****************************************************************************/ - -static int do_receivedata(FAR struct altmdm_dev_s *priv) -{ - int ret; - int dma_xfer_size; - FAR void *rxbuff; - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - /* Wait for Receiver Ready to receive. */ - - ret = wait_receiverready(priv, WAIT_RXREQ_TIMEOUT); - if (ret >= 0) - { - /* Get DMA transfer size */ - - dma_xfer_size = get_dmasize(priv, spidev->rx_param.total_size); - - rxbuff = spidev->rx_param.rxbuff->buff_addr; - - /* Do DMA transfer */ - - ret = do_dmaxfer(priv, NULL, rxbuff, dma_xfer_size); - } - - if (ret < 0) - { - m_err("Rcv Data Failed. ret = %d.\n", ret); - clear_rxheader(priv); - } - - return ret; -} - -/**************************************************************************** - * Name: do_senddata - * - * Description: - * Executes the transmission only transfer mode. - * - ****************************************************************************/ - -static int do_senddata(FAR struct altmdm_dev_s *priv) -{ - int ret; - int dma_xfer_size; - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - /* Wait for Receiver Ready to receive. */ - - ret = wait_receiverready(priv, WAIT_RXREQ_TIMEOUT); - if (ret >= 0) - { - /* Get DMA transfer size */ - - dma_xfer_size = get_dmasize(priv, spidev->tx_param.total_size); - - /* Do DMA transfer */ - - ret = do_dmaxfer(priv, (FAR void *)spidev->tx_param.buff_addr, - NULL, dma_xfer_size); - } - - if (ret < 0) - { - m_err("ERR:%04d Snd Data Failed. ret = %d.\n", __LINE__, ret); - clear_txheader(priv); - } - - return ret; -} - -/**************************************************************************** - * Name: do_trxdata - * - * Description: - * Executes the transmission and receive transfer mode. - * - ****************************************************************************/ - -static int do_trxdata(FAR struct altmdm_dev_s *priv) -{ - int ret; - int xfer_size; - int dma_xfer_size; - FAR void *rxbuff; - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - /* Wait for Receiver Ready to receive. */ - - ret = wait_receiverready(priv, WAIT_RXREQ_TIMEOUT); - if (ret >= 0) - { - /* Choose the larger one. */ - - if (spidev->tx_param.total_size < spidev->rx_param.total_size) - { - xfer_size = spidev->rx_param.total_size; - } - else - { - xfer_size = spidev->tx_param.total_size; - } - - rxbuff = spidev->rx_param.rxbuff->buff_addr; - - /* Get DMA transfer size */ - - dma_xfer_size = get_dmasize(priv, xfer_size); - - /* Do DMA transfer */ - - ret = do_dmaxfer(priv, (FAR void *)spidev->tx_param.buff_addr, rxbuff, - dma_xfer_size); - } - - if (ret < 0) - { - m_err("ERR:%04d Trx Data Failed. ret = %d.\n", __LINE__, ret); - clear_txheader(priv); - clear_rxheader(priv); - } - - return ret; -} - -/**************************************************************************** - * Name: do_receivedata_nobuff - * - * Description: - * Executes the receive only transfer mode. When receiving buffer cannot - * be prepared. - * - ****************************************************************************/ - -static int do_receivedata_nobuff(FAR struct altmdm_dev_s *priv) -{ - int ret; - int dma_xfer_size; - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - /* Wait for Receiver Ready to receive. */ - - ret = wait_receiverready(priv, WAIT_RXREQ_TIMEOUT); - if (ret >= 0) - { - /* Get DMA transfer size */ - - dma_xfer_size = get_dmasize(priv, spidev->rx_param.total_size); - - /* Do DMA transfer */ - - ret = do_dmaxfer(priv, NULL, NULL, dma_xfer_size); - } - - if (ret < 0) - { - m_err("ERR:%04d Rcv Data Nobuff Failed. ret = %d.\n", __LINE__, ret); - clear_rxheader(priv); - } - else - { - ret = TRANS_OK_RXDATANOBUFF; - } - - return ret; -} - -/**************************************************************************** - * Name: do_trxdata_norxbuff - * - * Description: - * Executes the transmission and receive transfer mode. When receiving - * buffer cannot be prepared. - * - ****************************************************************************/ - -static int do_trxdata_norxbuff(FAR struct altmdm_dev_s *priv) -{ - int ret; - int xfer_size; - int dma_xfer_size; - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - /* Wait for Receiver Ready to receive. */ - - ret = wait_receiverready(priv, WAIT_RXREQ_TIMEOUT); - if (ret >= 0) - { - /* Choose the larger one. */ - - if (spidev->tx_param.total_size < spidev->rx_param.total_size) - { - xfer_size = spidev->rx_param.total_size; - } - else - { - xfer_size = spidev->tx_param.total_size; - } - - /* Get DMA transfer size */ - - dma_xfer_size = get_dmasize(priv, xfer_size); - - /* Do DMA transfer */ - - ret = do_dmaxfer(priv, (FAR void *)spidev->tx_param.buff_addr, - NULL, dma_xfer_size); - } - - if (ret < 0) - { - m_err("ERR:%04d Trx Data Norxbuff Failed. ret = %d.\n", __LINE__, ret); - clear_txheader(priv); - clear_rxheader(priv); - } - else - { - ret = TRANS_OK_TRXDATANORXBUFF; - } - - return ret; -} - -/**************************************************************************** - * Name: do_receivesleepdata - * - * Description: - * Executes the sleep data transfer mode. - * - ****************************************************************************/ - -static int do_receivesleepdata(FAR struct altmdm_dev_s *priv, FAR int *resp) -{ - int ret; - int dma_xfer_size; - char rxbuff[UNIT_SIZE]; - - /* Wait for Receiver Ready to receive. */ - - ret = wait_receiverready(priv, WAIT_RXREQ_TIMEOUT); - if (ret >= 0) - { - /* Get DMA transfer size */ - - dma_xfer_size = get_dmasize(priv, UNIT_SIZE); - - /* Do DMA transfer */ - - ret = do_dmaxfer(priv, NULL, (FAR void *)rxbuff, dma_xfer_size); - } - - if (ret < 0) - { - m_err("ERR:%04d Rcv Sleep Resp Data Failed. ret = %d.\n", - __LINE__, ret); - } - else - { - m_info("[SRESP] 0x%02x,0x%02x,0x%02x,0x%02x\n", - rxbuff[0], rxbuff[1], - rxbuff[2], rxbuff[3]); - - if (!memcmp(rxbuff, "OK", 2)) - { - *resp = SLEEP_OK; - } - else - { - *resp = SLEEP_NG; - } - } - - return ret; -} - -/**************************************************************************** - * Name: do_receivereset - * - * Description: - * Executes the reset packet receive only transfer mode. - * - ****************************************************************************/ - -static int do_receivereset(FAR struct altmdm_dev_s *priv) -{ - int ret; - int dma_xfer_size; - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - char rxbuff[UNIT_SIZE]; - - /* Wait for Receiver Ready to receive. */ - - ret = wait_receiverready(priv, WAIT_RXREQ_TIMEOUT); - if (ret >= 0) - { - /* Get DMA transfer size */ - - dma_xfer_size = get_dmasize(priv, spidev->rx_param.total_size); - - /* Do DMA transfer */ - - ret = do_dmaxfer(priv, NULL, (FAR void *)rxbuff, dma_xfer_size); - } - - if (ret < 0) - { - m_err("ERR:%04d Rcv Reset Failed. ret = %d.\n", __LINE__, ret); - clear_rxheader(priv); - } - else - { - if ((STAT_INF_GET_BOOTSTAT | STAT_INF_RESET) == - (spidev->rx_param. - status_info & (STAT_INF_GET_BOOTSTAT | STAT_INF_RESET))) - { - switch (rxbuff[0]) - { - case RESET_BOOTSTAT_BOOTING: - altmdm_pm_set_bootstatus(priv, - MODEM_PM_ERR_RESET_BOOTSTAT_BOOTING); - break; - - case RESET_BOOTSTAT_UPDATING: - altmdm_pm_set_bootstatus(priv, - MODEM_PM_ERR_RESET_BOOTSTAT_UPDATING); - break; - - default: - m_err - ("ERR:%04d Invalid payload of reset packet. " \ - "%02x,%02x,%02x,%02x\n", - __LINE__, rxbuff[0], rxbuff[1], rxbuff[2], rxbuff[3]); - break; - } - } - else if (STAT_INF_RESET == - (spidev->rx_param.status_info & STAT_INF_RESET)) - { - altmdm_pm_set_bootstatus(priv, MODEM_PM_ERR_RESET_BOOTSTAT_DONE); - } - else - { - m_err("ERR:%04d Unexpected status info. %04x\n", __LINE__, - spidev->rx_param.status_info); - } - } - - return ret; -} - -/**************************************************************************** - * Name: do_trxreset - * - * Description: - * Executes the transmission and receive reset packet transfer mode. - * - ****************************************************************************/ - -static int do_trxreset(FAR struct altmdm_dev_s *priv) -{ - int ret; - int xfer_size; - int dma_xfer_size; - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - /* Wait for Receiver Ready to receive. */ - - ret = wait_receiverready(priv, WAIT_RXREQ_TIMEOUT); - if (ret >= 0) - { - /* Even in the case of a conflict between a reset packet - * and a send packet, the send size is compared and the - * larger size is sent as the payload. - * If the send packet that conflicts with the reset packet - * is in ALTCOM command format, the modem may assert. - * If it is not in the ALTCOM command format, it will be - * discarded by the modem, so dummy data will be sent to - * avoid assertion. - */ - - if (spidev->tx_param.total_size < spidev->rx_param.total_size) - { - xfer_size = spidev->rx_param.total_size; - } - else - { - xfer_size = spidev->tx_param.total_size; - } - - /* Get DMA transfer size */ - - dma_xfer_size = get_dmasize(priv, xfer_size); - - /* Do DMA transfer */ - - ret = do_dmaxfer(priv, NULL, NULL, dma_xfer_size); - } - - if (ret < 0) - { - m_err("ERR:%04d Trx Reset Failed. ret = %d.\n", __LINE__, ret); - clear_txheader(priv); - clear_rxheader(priv); - } - - return ret; -} - -/**************************************************************************** - * Name: do_xfersleep - * - * Description: - * Executes the sleep request. - * - ****************************************************************************/ - -static int do_xfersleep(FAR struct altmdm_dev_s *priv, uint32_t is_rcvrready) -{ - int ret; - int resp = 0; - int is_reset = 0; - int32_t total_size; - int32_t actual_size; - int32_t is_bufful; - - /* Transfer header for sleep request */ - - ret = do_xferheader(priv, 0, 0, 1, is_rcvrready); - if (ret >= 0) - { - parse_rxheader(priv, &total_size, &actual_size, &is_reset, &is_bufful); - - /* Transfer data for sleep request */ - - ret = do_receivesleepdata(priv, &resp); - if (ret >= 0) - { - ret = resp; - } - } - - if (ret < 0) - { - ret = SLEEP_NG; - } - - DEBUGASSERT(priv && priv->lower); - priv->lower->master_request(false); - - if (is_reset) - { - if (!priv->spidev.is_xferready) - { - priv->spidev.is_xferready = true; - m_info("ready to xfer\n"); - notify_xferready(priv); - } - - altmdm_pm_notify_reset(priv); - } - - return ret; -} - -/**************************************************************************** - * Name: decide_xfermode - * - * Description: - * Decide transfer mode. - * - ****************************************************************************/ - -static uint32_t decide_xfermode(FAR struct altmdm_dev_s *priv, - uint32_t is_rxreq, uint32_t is_txreq, - int ret) -{ - int retval; - int is_reset; - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - uint32_t mode = MODE_RXINVALID; - - if (ret < 0) - { - if (is_txreq) - { - mode = MODE_TRXHEADERFAILTXREQ; - } - else - { - mode = MODE_TRXHEADERFAILRXREQ; - } - - if (spidev->rx_param.rxbuff != NULL) - { - free_rxbuffer(priv, spidev->rx_param.rxbuff); - spidev->rx_param.rxbuff = NULL; - } - } - else - { - parse_rxheader(priv, &spidev->rx_param.total_size, - &spidev->rx_param.actual_size, &is_reset, - &spidev->tx_param.is_bufful); - - if (is_rxreq) - { - retval = verify_rxheader(priv, spidev->rx_param.total_size, - spidev->rx_param.actual_size); - if (retval != 0) - { - m_info("RX header:total=0x%02x, actual=0x%02x.\n", - spidev->rx_param.total_size, - spidev->rx_param.actual_size); - - if (spidev->rx_param.rxbuff != NULL) - { - free_rxbuffer(priv, spidev->rx_param.rxbuff); - spidev->rx_param.rxbuff = NULL; - } - - if (!is_txreq) - { - return mode; - } - - is_rxreq = 0; - - m_info("RX Header invalid. But Send will be done.\n"); - } - } - else if ((spidev->rx_param.actual_size != 0) || - (spidev->rx_param.total_size != 0)) - { - retval = verify_rxheader(priv, spidev->rx_param.total_size, - spidev->rx_param.actual_size); - if (retval == 0) - { - is_rxreq = 1; - } - } - - /* Diceide transfer mode here. */ - - if (is_txreq) - { - if (is_rxreq) - { - if (is_reset) - { - if (spidev->rx_param.rxbuff != NULL) - { - free_rxbuffer(priv, spidev->rx_param.rxbuff); - spidev->rx_param.rxbuff = NULL; - } - - mode = MODE_TRXRESET; - } - else - { - if (spidev->rx_param.rxbuff == NULL) - { - mode = MODE_TRXDATANOBUFF; - } - else - { - mode = MODE_TRXDATA; - spidev->rx_param.rxbuff->rx_size = - spidev->rx_param.actual_size; - m_info("received size = %d.\n", - spidev->rx_param.rxbuff->rx_size); - } - } - } - else - { - if (spidev->rx_param.rxbuff != NULL) - { - free_rxbuffer(priv, spidev->rx_param.rxbuff); - spidev->rx_param.rxbuff = NULL; - } - - mode = MODE_TXDATA; - } - } - else - { - if (is_reset) - { - if (spidev->rx_param.rxbuff != NULL) - { - free_rxbuffer(priv, spidev->rx_param.rxbuff); - spidev->rx_param.rxbuff = NULL; - } - - mode = MODE_RXRESET; - } - else - { - if (spidev->rx_param.rxbuff == NULL) - { - mode = MODE_RXDATANOBUFF; - } - else - { - mode = MODE_RXDATA; - spidev->rx_param.rxbuff->rx_size = - spidev->rx_param.actual_size; - m_info("received size = %d.\n", - spidev->rx_param.rxbuff->rx_size); - } - } - } - } - - clear_rxheader(priv); - clear_txheader(priv); - - return mode; -} - -/**************************************************************************** - * Name: done_xfer - * - * Description: - * Notify that transfer has completed. - * - ****************************************************************************/ - -static void done_xfer(FAR struct altmdm_dev_s *priv, uint32_t xfer_mode, - int ret) -{ - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - switch (xfer_mode) - { - case MODE_RXDATA: - if (ret < 0) - { - free_rxbuffer(priv, spidev->rx_param.rxbuff); - spidev->rx_param.rxbuff = NULL; - } - else - { - put_rxbufffifo(priv, spidev->rx_param.rxbuff); - spidev->rx_param.rxbuff = NULL; - } - break; - - case MODE_TXDATA: - if (spidev->tx_param.is_bufful) - { - spidev->tx_param.is_bufful = 0; - spidev->tx_param.result = (ret < 0) ? ret : TRANS_OK_RCVBUFFUL; - } - else - { - spidev->tx_param.result = (ret < 0) ? ret : TRANS_OK; - } - - altmdm_sys_setflag(&spidev->tx_param.done_flag, EVENT_TX_DONE); - break; - - case MODE_TRXDATA: - if (spidev->tx_param.is_bufful) - { - spidev->tx_param.is_bufful = 0; - spidev->tx_param.result = (ret < 0) ? ret : TRANS_OK_RCVBUFFUL; - } - else - { - spidev->tx_param.result = (ret < 0) ? ret : TRANS_OK; - } - - altmdm_sys_setflag(&spidev->tx_param.done_flag, EVENT_TX_DONE); - - if (ret < 0) - { - free_rxbuffer(priv, spidev->rx_param.rxbuff); - spidev->rx_param.rxbuff = NULL; - } - else - { - put_rxbufffifo(priv, spidev->rx_param.rxbuff); - spidev->rx_param.rxbuff = NULL; - } - break; - - case MODE_TRXDATANOBUFF: - if (spidev->tx_param.is_bufful) - { - spidev->tx_param.is_bufful = 0; - spidev->tx_param.result = (ret < 0) ? ret : TRANS_OK_RCVBUFFUL; - } - else - { - spidev->tx_param.result = (ret < 0) ? ret : TRANS_OK; - } - - altmdm_sys_setflag(&spidev->tx_param.done_flag, EVENT_TX_DONE); - - /* Yield the CPU so that the upper layer can execute - * the receiving process. - */ - - nxsig_usleep(YIELD_TASK_NOBUFF); - - break; - - case MODE_TRXHEADERFAILTXREQ: - spidev->tx_param.result = ret; - altmdm_sys_setflag(&spidev->tx_param.done_flag, EVENT_TX_DONE); - break; - - case MODE_RXRESET: - if (!spidev->is_xferready) - { - spidev->is_xferready = true; - m_info("ready to xfer\n"); - notify_xferready(priv); - } - - altmdm_pm_notify_reset(priv); - break; - - case MODE_TRXRESET: - if (!spidev->is_xferready) - { - spidev->is_xferready = true; - m_info("ready to xfer\n"); - notify_xferready(priv); - } - - altmdm_pm_notify_reset(priv); - if (spidev->tx_param.is_bufful) - { - spidev->tx_param.is_bufful = 0; - spidev->tx_param.result = (ret < 0) ? ret : TRANS_OK_RCVBUFFUL; - } - else - { - spidev->tx_param.result = (ret < 0) ? ret : TRANS_OK; - } - - altmdm_sys_setflag(&spidev->tx_param.done_flag, EVENT_TX_DONE); - break; - - case MODE_RXDATANOBUFF: - - /* Yield the CPU so that the upper layer can execute - * the receiving process. - */ - - nxsig_usleep(YIELD_TASK_NOBUFF); - break; - - case MODE_TRXHEADERFAILRXREQ: - case MODE_RXINVALID: - break; - - default: - break; - } -} - -/**************************************************************************** - * Name: done_sleep - * - * Description: - * Notify that sleep request has completed. - * - ****************************************************************************/ - -static void done_sleep(FAR struct altmdm_dev_s *priv, int ret) -{ - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - spidev->sleep_param.result = ret; - altmdm_sys_setflag(&spidev->sleep_param.done_flag, EVENT_SLEEP_DONE); -} - -/**************************************************************************** - * Name: xfer_task_init - * - * Description: - * Initialize SPI transfer task. - * - ****************************************************************************/ - -static void xfer_task_init(FAR struct altmdm_dev_s *priv) -{ - sigset_t mask; - - sigfillset(&mask); - nxsig_procmask(SIG_SETMASK, &mask, NULL); - - init_svtimer(priv); -} - -/**************************************************************************** - * Name: xfer_task - * - * Description: - * ALTMDM SPI transfer task. - * - ****************************************************************************/ - -static int xfer_task(int argc, char *argv[]) -{ - int ret; - int sleep_result; - int res_code; - uint32_t is_txreq; - uint32_t is_rxreq; - uint32_t is_sleepreq; - uint32_t is_timerexp; - uint32_t do_sleep; - uint32_t ptn; - uint32_t xfer_mode; - uint32_t modem_state; - uint32_t is_rcvrready = 0; - FAR struct altmdm_dev_s *priv = g_privdata; - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - xfer_task_init(priv); - - while (!spidev->is_not_run) - { - ret = altmdm_sys_waitflag(&spidev->xfer_flag, EVENT_TRANS_WAIT, - ALTMDM_SYS_FLAG_WMODEOR, &ptn, - ALTMDM_SYS_FLAG_TMOFEVR); - if (ret != 0) - { - m_err("wait flag failed:%d.\n", ret); - continue; - } - - m_info("ptn:%x.\n", ptn); - - if (ptn & EVENT_REQMASK) - { - is_txreq = ptn & EVENT_TXREQ; - is_rxreq = ptn & EVENT_RXREQ; - is_sleepreq = ptn & EVENT_SLEEPREQ; - is_timerexp = ptn & EVENT_SV_TIMER_EXP; - do_sleep = 0; - sleep_result = SLEEP_NG; - - /* Sleep transition event received. Check if it can sleep. */ - - if (is_sleepreq || is_timerexp) - { - /* If data transfer required at the same time, cannot sleep. */ - - if (!(is_txreq || is_rxreq)) - { - if (altmdm_pm_cansleep(priv)) - { - do_sleep = 1; - } - else if (is_timerexp) - { - /* Case where modem spontaneously enters sleep state - * and timer is not stopped. - */ - - modem_state = altmdm_pm_getinternalstate(); - if (modem_state == MODEM_PM_INTERNAL_STATE_SLEEP) - { - stop_svtimer(priv); - } - } - } - } - - if (do_sleep) - { - stop_svtimer(priv); - - /* Transfer sleep packet */ - - sleep_result = do_xfersleep(priv, 0); - if (sleep_result == SLEEP_OK) - { - altmdm_pm_sleepmodem(priv); - } - } - - if (is_sleepreq) - { - /* Send sleep response */ - - done_sleep(priv, sleep_result); - } - - /* Receive data transfer request */ - - if (is_txreq || is_rxreq) - { - stop_svtimer(priv); - - /* Wakeup modem before data transfer */ - - if (is_rxreq) - { - res_code = altmdm_pm_wakeup(priv, NULL); - } - else - { - res_code = altmdm_pm_wakeup(priv, wait_receiverready); - } - - if (res_code == MODEM_PM_WAKEUP_FAIL) - { - done_xfer(priv, MODE_TXDATA, TRANS_WAITRCVRTMO); - start_svtimer(priv); - continue; - } - else if (res_code == MODEM_PM_WAKEUP_DONE) - { - is_rcvrready = 1; - } - - /* transfer header */ - - ret = do_xferheader(priv, is_rxreq, is_txreq, 0, is_rcvrready); - - if (is_rcvrready) - { - is_rcvrready = 0; - } - - xfer_mode = decide_xfermode(priv, is_rxreq, is_txreq, ret); - - switch (xfer_mode) - { - case MODE_RXDATA: - ret = do_receivedata(priv); - break; - - case MODE_TXDATA: - ret = do_senddata(priv); - break; - - case MODE_TRXDATA: - ret = do_trxdata(priv); - break; - - case MODE_RXDATANOBUFF: - ret = do_receivedata_nobuff(priv); - break; - - case MODE_TRXDATANOBUFF: - ret = do_trxdata_norxbuff(priv); - break; - - case MODE_RXRESET: - ret = do_receivereset(priv); - break; - - case MODE_TRXRESET: - ret = do_trxreset(priv); - break; - - case MODE_RXINVALID: - ret = TRANS_RXINVALID; - break; - - case MODE_TRXHEADERFAILTXREQ: - case MODE_TRXHEADERFAILRXREQ: - break; - - default: - m_err("ERR:%04d Unknown decision of transfer: %d.\n", - __LINE__, xfer_mode); - break; - } - - if (is_txreq) - { - DEBUGASSERT(priv->lower); - priv->lower->master_request(false); - } - - m_info("m=%d\n", xfer_mode); - done_xfer(priv, xfer_mode, ret); - start_svtimer(priv); - } - } - - if (ptn & EVENT_EXIT) - { - spidev->is_not_run = true; - } - } - - delete_svtimer(priv); - task_delete(0); - - return 0; -} - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: altmdm_spi_gpioreadyisr - * - * Description: - * Interrupt handler for SLAVE_REQUEST GPIO line. - * - ****************************************************************************/ - -int altmdm_spi_gpioreadyisr(int irq, FAR void *context, FAR void *arg) -{ - FAR struct altmdm_dev_s *priv = g_privdata; - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - altmdm_sys_setflag(&spidev->xfer_flag, EVENT_RXREQ); - - return 0; -} - -/**************************************************************************** - * Name: altmdm_spi_init - * - * Description: - * Initialize ALTMDM driver. - * - ****************************************************************************/ - -int altmdm_spi_init(FAR struct altmdm_dev_s *priv) -{ - int ret = 0; - - g_privdata = priv; - - /* Initialize modem power management driver */ - - altmdm_pm_init(priv); - - memset(&priv->spidev, 0, sizeof(struct altmdm_spi_dev_s)); - priv->spidev.is_not_run = false; - priv->spidev.is_xferready = false; - - altmdm_sys_initlock(&priv->spidev.tx_param.lock); - altmdm_sys_initlock(&priv->spidev.rx_param.lock); - altmdm_sys_initlock(&priv->spidev.sleep_param.lock); - - altmdm_sys_initflag(&priv->spidev.xfer_flag); - altmdm_sys_initflag(&priv->spidev.xferready_flag); - altmdm_sys_initflag(&priv->spidev.tx_param.done_flag); - altmdm_sys_initflag(&priv->spidev.sleep_param.done_flag); - - create_rxbufffifo(priv); - - DEBUGASSERT(priv->lower); - - /* SPI settings */ - - SPI_LOCK(priv->spi, true); - SPI_SETMODE(priv->spi, SPIDEV_MODE0); - SPI_SETBITS(priv->spi, 8); - SPI_SETFREQUENCY(priv->spi, priv->lower->spi_maxfreq()); - SPI_LOCK(priv->spi, false); - - priv->lower->sready_irqattach(true, altmdm_spi_gpioreadyisr); - - priv->spidev.task_id = task_create(XFER_TASK_NAME, XFER_TASK_PRI, - XFER_TASK_STKSIZE, xfer_task, NULL); - if (priv->spidev.task_id == ERROR) - { - m_err("Failed to create xfer task\n"); - } - - return ret; -} - -/**************************************************************************** - * Name: altmdm_spi_uninit - * - * Description: - * Uninitialize ALTMDM driver. - * - ****************************************************************************/ - -int altmdm_spi_uninit(FAR struct altmdm_dev_s *priv) -{ - altmdm_sys_setflag(&priv->spidev.xfer_flag, EVENT_EXIT); - - /* check transfer task is deleted or not */ - - while (1) - { - if (priv->spidev.is_not_run) - { - break; - } - - nxsig_usleep(10); - } - - altmdm_sys_deletelock(&priv->spidev.tx_param.lock); - altmdm_sys_deletelock(&priv->spidev.rx_param.lock); - altmdm_sys_deletelock(&priv->spidev.sleep_param.lock); - - altmdm_sys_deleteflag(&priv->spidev.xfer_flag); - altmdm_sys_deleteflag(&priv->spidev.tx_param.done_flag); - altmdm_sys_deleteflag(&priv->spidev.sleep_param.done_flag); - - if (priv->spidev.rx_param.rxbuff != NULL) - { - free_rxbuffer(priv, priv->spidev.rx_param.rxbuff); - priv->spidev.rx_param.rxbuff = NULL; - } - - destroy_rxbufffifo(priv); - - DEBUGASSERT(priv->lower); - priv->lower->sready_irqattach(false, NULL); - - /* Uninitialize modem power management driver */ - - altmdm_pm_uninit(priv); - - return 0; -} - -/**************************************************************************** - * Name: altmdm_spi_enable - * - * Description: - * Enable ALTMDM SPI driver. - * - ****************************************************************************/ - -int altmdm_spi_enable(FAR struct altmdm_dev_s *priv) -{ - DEBUGASSERT(priv && priv->lower); - priv->lower->sready_irqenable(true); - - return 0; -} - -/**************************************************************************** - * Name: altmdm_spi_disable - * - * Description: - * Disable ALTMDM SPI driver. - * - ****************************************************************************/ - -int altmdm_spi_disable(FAR struct altmdm_dev_s *priv) -{ - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - DEBUGASSERT(priv->lower); - priv->lower->sready_irqenable(false); - - spidev->is_xferready = false; - - return 0; -} - -/**************************************************************************** - * Name: altmdm_spi_read - * - * Description: - * ALTMDM SPI driver read method. - * - ****************************************************************************/ - -ssize_t altmdm_spi_read(FAR struct altmdm_dev_s * priv, - FAR const char *buffer, size_t readlen) -{ - FAR struct altmdm_spi_dev_s *spidev; - FAR struct altmdm_spi_rxbuff_s *rbuff; - ssize_t rsize = readlen; - - /* Check argument */ - - if ((priv == NULL) || (buffer == NULL)) - { - return -EINVAL; - } - - if (!readlen || readlen > MAX_PKT_SIZE) - { - m_err("Invalid read length:%d.\n", readlen); - return -EINVAL; - } - - spidev = &priv->spidev; - - altmdm_sys_lock(&spidev->rx_param.lock); - - get_rxbufffifo(priv, &rbuff); - if (spidev->rx_param.rxabort) - { - spidev->rx_param.rxabort = false; - if (rbuff != NULL) - { - m_info("rx buffer discard because of abort.%d\n", __LINE__); - free_rxbuffer(priv, rbuff); - } - - rsize = -ECONNABORTED; - } - else - { - if (rbuff == NULL) - { - m_err("get rx buffer failed.\n"); - rsize = -EIO; - } - else if (rbuff->rx_size > readlen) - { - m_info("get rx buffer.%d\n", __LINE__); - rsize = readlen; - memcpy((void *)buffer, rbuff->buff_addr, rsize); - free_rxbuffer(priv, rbuff); - } - else - { - m_info("get rx buffer.%d\n", __LINE__); - rsize = rbuff->rx_size; - memcpy((void *)buffer, rbuff->buff_addr, rsize); - free_rxbuffer(priv, rbuff); - } - } - - altmdm_sys_unlock(&spidev->rx_param.lock); - - return rsize; -} - -/**************************************************************************** - * Name: altmdm_spi_write - * - * Description: - * ALTMDM SPI driver write method. - * - ****************************************************************************/ - -ssize_t altmdm_spi_write(FAR struct altmdm_dev_s * priv, - FAR const char *buffer, size_t witelen) -{ - int ret; - int remainder; - uint32_t ptn; - FAR struct altmdm_spi_dev_s *spidev; - ssize_t wsize = witelen; - - /* Check argument */ - - if ((priv == NULL) || (buffer == NULL)) - { - return -EINVAL; - } - - if (!witelen || witelen > MAX_PKT_SIZE) - { - m_err("Invalid write length:%d.\n", witelen); - return -EINVAL; - } - - spidev = &priv->spidev; - - if (!spidev->is_xferready) - { - wait_xferready(priv); - } - - altmdm_sys_lock(&spidev->tx_param.lock); - -again: - spidev->tx_param.buff_addr = (void *)buffer; - spidev->tx_param.actual_size = witelen; - - remainder = witelen % UNIT_SIZE; - if (remainder == 0) - { - spidev->tx_param.total_size = spidev->tx_param.actual_size; - } - else - { - spidev->tx_param.total_size = - ((spidev->tx_param.actual_size / UNIT_SIZE) + 1) * UNIT_SIZE; - } - - spidev->tx_param.result = 0; - - altmdm_sys_setflag(&spidev->xfer_flag, EVENT_TXREQ); - - ret = altmdm_sys_waitflag(&spidev->tx_param.done_flag, - EVENT_TX_DONE, - ALTMDM_SYS_FLAG_WMODEOR, - &ptn, - WRITE_WAIT_TIMEOUT); - if (ret != OK) - { - m_err("wait failed:%d\n", ret); - wsize = -ETIME; - } - else - { - switch (spidev->tx_param.result) - { - case TRANS_OK: - case TRANS_OK_TRXDATANORXBUFF: - wsize = witelen; - break; - - case TRANS_RXINVALID: - case TRANS_WAITRCVRTMO: - wsize = -EIO; - break; - - case TRANS_OK_RCVBUFFUL: - nxsig_usleep(100); - goto again; - break; - - default: - m_err("Unexpected situation. tx result = %d.\n", - spidev->tx_param.result); - wsize = -EIO; - break; - } - - m_info("%s: tx result: %d.\n", __func__, spidev->tx_param.result); - m_info("%s: write size: %d.\n", __func__, wsize); - } - - altmdm_sys_unlock(&spidev->tx_param.lock); - - return wsize; -} - -/**************************************************************************** - * Name: spicom_read_abort - * - * Description: - * Abort the read process. - * - ****************************************************************************/ - -int altmdm_spi_readabort(FAR struct altmdm_dev_s *priv) -{ - /* Check argument */ - - if (priv == NULL) - { - return -EINVAL; - } - - abort_get_rxbufffifo(priv); - - return OK; -} - -/**************************************************************************** - * Name: altmdm_spi_sleepmodem - * - * Description: - * Make ALTMDM sleep. - * - ****************************************************************************/ - -int altmdm_spi_sleepmodem(FAR struct altmdm_dev_s *priv) -{ - int ret; - bool sleep_requested; - uint32_t ptn; - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - altmdm_sys_lock(&spidev->sleep_param.lock); - sleep_requested = spidev->sleep_param.requested; - if (!sleep_requested) - { - spidev->sleep_param.requested = true; - } - - altmdm_sys_unlock(&spidev->sleep_param.lock); - - if (sleep_requested) - { - ret = -EBUSY; - } - else - { - spidev->sleep_param.result = 0; - - altmdm_sys_setflag(&spidev->xfer_flag, EVENT_SLEEPREQ); - - ret = altmdm_sys_waitflag(&spidev->sleep_param.done_flag, - EVENT_SLEEP_DONE, ALTMDM_SYS_FLAG_WMODEOR, - &ptn, SREQ_WAIT_TIMEOUT); - if (ret != OK) - { - m_err("wait failed:%d\n", ret); - } - else - { - ret = spidev->sleep_param.result; - m_info("%s: sleep result: %d.\n", __func__, - spidev->sleep_param.result); - } - - spidev->sleep_param.requested = false; - } - - return ret; -} - -/**************************************************************************** - * Name: altmdm_spi_setreceiverready - * - * Description: - * Set receiver ready notification. - * - ****************************************************************************/ - -int altmdm_spi_setreceiverready(FAR struct altmdm_dev_s *priv) -{ - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - altmdm_sys_setflag(&spidev->xfer_flag, EVENT_RXREQ); - - return 0; -} - -/**************************************************************************** - * Name: altmdm_spi_isreceiverready - * - * Description: - * Check already notified or not by altmdm_spi_setreceiverready. - * - ****************************************************************************/ - -int altmdm_spi_isreceiverready(FAR struct altmdm_dev_s *priv) -{ - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - struct altmdm_sys_flagstate_s flag_status; - - altmdm_sys_referflag(&spidev->xfer_flag, &flag_status); - if (flag_status.flag_pattern & EVENT_RXREQ) - { - return 1; - } - - return 0; -} - -/**************************************************************************** - * Name: altmdm_spi_clearreceiverready - * - * Description: - * Clear receiver ready notification. - * - ****************************************************************************/ - -int altmdm_spi_clearreceiverready(FAR struct altmdm_dev_s *priv) -{ - FAR struct altmdm_spi_dev_s *spidev = &priv->spidev; - - altmdm_sys_clearflag(&spidev->xfer_flag, EVENT_RXREQ); - - return 0; -} - -#endif /* CONFIG_MODEM_ALTMDM */ diff --git a/drivers/modem/altair/altmdm_spi.h b/drivers/modem/altair/altmdm_spi.h deleted file mode 100644 index 48def41c140..00000000000 --- a/drivers/modem/altair/altmdm_spi.h +++ /dev/null @@ -1,172 +0,0 @@ -/**************************************************************************** - * drivers/modem/altair/altmdm_spi.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_ALTAIR_ALTMDM_SPI_H -#define __DRIVERS_MODEM_ALTAIR_ALTMDM_SPI_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include "altmdm_dev.h" -#include "altmdm_sys.h" - -#if defined(CONFIG_MODEM_ALTMDM) - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/* This structure describes the transfer header. */ - -struct altmdm_spi_xferhdr_s -{ - uint8_t header[4]; /* Transfer header. */ -}; - -/* This structure describes the buffer for data receive. */ - -struct altmdm_spi_rxbuff_s -{ - FAR char *buff_addr; /* Receive buffer address. */ - uint32_t buff_size; /* Size of this buffer. */ - uint32_t rx_size; /* Received data size. */ - FAR struct altmdm_spi_rxbuff_s *next; /* Link for next buffer. */ -}; - -/* This structure describes the fifo for received buffer. */ - -struct altmdm_spi_rxbufffifo_s -{ - FAR struct altmdm_spi_rxbuff_s *head; /* Point to the head of fifo */ - FAR struct altmdm_spi_rxbuff_s *tail; /* Point to the tail of fifo */ - struct altmdm_sys_csem_s csem; /* It is used for notification when - * data is put in fifo. - */ -}; - -/* This structure describes the parameters for receive buffer information. */ - -struct altmdm_spi_rxbuffinfo_s -{ - FAR struct altmdm_spi_rxbuff_s *free_buff; /* Free receive buffer address. */ - struct altmdm_spi_rxbufffifo_s fifo; /* Receive buffer fifo. */ -}; - -/* This structure describes the parameters for send data. */ - -struct altmdm_spi_tx_s -{ - struct altmdm_sys_lock_s lock; /* Lock on accessing the following - * parameters. - */ - struct altmdm_sys_flag_s done_flag; /* Notify that tx request has been - * completed. - */ - struct altmdm_spi_xferhdr_s header; /* Tx header. */ - FAR char *buff_addr; /* Buffer address for data transmission - * specified by the user. - */ - int32_t actual_size; /* Actual data size. */ - int32_t total_size; /* Data size of 4byte alignment. */ - int32_t result; /* Result of transfer. */ - int32_t is_bufful; /* Indicates the slave is buffer full status. */ -}; - -/* This structure describes the parameters for receive data. */ - -struct altmdm_spi_rx_s -{ - struct altmdm_sys_lock_s lock; /* Lock on accessing the following - * parameters. - */ - struct altmdm_spi_xferhdr_s header; /* Rx header. */ - int8_t status_info; /* Header status information */ - int32_t actual_size; /* Actual data size */ - int32_t total_size; /* Data size of 4byte alignment. */ - - FAR struct altmdm_spi_rxbuff_s *rxbuff; /* Current receive buffer. */ - bool rxabort; /* Indicates whether the rx process - * is aborted. - */ -}; - -/* This structure describes the parameters for sleep modem. */ - -struct altmdm_spi_sleepmodem_s -{ - struct altmdm_sys_lock_s lock; /* Lock on accessing the following - * parameters. - */ - - struct altmdm_sys_flag_s done_flag; /* Notify that sleep request has been - * completed. - */ - int32_t result; /* Result of sleep request. */ - bool requested; /* Indicates that sleep request has been requested. */ - timer_t sv_timerid; /* Supervisor timer. */ -}; - -/* This structure describes the resource of the ALTMDM spi driver */ - -struct altmdm_spi_dev_s -{ - /* Common fields */ - - bool is_not_run; /* Indicates xfer task is not run. */ - int32_t task_id; /* xfer task ID. */ - bool is_xferready; /* Indicates whether the modem is ready to xfer. */ - - struct altmdm_sys_flag_s xferready_flag; /* Used for waiting ready to - * xfer. - */ - - struct altmdm_sys_flag_s xfer_flag; /* Used for event handling of xfer - * task. - */ - - struct altmdm_sys_flag_s dma_done_flag; /* Notify that DMA transfer has - * been completed. - */ - - /* Parameter for receive buffer */ - - struct altmdm_spi_rxbuffinfo_s rxbuffinfo; - - /* Parameter for send data */ - - struct altmdm_spi_tx_s tx_param; - - /* Parameter for receive data */ - - struct altmdm_spi_rx_s rx_param; - - /* Parameters for sleep modem */ - - struct altmdm_spi_sleepmodem_s sleep_param; -}; - -#endif -#endif /* __DRIVERS_MODEM_ALTAIR_ALTMDM_SPI_H */ diff --git a/drivers/modem/altair/altmdm_sys.c b/drivers/modem/altair/altmdm_sys.c deleted file mode 100644 index 48e469c4a1d..00000000000 --- a/drivers/modem/altair/altmdm_sys.c +++ /dev/null @@ -1,724 +0,0 @@ -/**************************************************************************** - * drivers/modem/altair/altmdm_sys.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 -#include -#include -#include - -#include - -#include "altmdm_dev.h" -#include "altmdm_sys.h" - -#if defined(CONFIG_MODEM_ALTMDM) - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define MY_TIMER_SIGNAL SIGUSR1 - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: altmdm_sys_initlock - * - * Description: - * Initialize lock resource. - * - ****************************************************************************/ - -int altmdm_sys_initlock(FAR struct altmdm_sys_lock_s *handle) -{ - int ret; - - /* Check argument. */ - - if (handle == NULL) - { - return ERROR; - } - - ret = nxmutex_init(&handle->lock); - -#ifdef CONFIG_MODEM_ALTMDM_DEBUG - if (ret < 0) - { - m_err("nxsem_init() failed:%d\n", ret); - } -#endif - - return ret; -} - -/**************************************************************************** - * Name: altmdm_sys_deletelock - * - * Description: - * Delete lock resource - * - ****************************************************************************/ - -int altmdm_sys_deletelock(FAR struct altmdm_sys_lock_s *handle) -{ - int ret; - - /* Check argument. */ - - if (handle == NULL) - { - return ERROR; - } - - ret = nxmutex_destroy(&handle->lock); - -#ifdef CONFIG_MODEM_ALTMDM_DEBUG - if (ret < 0) - { - m_err("nxsem_destroy() failed:%d\n", ret); - } -#endif - - return ret; -} - -/**************************************************************************** - * Name: altmdm_sys_lock - * - * Description: - * Acquire lock. - * - ****************************************************************************/ - -int altmdm_sys_lock(FAR struct altmdm_sys_lock_s *handle) -{ - int ret; - - /* Check argument. */ - - if (handle == NULL) - { - return ERROR; - } - - ret = nxmutex_lock(&handle->lock); - if (ret < 0) - { - m_err("nxsem_wait_uninterruptible() failed:%d\n", ret); - } - - return ret; -} - -/**************************************************************************** - * Name: altmdm_sys_unlock - * - * Description: - * Release lock. - * - ****************************************************************************/ - -int altmdm_sys_unlock(FAR struct altmdm_sys_lock_s *handle) -{ - int ret; - - /* Check argument. */ - - if (handle == NULL) - { - return ERROR; - } - - ret = nxmutex_unlock(&handle->lock); - -#ifdef CONFIG_MODEM_ALTMDM_DEBUG - if (ret < 0) - { - m_err("nxsem_post() failed:%d\n", ret); - } -#endif - - return ret; -} - -/**************************************************************************** - * Name: altmdm_sys_initcsem - * - * Description: - * Initialize counting semaphore. - * - ****************************************************************************/ - -int altmdm_sys_initcsem(FAR struct altmdm_sys_csem_s *handle) -{ - int ret; - - /* Check argument. */ - - if (handle == NULL) - { - return ERROR; - } - - ret = nxsem_init(&handle->sem, 0, 0); - -#ifdef CONFIG_MODEM_ALTMDM_DEBUG - if (ret < 0) - { - m_err("nxsem_init() failed:%d\n", ret); - } -#endif - - return ret; -} - -/**************************************************************************** - * Name: altmdm_sys_deletecsem - * - * Description: - * Delete counting semaphore. - * - ****************************************************************************/ - -int altmdm_sys_deletecsem(FAR struct altmdm_sys_csem_s *handle) -{ - int ret; - - /* Check argument. */ - - if (handle == NULL) - { - return ERROR; - } - - ret = nxsem_destroy(&handle->sem); - -#ifdef CONFIG_MODEM_ALTMDM_DEBUG - if (ret < 0) - { - m_err("nxsem_destroy() failed:%d\n", ret); - } -#endif - - return ret; -} - -/**************************************************************************** - * Name: altmdm_sys_waitcsem - * - * Description: - * Wait counting semaphore. - * - ****************************************************************************/ - -int altmdm_sys_waitcsem(FAR struct altmdm_sys_csem_s *handle) -{ - int ret; - - /* Check argument. */ - - if (handle == NULL) - { - return ERROR; - } - - ret = nxsem_wait_uninterruptible(&handle->sem); - if (ret < 0) - { - m_err("nxsem_wait_uninterruptible() failed:%d\n", ret); - } - - return ret; -} - -/**************************************************************************** - * Name: altmdm_sys_postcsem - * - * Description: - * Post counting semaphore. - * - ****************************************************************************/ - -int altmdm_sys_postcsem(FAR struct altmdm_sys_csem_s *handle) -{ - int ret; - - /* Check argument. */ - - if (handle == NULL) - { - return ERROR; - } - - ret = nxsem_post(&handle->sem); - -#ifdef CONFIG_MODEM_ALTMDM_DEBUG - if (ret < 0) - { - m_err("nxsem_post() failed:%d\n", ret); - } -#endif - - return ret; -} - -/**************************************************************************** - * Name: altmdm_sys_getcsemvalue - * - * Description: - * Get value of counting semaphore. - * - ****************************************************************************/ - -int altmdm_sys_getcsemvalue(FAR struct altmdm_sys_csem_s *handle, - FAR int *value) -{ - int ret; - - /* Check argument. */ - - if ((handle == NULL) || (value == NULL)) - { - return ERROR; - } - - ret = nxsem_get_value(&handle->sem, value); - -#ifdef CONFIG_MODEM_ALTMDM_DEBUG - if (ret < 0) - { - m_err("nxsem_get_value() failed:%d\n", ret); - } -#endif - - return ret; -} - -/**************************************************************************** - * Name: altmdm_sys_initflag - * - * Description: - * Initialize event flag resource. - * - ****************************************************************************/ - -int altmdm_sys_initflag(FAR struct altmdm_sys_flag_s *handle) -{ - int ret; - - /* Check argument. */ - - if (handle == NULL) - { - return ERROR; - } - - handle->flag = 0; - ret = nxsem_init(&handle->sem, 0, 0); - -#ifdef CONFIG_MODEM_ALTMDM_DEBUG - if (ret < 0) - { - m_err("nxsem_init() failed:%d\n", ret); - } -#endif - - return ret; -} - -/**************************************************************************** - * Name: altmdm_sys_deleteflag - * - * Description: - * Delete event flag resource. - * - ****************************************************************************/ - -int altmdm_sys_deleteflag(FAR struct altmdm_sys_flag_s *handle) -{ - int ret; - - /* Check argument. */ - - if (handle == NULL) - { - return ERROR; - } - - ret = nxsem_destroy(&handle->sem); - -#ifdef CONFIG_MODEM_ALTMDM_DEBUG - if (ret < 0) - { - m_err("nxsem_destroy() failed:%d\n", ret); - } -#endif - - return ret; -} - -/**************************************************************************** - * Name: altmdm_sys_waitflag - * - * Description: - * Wait event flag. - * - ****************************************************************************/ - -int altmdm_sys_waitflag(FAR struct altmdm_sys_flag_s *handle, - uint32_t wait_pattern, uint32_t wait_mode, - FAR uint32_t * pattern, uint32_t timeout_ms) -{ - int ret = OK; - irqstate_t flags; - uint32_t ptn; - - /* Check argument. */ - - if ((handle == NULL) || (pattern == NULL)) - { - m_err("invalid parameter\n"); - - return ERROR; - } - - switch (wait_mode) - { - case ALTMDM_SYS_FLAG_WMODEOR: - case ALTMDM_SYS_FLAG_WMODEAND: - break; - - default: - m_err("invalid wait mode:%d\n", wait_mode); - return ERROR; - } - - *pattern = 0; - - while (1) - { - if (wait_mode == ALTMDM_SYS_FLAG_WMODEOR) - { - flags = enter_critical_section(); - - ptn = (handle->flag & wait_pattern); - if (ptn != 0) - { - /* Wait pattern matched. */ - - *pattern = ptn; - handle->flag = (handle->flag & ~ptn); - - /* Clear the semaphore posted by altmdm_sys_setflag. */ - - while (1) - { - if (nxsem_trywait(&handle->sem) < 0) - { - break; - } - } - - leave_critical_section(flags); - - ret = OK; - break; - } - - leave_critical_section(flags); - } - else - { - flags = enter_critical_section(); - - ptn = (handle->flag & wait_pattern); - if (ptn == wait_pattern) - { - /* Wait pattern matched. */ - - *pattern = ptn; - handle->flag = (handle->flag & ~ptn); - - /* Clear the semaphore posted by altmdm_sys_setflag. */ - - while (1) - { - if (nxsem_trywait(&handle->sem) < 0) - { - break; - } - } - - leave_critical_section(flags); - - ret = OK; - break; - } - - leave_critical_section(flags); - } - - if (timeout_ms != ALTMDM_SYS_FLAG_TMOFEVR) - { - /* Wait for the semaphore to be posted until timeout occurs. */ - - ret = nxsem_tickwait_uninterruptible(&handle->sem, - MSEC2TICK(timeout_ms)); - if (ret < 0) - { - m_err("nxsem_tickwait_uninterruptible() failed:%d\n", ret); - break; - } - } - else - { - /* Wait for the semaphore to be posted forever. */ - - ret = nxsem_wait_uninterruptible(&handle->sem); - if (ret < 0) - { - m_err("nxsem_wait_uninterruptible() failed:%d\n", ret); - break; - } - } - } - - return ret; -} - -/**************************************************************************** - * Name: altmdm_sys_setflag - * - * Description: - * Set event flag. - * - ****************************************************************************/ - -int altmdm_sys_setflag(FAR struct altmdm_sys_flag_s *handle, - uint32_t pattern) -{ - int ret; - irqstate_t flags; - - /* Check argument. */ - - if (handle == NULL) - { - return ERROR; - } - - flags = enter_critical_section(); - - handle->flag = (handle->flag | pattern); - - leave_critical_section(flags); - - ret = nxsem_post(&handle->sem); - - return ret; -} - -/**************************************************************************** - * Name: altmdm_sys_clearflag - * - * Description: - * Clear event flag. - * - ****************************************************************************/ - -int altmdm_sys_clearflag(FAR struct altmdm_sys_flag_s *handle, - uint32_t pattern) -{ - irqstate_t flags; - - /* Check argument. */ - - if (handle == NULL) - { - return ERROR; - } - - flags = enter_critical_section(); - - handle->flag = (handle->flag & ~pattern); - - leave_critical_section(flags); - - return OK; -} - -/**************************************************************************** - * Name: altmdm_sys_referflag - * - * Description: - * Refer event flag. - * - ****************************************************************************/ - -int altmdm_sys_referflag(FAR struct altmdm_sys_flag_s *handle, - FAR struct altmdm_sys_flagstate_s *status) -{ - irqstate_t flags; - - /* Check argument. */ - - if ((handle == NULL) || (status == NULL)) - { - return ERROR; - } - - flags = enter_critical_section(); - - status->flag_pattern = handle->flag; - - leave_critical_section(flags); - - return OK; -} - -/**************************************************************************** - * Name: altmdm_sys_starttimer - * - * Description: - * Start timer. - * - ****************************************************************************/ - -timer_t altmdm_sys_starttimer(int first_ms, int interval_ms, - FAR void *handler, int int_param, - FAR void *ptr_param) -{ - int ret; - sigset_t mask; - struct sigaction sa; - struct sigevent sev; - struct itimerspec timer; - timer_t timerid; - - /* Check argument. */ - - if (handler == NULL) - { - return NULL; - } - - sigemptyset(&mask); - nxsig_addset(&mask, MY_TIMER_SIGNAL); - - ret = nxsig_procmask(SIG_UNBLOCK, &mask, NULL); - if (ret != OK) - { - m_err("nxsig_procmask() failed:%d\n", ret); - return NULL; - } - - sa.sa_sigaction = handler; - sa.sa_flags = SA_SIGINFO; - sigfillset(&sa.sa_mask); - nxsig_delset(&sa.sa_mask, MY_TIMER_SIGNAL); - - ret = nxsig_action(MY_TIMER_SIGNAL, &sa, NULL, false); - if (ret != OK) - { - m_err("nxsig_action() failed:%d\n", ret); - return NULL; - } - - sev.sigev_notify = SIGEV_SIGNAL; - sev.sigev_signo = MY_TIMER_SIGNAL; - sev.sigev_value.sival_int = int_param; - sev.sigev_value.sival_ptr = ptr_param; - - ret = timer_create(CLOCK_REALTIME, &sev, &timerid); - if (ret != OK) - { - m_err("timer_create() failed:%d\n", ret); - return NULL; - } - - timer.it_value.tv_sec = first_ms / 1000; - timer.it_value.tv_nsec = (first_ms % 1000) * 1000 * 1000; - timer.it_interval.tv_sec = interval_ms / 1000; - timer.it_interval.tv_nsec = (interval_ms % 1000) * 1000 * 1000; - - ret = timer_settime(timerid, 0, &timer, NULL); - if (ret != OK) - { - m_err("timer_settime() failed:%d\n", ret); - return NULL; - } - - return timerid; -} - -/**************************************************************************** - * Name: altmdm_sys_restarttimer - * - * Description: - * Restart timer. - * - ****************************************************************************/ - -int altmdm_sys_restarttimer(timer_t timerid, int first_ms, int interval_ms) -{ - int ret; - struct itimerspec timer; - - timer.it_value.tv_sec = first_ms / 1000; - timer.it_value.tv_nsec = (first_ms % 1000) * 1000 * 1000; - timer.it_interval.tv_sec = interval_ms / 1000; - timer.it_interval.tv_nsec = (interval_ms % 1000) * 1000 * 1000; - - ret = timer_settime(timerid, 0, &timer, NULL); - if (ret != OK) - { - m_err("timer_settime() failed:%d\n", ret); - return ret; - } - - return ret; -} - -/**************************************************************************** - * Name: altmdm_sys_stoptimer - * - * Description: - * Stop timer. - * - ****************************************************************************/ - -void altmdm_sys_stoptimer(timer_t timerid) -{ - sigset_t mask; - - timer_delete(timerid); - - sigfillset(&mask); - nxsig_procmask(SIG_SETMASK, &mask, NULL); -} - -#endif diff --git a/drivers/modem/altair/altmdm_sys.h b/drivers/modem/altair/altmdm_sys.h deleted file mode 100644 index 773ea545bfe..00000000000 --- a/drivers/modem/altair/altmdm_sys.h +++ /dev/null @@ -1,260 +0,0 @@ -/**************************************************************************** - * drivers/modem/altair/altmdm_sys.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_ALTAIR_ALTMDM_SYS_H -#define __DRIVERS_MODEM_ALTAIR_ALTMDM_SYS_H - -#if defined(CONFIG_MODEM_ALTMDM) - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -#define ALTMDM_SYS_FLAG_WMODEOR 0 -#define ALTMDM_SYS_FLAG_WMODEAND 1 -#define ALTMDM_SYS_FLAG_TMOFEVR 0 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct altmdm_sys_lock_s -{ - mutex_t lock; -}; - -struct altmdm_sys_csem_s -{ - sem_t sem; -}; - -struct altmdm_sys_flag_s -{ - sem_t sem; - uint32_t flag; -}; - -struct altmdm_sys_flagstate_s -{ - uint32_t flag_pattern; -}; - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -/**************************************************************************** - * Name: altmdm_sys_initlock - * - * Description: - * Initialize lock resource. - * - ****************************************************************************/ - -int altmdm_sys_initlock(FAR struct altmdm_sys_lock_s *handle); - -/**************************************************************************** - * Name: altmdm_sys_deletelock - * - * Description: - * Delete lock resource - * - ****************************************************************************/ - -int altmdm_sys_deletelock(FAR struct altmdm_sys_lock_s *handle); - -/**************************************************************************** - * Name: altmdm_sys_lock - * - * Description: - * Acquire lock. - * - ****************************************************************************/ - -int altmdm_sys_lock(FAR struct altmdm_sys_lock_s *handle); - -/**************************************************************************** - * Name: altmdm_sys_unlock - * - * Description: - * Release lock. - * - ****************************************************************************/ - -int altmdm_sys_unlock(FAR struct altmdm_sys_lock_s *handle); - -/**************************************************************************** - * Name: altmdm_sys_initcsem - * - * Description: - * Initialize counting semaphore. - * - ****************************************************************************/ - -int altmdm_sys_initcsem(FAR struct altmdm_sys_csem_s *handle); - -/**************************************************************************** - * Name: altmdm_sys_deletecsem - * - * Description: - * Delete counting semaphore. - * - ****************************************************************************/ - -int altmdm_sys_deletecsem(FAR struct altmdm_sys_csem_s *handle); - -/**************************************************************************** - * Name: altmdm_sys_waitcsem - * - * Description: - * Wait counting semaphore. - * - ****************************************************************************/ - -int altmdm_sys_waitcsem(FAR struct altmdm_sys_csem_s *handle); - -/**************************************************************************** - * Name: altmdm_sys_postcsem - * - * Description: - * Post counting semaphore. - * - ****************************************************************************/ - -int altmdm_sys_postcsem(FAR struct altmdm_sys_csem_s *handle); - -/**************************************************************************** - * Name: altmdm_sys_getcsemvalue - * - * Description: - * Get value of counting semaphore. - * - ****************************************************************************/ - -int altmdm_sys_getcsemvalue(FAR struct altmdm_sys_csem_s *handle, - FAR int *value); - -/**************************************************************************** - * Name: altmdm_sys_initflag - * - * Description: - * Initialize event flag resource. - * - ****************************************************************************/ - -int altmdm_sys_initflag(FAR struct altmdm_sys_flag_s *handle); - -/**************************************************************************** - * Name: altmdm_sys_deleteflag - * - * Description: - * Delete event flag resource. - * - ****************************************************************************/ - -int altmdm_sys_deleteflag(FAR struct altmdm_sys_flag_s *handle); - -/**************************************************************************** - * Name: altmdm_sys_waitflag - * - * Description: - * Wait event flag. - * - ****************************************************************************/ - -int altmdm_sys_waitflag(FAR struct altmdm_sys_flag_s *handle, - uint32_t wait_pattern, uint32_t wait_mode, - FAR uint32_t * pattern, uint32_t timeout_ms); - -/**************************************************************************** - * Name: altmdm_sys_setflag - * - * Description: - * Set event flag. - * - ****************************************************************************/ - -int altmdm_sys_setflag(FAR struct altmdm_sys_flag_s *handle, - uint32_t pattern); - -/**************************************************************************** - * Name: altmdm_sys_clearflag - * - * Description: - * Clear event flag. - * - ****************************************************************************/ - -int altmdm_sys_clearflag(FAR struct altmdm_sys_flag_s *handle, - uint32_t pattern); - -/**************************************************************************** - * Name: altmdm_sys_referflag - * - * Description: - * Refer event flag. - * - ****************************************************************************/ - -int altmdm_sys_referflag(FAR struct altmdm_sys_flag_s *handle, - FAR struct altmdm_sys_flagstate_s *status); - -/**************************************************************************** - * Name: altmdm_sys_starttimer - * - * Description: - * Start timer. - * - ****************************************************************************/ - -timer_t altmdm_sys_starttimer(int first_ms, int interval_ms, - FAR void *handler, int int_param, - FAR void *ptr_param); - -/**************************************************************************** - * Name: altmdm_sys_restarttimer - * - * Description: - * Restart timer. - * - ****************************************************************************/ - -int altmdm_sys_restarttimer(timer_t timerid, int first_ms, int interval_ms); - -/**************************************************************************** - * Name: altmdm_sys_stoptimer - * - * Description: - * Stop timer. - * - ****************************************************************************/ - -void altmdm_sys_stoptimer(timer_t timerid); - -#endif -#endif /* __DRIVERS_MODEM_ALTAIR_ALTMDM_SYS_H */ diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h index 8c2b303e6e9..ef654c47c9d 100644 --- a/include/nuttx/fs/ioctl.h +++ b/include/nuttx/fs/ioctl.h @@ -91,6 +91,7 @@ #define _MMCSDIOBASE (0x3300) /* MMCSD device ioctl commands */ #define _BLUETOOTHBASE (0x3400) /* Bluetooth ioctl commands */ #define _PKTRADIOBASE (0x3500) /* Packet radio ioctl commands */ +#define _LTEBASE (0x3600) /* LTE device ioctl commands */ #define _WLIOCBASE (0x8b00) /* Wireless modules ioctl network commands */ /* boardctl() commands share the same number space */ @@ -593,6 +594,11 @@ #define _PKRADIOIOCVALID(c) (_IOC_TYPE(c)==_PKTRADIOBASE) #define _PKRADIOIOC(nr) _IOC(_PKTRADIOBASE,nr) +/* LTE device ioctl definitions *********************************************/ + +#define _LTEIOCVALID(c) (_IOC_TYPE(c)==_LTEBASE) +#define _LTEIOC(nr) _IOC(_LTEBASE,nr) + /* Wireless driver network ioctl definitions ********************************/ /* (see nuttx/include/wireless/wireless.h */ diff --git a/include/nuttx/modem/alt1250.h b/include/nuttx/modem/alt1250.h new file mode 100644 index 00000000000..54377fdd6d1 --- /dev/null +++ b/include/nuttx/modem/alt1250.h @@ -0,0 +1,394 @@ +/**************************************************************************** + * include/nuttx/modem/alt1250.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_MODEM_ALT1250_H +#define __INCLUDE_NUTTX_MODEM_ALT1250_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Debug ********************************************************************/ + +/* Non-standard debug that may be enabled just for testing the modem driver */ + +#ifdef CONFIG_MODEM_ALT1250_DEBUG +# define m_err _err +# define m_warn _warn +# define m_info _info +#else +# define m_err(...) +# define m_warn(...) +# define m_info(...) +#endif + +#define ALT1250_IOC_POWER _MODEMIOC(1) +#define ALT1250_IOC_SEND _MODEMIOC(2) +#define ALT1250_IOC_SETEVTBUFF _MODEMIOC(3) +#define ALT1250_IOC_EXCHGCONTAINER _MODEMIOC(4) + +#define ALT1250_EVTBIT_RESET (1ULL << 63) +#define ALT1250_EVTBIT_REPLY (1ULL << 62) + +/* Number of sockets */ + +#define ALTCOM_NSOCKET 10 + +/* Macros for fcntl */ + +#define ALTCOM_GETFL 3 +#define ALTCOM_SETFL 4 + +#define ALTCOM_O_NONBLOCK 0x01 + +#define ALTCOM_FD_SETSIZE ALTCOM_NSOCKET + +#define ALTCOM_FDSETSAFESET(s, code) \ + do { \ + if (((s) < ALTCOM_FD_SETSIZE) && ((int)(s) >= 0)) \ + { \ + code; \ + } \ + } while(0) +#define ALTCOM_FDSETSAFEGET(s, code) \ + (((s) < ALTCOM_FD_SETSIZE) && ((int)(s) >= 0) ? (code) : 0) + +#define ALTCOM_FD_SET(s, set) ALTCOM_FDSETSAFESET(s, (set)->fd_bits[(s)/8] |= (1 << ((s) & 7))) +#define ALTCOM_FD_CLR(s, set) ALTCOM_FDSETSAFESET(s, (set)->fd_bits[(s)/8] &= ~(1 << ((s) & 7))) +#define ALTCOM_FD_ISSET(s, set) ALTCOM_FDSETSAFEGET(s, (set)->fd_bits[(s)/8] & (1 << ((s) & 7))) +#define ALTCOM_FD_ZERO(set) memset((void*)(set), 0, sizeof(*(set))) + +#define ALTCOM_DNS_SERVERS (4) +#define ALTCOM_REPEVT_FLAG_SIMSTAT (1 << 0) +#define ALTCOM_REPEVT_FLAG_LTIME (1 << 1) + +#define ALTCOM_VERX (0) +#define ALTCOM_VER1 (1) +#define ALTCOM_VER4 (4) + +#define APICMDID_UNKNOWN (0x0000) +#define APICMDID_POWER_ON (0x0001) +#define ALTCOM_CMDID_POWER_ON_V1 (0x0001) +#define ALTCOM_CMDID_POWER_ON_V4 (0x0311) +#define APICMDID_GET_VERSION (0x000C) +#define APICMDID_GET_PHONENO (0x000D) +#define APICMDID_GET_IMSI (0x000E) +#define APICMDID_GET_IMEI (0x000F) +#define APICMDID_GET_PINSET (0x0010) +#define APICMDID_SET_PIN_LOCK (0x0011) +#define APICMDID_SET_PIN_CODE (0x0012) +#define APICMDID_ENTER_PIN (0x0013) +#define APICMDID_GET_LTIME (0x0014) +#define APICMDID_GET_OPERATOR (0x0015) +#define APICMDID_SET_REP_EVT (0x0019) +#define APICMDID_SET_REP_QUALITY (0x001A) +#define APICMDID_SET_REP_CELLINFO (0x001B) +#define APICMDID_REPORT_EVT (0x001D) +#define APICMDID_REPORT_QUALITY (0x001E) +#define APICMDID_REPORT_CELLINFO (0x001F) +#define APICMDID_GET_EDRX (0x0020) +#define APICMDID_SET_EDRX (0x0021) +#define APICMDID_GET_PSM (0x0022) +#define APICMDID_SET_PSM (0x0023) +#define APICMDID_GET_CE (0x0024) +#define APICMDID_SET_CE (0x0025) +#define APICMDID_RADIO_ON (0x0026) +#define APICMDID_RADIO_OFF (0x0027) +#define APICMDID_ACTIVATE_PDN (0x0028) +#define APICMDID_DEACTIVATE_PDN (0x0029) +#define APICMDID_DATA_ALLOW (0x002A) +#define APICMDID_GET_NETINFO (0x002B) +#define APICMDID_GET_IMS_CAP (0x002C) +#define APICMDID_SETREP_NETINFO (0x002D) +#define APICMDID_REPORT_NETINFO (0x002E) +#define APICMDID_REPORT_RESTART (0x002F) +#define APICMDID_ERRINFO (0x0030) +#define APICMDID_SET_REP_EVT_LTIME (0x0031) +#define APICMDID_SET_REP_EVT_SIMSTATE (0x0032) +#define APICMDID_POWER_OFF (0x0033) +#define APICMDID_GET_SIMINFO (0x0034) +#define APICMDID_GET_DYNAMICEDRX (0x0035) +#define APICMDID_GET_DYNAMICPSM (0x0036) +#define APICMDID_GET_QUALITY (0x0037) +#define APICMDID_ACTIVATE_PDN_CANCEL (0x0038) +#define APICMDID_FW_INJECTDELTAIMG (0x1040) +#define APICMDID_FW_GETDELTAIMGLEN (0x1041) +#define APICMDID_FW_EXECDELTAUPDATE (0x1042) +#define APICMDID_FW_GETUPDATERESULT (0x1043) +#define APICMDID_CLOGS (0x1023) +#define APICMDID_LOGLIST (0x1024) +#define APICMDID_LOGOPEN (0x1030) +#define APICMDID_LOGCLOSE (0x1031) +#define APICMDID_LOGREAD (0x1033) +#define APICMDID_LOGREMOVE (0x1034) +#define APICMDID_LOGLSEEK (0x1035) + +/* dummy ID because not support V1 */ + +#define APICMDID_GET_CELLINFO (0x0039) +#define APICMDID_GET_RAT (0x00A0) +#define APICMDID_SET_RAT (0x00A1) +#define APICMDID_SEND_ATCMD (0x00B0) +#define APICMDID_URC_EVENT (0x00B2) + +#define APICMDID_GET_VERSION_V4 (0x000B) +#define APICMDID_GET_PHONENO_V4 (0x000C) +#define APICMDID_GET_IMSI_V4 (0x000D) +#define APICMDID_GET_IMEI_V4 (0x000E) +#define APICMDID_GET_PINSET_V4 (0x000F) +#define APICMDID_SET_PIN_LOCK_V4 (0x0010) +#define APICMDID_SET_PIN_CODE_V4 (0x0011) +#define APICMDID_ENTER_PIN_V4 (0x0012) +#define APICMDID_GET_LTIME_V4 (0x0013) +#define APICMDID_GET_OPERATOR_V4 (0x0014) +#define APICMDID_GET_SLPMODESET_V4 (0x0015) +#define APICMDID_SET_SLPMODESET_V4 (0x0016) +#define APICMDID_SET_REP_NETSTAT_V4 (0x0017) +#define APICMDID_SET_REP_EVT_V4 (0x0018) +#define APICMDID_SET_REP_QUALITY_V4 (0x0019) +#define APICMDID_SET_REP_CELLINFO_V4 (0x001A) +#define APICMDID_REPORT_NETSTAT_V4 (0x001B) +#define APICMDID_REPORT_EVT_V4 (0x001C) +#define APICMDID_REPORT_QUALITY_V4 (0x001D) +#define APICMDID_REPORT_CELLINFO_V4 (0x001E) +#define APICMDID_GET_EDRX_V4 (0x001F) +#define APICMDID_SET_EDRX_V4 (0x0020) +#define APICMDID_GET_PSM_V4 (0x0021) +#define APICMDID_SET_PSM_V4 (0x0022) +#define APICMDID_GET_CELLINFO_V4 (0x0024) +#define APICMDID_GET_QUALITY_V4 (0x0025) +#define APICMDID_GET_SIMINFO_V4 (0x0310) +#define APICMDID_POWER_ON_V4 (0x0311) +#define APICMDID_RADIO_ON_V4 (0x0312) +#define APICMDID_RADIO_OFF_V4 (0x0313) +#define APICMDID_ACTIVATE_PDN_V4 (0x0314) +#define APICMDID_ACTIVATE_PDN_CANCEL_V4 (0x0315) +#define APICMDID_DEACTIVATE_PDN_V4 (0x0316) +#define APICMDID_DATA_ALLOW_V4 (0x0317) +#define APICMDID_GET_NETINFO_V4 (0x0318) +#define APICMDID_GET_IMS_CAP_V4 (0x0319) +#define APICMDID_SETREP_NETINFO_V4 (0x031A) +#define APICMDID_REPORT_NETINFO_V4 (0x031B) +#define APICMDID_ERRINFO_V4 (0xFFFD) +#define APICMDID_GET_RAT_V4 (0x00A0) +#define APICMDID_SET_RAT_V4 (0x00A1) +#define APICMDID_SEND_ATCMD_V4 (0x0030) +#define APICMDID_URC_EVENT_V4 (0x0032) +#define APICMDID_FW_INJECTDELTAIMG_V4 (0x0270) +#define APICMDID_FW_GETDELTAIMGLEN_V4 (0x0271) +#define APICMDID_FW_EXECDELTAUPDATE_V4 (0x0272) +#define APICMDID_FW_GETUPDATERESULT_V4 (0x0273) +#define APICMDID_CLOGS_V4 (0x0300) +#define APICMDID_LOGLIST_V4 (0x0301) +#define APICMDID_LOGOPEN_V4 (0x0280) +#define APICMDID_LOGCLOSE_V4 (0x0281) +#define APICMDID_LOGREAD_V4 (0x0283) +#define APICMDID_LOGREMOVE_V4 (0x0284) +#define APICMDID_LOGLSEEK_V4 (0x0285) + +#define APICMDID_SOCK_ACCEPT (0x0080) +#define APICMDID_SOCK_BIND (0x0081) +#define APICMDID_SOCK_CLOSE (0x0082) +#define APICMDID_SOCK_CONNECT (0x0083) +#define APICMDID_SOCK_FCNTL (0x0084) +#define APICMDID_SOCK_GETADDRINFO (0x0085) +#define APICMDID_SOCK_GETHOSTBYNAME (0x0086) +#define APICMDID_SOCK_GETHOSTBYNAMER (0x0087) +#define APICMDID_SOCK_GETSOCKNAME (0x0088) +#define APICMDID_SOCK_GETSOCKOPT (0x0089) +#define APICMDID_SOCK_LISTEN (0x008A) +#define APICMDID_SOCK_RECV (0x008B) +#define APICMDID_SOCK_RECVFROM (0x008C) +#define APICMDID_SOCK_SELECT (0x008D) +#define APICMDID_SOCK_SEND (0x008E) +#define APICMDID_SOCK_SENDTO (0x008F) +#define APICMDID_SOCK_SHUTDOWN (0x0090) +#define APICMDID_SOCK_SOCKET (0x0091) +#define APICMDID_SOCK_SETSOCKOPT (0x0092) + +#define APICMDID_TLS_CONFIG_VERIFY_CALLBACK (0x0129) +#define APICMDID_TLS_CONFIG_VERIFY_CALLBACK_V4 (0x0161) + +#define APICMDID_SMS_INIT (0x0330) +#define APICMDID_SMS_FIN (0x0331) +#define APICMDID_SMS_SEND (0x0332) +#define APICMDID_SMS_REPORT_RECV (0x0333) +#define APICMDID_SMS_DELETE (0x0334) + +#define ALTCOM_CMDID_ERRIND (0xFFFF) + +#define ALTCOM_CMDID_REPLY_BIT (0x8000) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct alt_power_s +{ + uint32_t cmdid; +}; + +typedef struct alt_container_s +{ + sq_entry_t node; + int sock; + unsigned long priv; + uint32_t cmdid; + uint16_t altcid; + uint16_t alttid; + int result; + FAR void **inparam; + size_t inparamlen; + FAR void **outparam; + size_t outparamlen; +} alt_container_t; + +typedef enum alt_evtbuf_state_e +{ + ALTEVTBUF_ST_WRITABLE = 0, + ALTEVTBUF_ST_NOTWRITABLE = 1, +} alt_evtbuf_state_t; + +typedef struct alt_evtbuf_inst_s +{ + uint32_t cmdid; + uint16_t altcid; + FAR void **outparam; + size_t outparamlen; + sem_t stat_lock; + alt_evtbuf_state_t stat; +} alt_evtbuf_inst_t; + +struct alt_evtbuffer_s +{ + unsigned int ninst; + alt_evtbuf_inst_t *inst; +}; + +struct alt_readdata_s +{ + uint64_t evtbitmap; + FAR struct alt_container_s *head; +}; + +struct alt1250_lower_s +{ + FAR struct spi_dev_s * (*poweron)(void); + void (*poweroff)(void); + void (*reset)(void); + void (*irqattach)(xcpt_t handler); + void (*irqenable)(bool enable); + bool (*get_sready)(void); + void (*set_mready)(bool on); + void (*set_wakeup)(bool on); +}; + +struct altcom_fd_set_s +{ + unsigned char fd_bits[(ALTCOM_FD_SETSIZE + 7) / 8]; +}; + +typedef struct altcom_fd_set_s altcom_fd_set; + +struct alt_queue_s +{ + sq_queue_t queue; + sem_t lock; +}; + +struct alt1250_dev_s +{ + FAR struct spi_dev_s *spi; + FAR const struct alt1250_lower_s *lower; + sem_t refslock; + uint8_t crefs; + struct alt_queue_s waitlist; + struct alt_queue_s replylist; + uint64_t evtbitmap; + sem_t evtmaplock; + sem_t pfdlock; + FAR struct pollfd *pfd; + pthread_t recvthread; + FAR struct alt_evtbuffer_s *evtbuff; + uint32_t discardcnt; + sem_t senddisablelock; + bool senddisable; + FAR alt_container_t *select_container; + struct alt_evtbuf_inst_s select_inst; +}; + +typedef int32_t (*compose_handler_t)(FAR void **arg, size_t arglen, + uint8_t altver, FAR uint8_t *pktbuf, const size_t pktsz, + FAR uint16_t *altcid); +typedef int32_t (*parse_handler_t)(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, size_t pktsz, uint8_t altver, FAR void **arg, + size_t arglen, FAR uint64_t *bitmap); + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Name: alt1250_register + * + * Description: + * Register the ALT1250 character device as 'devpath'. + * + * Input Parameters: + * devpath - The full path to the driver to register. E.g., "/dev/alt1250". + * dev - An instance of the SPI interface to use to communicate with + * ALT1250. + * lower - An instance of the lower interface. + * + * Returned Value: + * Not NULL on success; NULL on failure. + * + ****************************************************************************/ + +FAR void *alt1250_register(FAR const char *devpath, + FAR struct spi_dev_s *dev, FAR const struct alt1250_lower_s *lower); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __INCLUDE_NUTTX_MODEM_ALT1250_H */ diff --git a/include/nuttx/modem/altmdm.h b/include/nuttx/modem/altmdm.h deleted file mode 100644 index e5f0b85c984..00000000000 --- a/include/nuttx/modem/altmdm.h +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** - * include/nuttx/modem/altmdm.h - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -#ifndef __INCLUDE_NUTTX_MODEM_ALTMDM_H -#define __INCLUDE_NUTTX_MODEM_ALTMDM_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include -#include -#include -#include -#include - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/* Debug ********************************************************************/ - -/* Non-standard debug that may be enabled just for testing the modem driver */ - -#ifdef CONFIG_MODEM_ALTMDM_DEBUG -# define m_err _err -# define m_info _info -#else -# define m_err(x...) -# define m_info(x...) -#endif - -#define MODEM_IOC_POWERON _MODEMIOC(1) -#define MODEM_IOC_POWEROFF _MODEMIOC(2) -#define MODEM_IOC_READABORT _MODEMIOC(3) -#define MODEM_IOC_SLEEP _MODEMIOC(4) -#define MODEM_IOC_PM_REGISTERCB _MODEMIOC(5) -#define MODEM_IOC_PM_DEREGISTERCB _MODEMIOC(6) -#define MODEM_IOC_PM_GETSTATE _MODEMIOC(7) -#define MODEM_IOC_PM_INITWAKELOCK _MODEMIOC(8) -#define MODEM_IOC_PM_ACQUIREWAKELOCK _MODEMIOC(9) -#define MODEM_IOC_PM_RELEASEWAKELOCK _MODEMIOC(10) -#define MODEM_IOC_PM_GETNUMOFWAKELOCK _MODEMIOC(11) -#define MODEM_IOC_PM_GETWAKELOCKSTATE _MODEMIOC(12) -#define MODEM_IOC_PM_ERR_REGISTERCB _MODEMIOC(13) -#define MODEM_IOC_PM_ERR_DEREGISTERCB _MODEMIOC(14) - -#define MODEM_PM_CB_TYPE_NORMAL 0 -#define MODEM_PM_CB_TYPE_ERROR 1 -#define MODEM_PM_STATE_SLEEP 0 -#define MODEM_PM_STATE_WAKE 1 -#define MODEM_PM_ERR_RESET_BOOTSTAT_NONE 0x00 -#define MODEM_PM_ERR_RESET_BOOTSTAT_BOOTING 0x01 -#define MODEM_PM_ERR_RESET_BOOTSTAT_UPDATING 0x02 -#define MODEM_PM_ERR_RESET_BOOTSTAT_DONE 0x10 - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -struct altmdm_pm_wakelock_s - { - sq_entry_t queue; - int count; - }; - -struct altmdm_lower_s -{ - void (*poweron)(void); - void (*poweroff)(void); - void (*sready_irqattach)(bool attach, xcpt_t handler); - void (*sready_irqenable)(bool enable); - bool (*sready)(void); - void (*master_request)(bool request); - void (*wakeup)(bool wakeup); - uint32_t (*spi_maxfreq)(void); -}; - -typedef void (*altmdm_pm_cbfunc_t) (uint32_t state); - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Name: altmdm_register - * - * Description: - * Register the ALTMDM character device as 'devpath'. - * - * Input Parameters: - * devpath - The full path to the driver to register. E.g., "/dev/altmdm". - * dev - An instance of the SPI interface to use to communicate with - * ALTMDM. - * lower - An instance of the lower interface. - * - * Returned Value: - * Not NULL on success; NULL on failure. - * - ****************************************************************************/ - -FAR void *altmdm_register(FAR const char *devpath, FAR struct spi_dev_s *dev, - FAR const struct altmdm_lower_s *lower); - -/**************************************************************************** - * Name: altmdm_unregister - * - * Description: - * Unregister the ALTMDM character device. - * - * Input Parameters: - * handle - The pointer that getting from altmdm_register. - * - * Returned Value: - * None. - * - ****************************************************************************/ - -void altmdm_unregister(FAR void *handle); - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* __INCLUDE_NUTTX_MODEM_ALTMDM_H */ diff --git a/include/nuttx/net/sms.h b/include/nuttx/net/sms.h new file mode 100644 index 00000000000..aeec9dab61c --- /dev/null +++ b/include/nuttx/net/sms.h @@ -0,0 +1,163 @@ +/**************************************************************************** + * include/nuttx/net/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 __INCLUDE_NUTTX_NET_SMS_H +#define __INCLUDE_NUTTX_NET_SMS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define SMS_MAX_ADDRLEN 16 /* 16 characters in USC2 format: 32byte */ +#define SMS_MAX_DATALEN 670 /* 670 characters in USC2 format: 1340byte */ + +#define SMS_MSG_TYPE_DELIVER 0 +#define SMS_MSG_TYPE_STATUS_REPORT 1 + +#define SMS_STATUS_SUCCESS 0 +#define SMS_STATUS_FAILED 1 +#define SMS_STATUS_PENDING 2 + +#define SMS_CHSET_UCS2 0 +#define SMS_CHSET_GSM7 1 +#define SMS_CHSET_BINARY 2 + +#define SMS_CONCATENATE_MAX 10 + +/* Nature of Address Indicator */ + +#define SMS_NAI_UNKNOWN 0x0 /* Unknown */ +#define SMS_NAI_INTERNATIONAL 0x1 /* International number */ +#define SMS_NAI_NATIONAL 0x2 /* National number */ +#define SMS_NAI_NETWORK_SPEC 0x3 /* Network specific number */ +#define SMS_NAI_SUBSCRIBER 0x4 /* Subscriber number */ +#define SMS_NAI_ALPANUMERIC 0x5 /* Alphanumeric */ +#define SMS_NAI_ABBREVIATED 0x6 /* Abbreviated number */ +#define SMS_NAI_RESERVED 0x7 /* Reserved for extension */ + +/* Numbering Plan Indicator */ + +#define SMS_NPI_UNKNOWN 0x0 /* Unknown */ +#define SMS_NPI_ISDN 0x1 /* ISDN/telephone numbering plan */ +#define SMS_NPI_DATA 0x3 /* Data numbering plan */ +#define SMS_NPI_TELEX 0x4 /* Telex numbering plan */ +#define SMS_NPI_SERVICE_CENTRE_SPEC 0x5 /* Service Centre Specific plan 1) */ +#define SMS_NPI_SERVICE_CENTRE_SPEC2 0x6 /* Service Centre Specific plan 1) */ +#define SMS_NPI_NATIONAL 0x8 /* National numbering plan */ +#define SMS_NPI_PRIVATE 0x9 /* Private numbering plan */ +#define SMS_NPI_ERMES 0xa /* ERMES numbering plan */ +#define SMS_NPI_RESERVED 0xf /* Reserved for extension */ + +#define SMS_NAI_SHIFT(a) ((a) << 4) +#define SMS_SET_TOA(a, p) (SMS_NAI_SHIFT(a) | (p)) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +struct sms_timestamp_s +{ + unsigned char year; /* Years (0-99) */ + unsigned char mon; /* Month (1-12) */ + unsigned char mday; /* Day of the month (1-31) */ + unsigned char hour; /* Hours (0-23) */ + unsigned char min; /* Minutes (0-59) */ + unsigned char sec; /* Seconds (0-59) */ + signed char tz; /* Time zone (-24-24) */ +}; + +/* This is the data structure used when sending SMS */ + +struct sms_send_msg_header_s +{ + unsigned char destaddrlen; + unsigned char reserve; + unsigned short datalen; + unsigned short destaddr[SMS_MAX_ADDRLEN]; +}; + +struct sms_send_msg_s +{ + struct sms_send_msg_header_s header; + + unsigned short data[0]; /* payload data in USC2 format */ +}; + +/* This is the data structure used when receiving SMS */ + +struct sms_recv_msg_header_s +{ + unsigned char msgtype; + struct sms_timestamp_s send_time; + unsigned char srcaddrlen; + unsigned char reserve; + unsigned short datalen; + unsigned short srcaddr[SMS_MAX_ADDRLEN]; +}; + +struct sms_deliver_msg_s +{ + struct sms_recv_msg_header_s header; + + unsigned short data[0]; /* payload data in USC2 format */ +}; + +struct sms_deliver_msg_max_s +{ + struct sms_recv_msg_header_s header; + + unsigned short data[SMS_MAX_DATALEN]; /* payload data in USC2 format */ +}; + +struct sms_status_report_s +{ + unsigned char refid; + unsigned char status; + unsigned char reserve; + struct sms_timestamp_s discharge_time; +}; + +struct sms_status_report_msg_s +{ + struct sms_recv_msg_header_s header; + + struct sms_status_report_s status_report; +}; + +struct sms_refids_s +{ + unsigned char nrefid; + unsigned char refid[SMS_CONCATENATE_MAX]; +}; + +struct sms_sc_addr_s +{ + unsigned char toa; + unsigned char addrlen; + unsigned short addr[SMS_MAX_ADDRLEN]; +}; + +#endif /* __INCLUDE_NUTTX_NET_SMS_H */ diff --git a/include/nuttx/wireless/lte/lte.h b/include/nuttx/wireless/lte/lte.h new file mode 100644 index 00000000000..16afa46473f --- /dev/null +++ b/include/nuttx/wireless/lte/lte.h @@ -0,0 +1,2045 @@ +/**************************************************************************** + * include/nuttx/wireless/lte/lte.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_WIRELESS_LTE_LTE_H +#define __INCLUDE_NUTTX_WIRELESS_LTE_LTE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define LTE_RESULT_OK (0) /* Result code on success */ +#define LTE_RESULT_ERROR (1) /* Result code on failure */ +#define LTE_RESULT_CANCEL (2) /* Result code on cancel */ + +#define LTE_VALID (true) /* Valid */ +#define LTE_INVALID (false) /* Invalid */ + +#define LTE_ENABLE (true) /* Enable */ +#define LTE_DISABLE (false) /* Disable */ + +#define LTE_ERR_WAITENTERPIN (1) /* Waiting for PIN enter */ +#define LTE_ERR_REJECT (2) /* Rejected from the network */ +#define LTE_ERR_MAXRETRY (3) /* No response from the network */ +#define LTE_ERR_BARRING (4) /* Network barring */ +#define LTE_ERR_DETACHED (5) /* Network detached */ +#define LTE_ERR_UNEXPECTED (255) /* Unexpected cause */ + +#define LTE_SESSION_ID_MIN (1) /* Minimum value of session ID */ +#define LTE_SESSION_ID_MAX (5) /* Maximum value of session ID */ + +/* Network status: Not registered, MT is not currently searching + * a new operator to register to + */ + +#define LTE_NETSTAT_NOT_REG_NOT_SEARCHING (0) + +/* Network status: Registered, home network */ + +#define LTE_NETSTAT_REG_HOME (1) + +/* Network status: Not registered, but MT is currently searching + * a new operator to register to + */ + +#define LTE_NETSTAT_NOT_REG_SEARCHING (2) + +/* Network status: Registration denied */ + +#define LTE_NETSTAT_REG_DENIED (3) + +/* Network status: Unknown */ + +#define LTE_NETSTAT_UNKNOWN (4) + +/* Network status: Registered, roaming */ + +#define LTE_NETSTAT_REG_ROAMING (5) + +/* Network status: Registered for "SMS only", home network */ + +#define LTE_NETSTAT_REG_SMS_ONLY_HOME (6) + +/* Network status: Registered for "SMS only", roaming */ + +#define LTE_NETSTAT_REG_SMS_ONLY_ROAMING (7) + +/* Network status: Attached for emergency bearer services only */ + +#define LTE_NETSTAT_NOT_REG_EMERGENCY (8) + +/* Network status: Registered for "CSFB not preferred", home network */ + +#define LTE_NETSTAT_REG_CSFB_NOT_PREF_HOME (9) + +/* Network status: Registered for "CSFB not preferred", roaming */ + +#define LTE_NETSTAT_REG_CSFB_NOT_PREF_ROAMING (10) + +/* The maximum string length of the APN name */ + +#define LTE_APN_LEN (101) + +/* The maximum string length of the APN user name */ + +#define LTE_APN_USER_NAME_LEN (64) + +/* The maximum string length of the APN password */ + +#define LTE_APN_PASSWD_LEN (32) + +#define LTE_IPTYPE_V4 (0) /* Internet protocol type: IPv4 */ +#define LTE_IPTYPE_V6 (1) /* Internet protocol type: IPv6 */ +#define LTE_IPTYPE_V4V6 (2) /* Internet protocol type: IPv4/v6 */ +#define LTE_IPTYPE_NON (3) /* Internet protocol type: + * Non-IP Data Delivery + */ + +/* Internet protocol type: IP + * deprecated. Use LTE_IPTYPE_V4 instead. + */ + +#define LTE_APN_IPTYPE_IP LTE_IPTYPE_V4 + +/* Internet protocol type: IPv6 + * deprecated. Use LTE_IPTYPE_V6 instead. + */ + +#define LTE_APN_IPTYPE_IPV6 LTE_IPTYPE_V6 + +/* Internet protocol type: IPv4/v6 + * deprecated. Use LTE_IPTYPE_V4V6 instead. + */ + +#define LTE_APN_IPTYPE_IPV4V6 LTE_IPTYPE_V4V6 + +#define LTE_APN_AUTHTYPE_NONE (0) /* PPP authentication type: NONE */ +#define LTE_APN_AUTHTYPE_PAP (1) /* PPP authentication type: PAP */ +#define LTE_APN_AUTHTYPE_CHAP (2) /* PPP authentication type: CHAP */ + +/* APN type: Unknown */ + +#define LTE_APN_TYPE_UNKNOWN (0x01) + +/* APN type: Default data traffic */ + +#define LTE_APN_TYPE_DEFAULT (0x02) + +/* APN type: MMS traffic(Multimedia Messaging Service) */ + +#define LTE_APN_TYPE_MMS (0x04) + +/* APN type: SUPL assisted GPS */ + +#define LTE_APN_TYPE_SUPL (0x08) + +/* APN type: DUN traffic(Dial Up Networking bridge ) */ + +#define LTE_APN_TYPE_DUN (0x10) + +/* APN type: HiPri traffic(High Priority Mobile data) */ + +#define LTE_APN_TYPE_HIPRI (0x20) + +/* APN type: FOTA(Firmware On The Air) */ + +#define LTE_APN_TYPE_FOTA (0x40) + +/* APN type: IMS(IP Multimedia Subsystem) */ + +#define LTE_APN_TYPE_IMS (0x80) + +/* APN type: CBS(Carrier Branded Services) */ + +#define LTE_APN_TYPE_CBS (0x100) + +/* APN type: IA(Initial Attach APN) */ + +#define LTE_APN_TYPE_IA (0x200) + +/* APN type: Emergency PDN */ + +#define LTE_APN_TYPE_EMERGENCY (0x400) + +/* Network error type: MAX_RETRY */ + +#define LTE_NETERR_MAXRETRY (0) + +/* Network error type: REJECT */ + +#define LTE_NETERR_REJECT (1) + +/* Network error type: Network Detach */ + +#define LTE_NETERR_NWDTCH (2) + +/* Network reject category: NAS-EMM */ + +#define LTE_REJECT_CATEGORY_EMM (0) + +/* Network reject category: NAS-ESM */ + +#define LTE_REJECT_CATEGORY_ESM (1) + +/* Length of character string for BB product */ + +#define LTE_VER_BB_PRODUCT_LEN (5) + +/* Length of character string for NP package */ + +#define LTE_VER_NP_PACKAGE_LEN (32) + +/* Enable setting of PIN lock + * deprecated. Use LTE_ENABLE instead. + */ + +#define LTE_PIN_ENABLE LTE_ENABLE + +/* Disable setting of PIN lock + * deprecated. Use LTE_DISABLE instead. + */ + +#define LTE_PIN_DISABLE LTE_DISABLE + +/* PIN status: Not pending for any password */ + +#define LTE_PINSTAT_READY (0) + +/* PIN status: Waiting SIM PIN to be given */ + +#define LTE_PINSTAT_SIM_PIN (1) + +/* PIN status: Waiting SIM PUK to be given */ + +#define LTE_PINSTAT_SIM_PUK (2) + +/* PIN status: Waiting phone to SIM card password to be given */ + +#define LTE_PINSTAT_PH_SIM_PIN (3) + +/* PIN status: Waiting phone-to-very first SIM card password to be given */ + +#define LTE_PINSTAT_PH_FSIM_PIN (4) + +/* PIN status: Waiting phone-to-very first SIM card unblocking + * password to be given + */ + +#define LTE_PINSTAT_PH_FSIM_PUK (5) + +/* PIN status: Waiting SIM PIN2 to be given */ + +#define LTE_PINSTAT_SIM_PIN2 (6) + +/* PIN status: Waiting SIM PUK2 to be given */ + +#define LTE_PINSTAT_SIM_PUK2 (7) + +/* PIN status: Waiting network personalization password to be given */ + +#define LTE_PINSTAT_PH_NET_PIN (8) + +/* PIN status: Waiting network personalization unblocking password + * to be given + */ + +#define LTE_PINSTAT_PH_NET_PUK (9) + +/* PIN status: Waiting network subset personalization password to be given */ + +#define LTE_PINSTAT_PH_NETSUB_PIN (10) + +/* PIN status: Waiting network subset personalization unblocking password + * to be given + */ + +#define LTE_PINSTAT_PH_NETSUB_PUK (11) + +/* PIN status: Waiting service provider personalization password + * to be given + */ + +#define LTE_PINSTAT_PH_SP_PIN (12) + +/* PIN status: Waiting service provider personalization unblocking password + * to be given + */ + +#define LTE_PINSTAT_PH_SP_PUK (13) + +/* PIN status: Waiting corporate personalization password to be given */ + +#define LTE_PINSTAT_PH_CORP_PIN (14) + +/* PIN status: Waiting corporate personalization unblocking password + * to be given + */ + +#define LTE_PINSTAT_PH_CORP_PUK (15) + +#define LTE_TARGET_PIN (0) /* Select of PIN change */ +#define LTE_TARGET_PIN2 (1) /* Select of PIN2 change */ + +/* SIM status: SIM removal signal detected */ + +#define LTE_SIMSTAT_REMOVAL (0) + +/* SIM status: SIM insertion signal detected */ + +#define LTE_SIMSTAT_INSERTION (1) + +/* SIM status: SIM init passed, wait for PIN unlock */ + +#define LTE_SIMSTAT_WAIT_PIN_UNLOCK (2) + +/* SIM status: Personalization failed, wait for run-time depersonalization */ + +#define LTE_SIMSTAT_PERSONAL_FAILED (3) + +/* SIM status: Activation completed. Event is sent always + * at any SIM activation completion + */ + +#define LTE_SIMSTAT_ACTIVATE (4) + +/* SIM status: SIM is deactivated */ + +#define LTE_SIMSTAT_DEACTIVATE (5) + +#define LTE_MCC_DIGIT (3) /* Digit number of Mobile Country Code */ +#define LTE_MNC_DIGIT_MAX (3) /* Max digit number of Mobile Network Code */ + +/* Digit number of mcc + * deprecated. Use LTE_MCC_DIGIT instead. + */ + +#define LTE_CELLINFO_MCC_DIGIT LTE_MCC_DIGIT + +/* Max digit number of mnc + * deprecated. Use LTE_MNC_DIGIT_MAX instead. + */ + +#define LTE_CELLINFO_MNC_DIGIT_MAX LTE_MNC_DIGIT_MAX + +#define LTE_EDRX_ACTTYPE_WBS1 (0) /* E-UTRAN (WB-S1 mode) */ +#define LTE_EDRX_ACTTYPE_NBS1 (1) /* E-UTRAN (NB-S1 mode) */ +#define LTE_EDRX_ACTTYPE_ECGSMIOT (2) /* EC-GSM-IoT (A/Gb mode) */ +#define LTE_EDRX_ACTTYPE_GSM (3) /* GSM (A/Gb mode) */ +#define LTE_EDRX_ACTTYPE_IU (4) /* UTRAN (Iu mode) */ +#define LTE_EDRX_ACTTYPE_NOTUSE (5) /* eDRX is not running */ + +#define LTE_EDRX_CYC_512 (0) /* eDRX cycle: 5.12 sec */ +#define LTE_EDRX_CYC_1024 (1) /* eDRX cycle: 10.24 sec */ +#define LTE_EDRX_CYC_2048 (2) /* eDRX cycle: 20.48 sec */ +#define LTE_EDRX_CYC_4096 (3) /* eDRX cycle: 40.96 sec */ +#define LTE_EDRX_CYC_6144 (4) /* eDRX cycle: 61.44 sec */ +#define LTE_EDRX_CYC_8192 (5) /* eDRX cycle: 81.92 sec */ +#define LTE_EDRX_CYC_10240 (6) /* eDRX cycle: 102.40 sec */ +#define LTE_EDRX_CYC_12288 (7) /* eDRX cycle: 122.88 sec */ +#define LTE_EDRX_CYC_14336 (8) /* eDRX cycle: 143.36 sec */ +#define LTE_EDRX_CYC_16384 (9) /* eDRX cycle: 163.84 sec */ +#define LTE_EDRX_CYC_32768 (10) /* eDRX cycle: 327.68 sec */ +#define LTE_EDRX_CYC_65536 (11) /* eDRX cycle: 655.36 sec */ +#define LTE_EDRX_CYC_131072 (12) /* eDRX cycle: 1310.72 sec */ +#define LTE_EDRX_CYC_262144 (13) /* eDRX cycle: 2621.44 sec */ +#define LTE_EDRX_CYC_524288 (14) /* eDRX cycle: 5242.88 sec */ +#define LTE_EDRX_CYC_1048576 (15) /* eDRX cycle: 10485.76 sec */ +#define LTE_EDRX_PTW_128 (0) /* Paging time window: 1.28 sec */ +#define LTE_EDRX_PTW_256 (1) /* Paging time window: 2.56 sec */ +#define LTE_EDRX_PTW_384 (2) /* Paging time window: 3.84 sec */ +#define LTE_EDRX_PTW_512 (3) /* Paging time window: 5.12 sec */ +#define LTE_EDRX_PTW_640 (4) /* Paging time window: 6.40 sec */ +#define LTE_EDRX_PTW_768 (5) /* Paging time window: 7.68 sec */ +#define LTE_EDRX_PTW_896 (6) /* Paging time window: 8.96 sec */ +#define LTE_EDRX_PTW_1024 (7) /* Paging time window: 10.24 sec */ +#define LTE_EDRX_PTW_1152 (8) /* Paging time window: 11.52 sec */ +#define LTE_EDRX_PTW_1280 (9) /* Paging time window: 12.80 sec */ +#define LTE_EDRX_PTW_1408 (10) /* Paging time window: 14.08 sec */ +#define LTE_EDRX_PTW_1536 (11) /* Paging time window: 15.36 sec */ +#define LTE_EDRX_PTW_1664 (12) /* Paging time window: 16.64 sec */ +#define LTE_EDRX_PTW_1792 (13) /* Paging time window: 17.92 sec */ +#define LTE_EDRX_PTW_1920 (14) /* Paging time window: 19.20 sec */ +#define LTE_EDRX_PTW_2048 (15) /* Paging time window: 20.48 sec */ +#define LTE_EDRX_PTW_2304 (16) /* Paging time window: 23.04 sec */ +#define LTE_EDRX_PTW_2560 (17) /* Paging time window: 25.60 sec */ +#define LTE_EDRX_PTW_2816 (18) /* Paging time window: 28.16 sec */ +#define LTE_EDRX_PTW_3072 (19) /* Paging time window: 30.72 sec */ +#define LTE_EDRX_PTW_3328 (20) /* Paging time window: 33.28 sec */ +#define LTE_EDRX_PTW_3584 (21) /* Paging time window: 35.84 sec */ +#define LTE_EDRX_PTW_3840 (22) /* Paging time window: 38.40 sec */ +#define LTE_EDRX_PTW_4096 (23) /* Paging time window: 40.96 sec */ + +/* Unit of request active time(T3324): 2 sec */ + +#define LTE_PSM_T3324_UNIT_2SEC (0) + +/* Unit of request active time(T3324): 1 min */ + +#define LTE_PSM_T3324_UNIT_1MIN (1) + +/* Unit of request active time(T3324): 6 min */ + +#define LTE_PSM_T3324_UNIT_6MIN (2) + +/* Unit of request active time(T3324): The value indicates that + * the timer is deactivated. + */ + +#define LTE_PSM_T3324_UNIT_DEACT (3) + +/* Unit of extended periodic TAU time(T3412): 2 sec */ + +#define LTE_PSM_T3412_UNIT_2SEC (0) + +/* Unit of extended periodic TAU time(T3412): 30 sec */ + +#define LTE_PSM_T3412_UNIT_30SEC (1) + +/* Unit of extended periodic TAU time(T3412): 1 min */ + +#define LTE_PSM_T3412_UNIT_1MIN (2) + +/* Unit of extended periodic TAU time(T3412): 10 min */ + +#define LTE_PSM_T3412_UNIT_10MIN (3) + +/* Unit of extended periodic TAU time(T3412): 1 hour */ + +#define LTE_PSM_T3412_UNIT_1HOUR (4) + +/* Unit of extended periodic TAU time(T3412): 10 hour */ + +#define LTE_PSM_T3412_UNIT_10HOUR (5) + +/* Unit of extended periodic TAU time(T3412): 320 hour */ + +#define LTE_PSM_T3412_UNIT_320HOUR (6) + +/* Unit of extended periodic TAU time(T3412): The value indicates that + * the timer is deactivated. + */ + +#define LTE_PSM_T3412_UNIT_DEACT (7) + +/* The minimum timer value used by PSM related timers */ + +#define LTE_PSM_TIMEVAL_MIN (0) + +/* The maximum timer value used by PSM related timers */ + +#define LTE_PSM_TIMEVAL_MAX (31) + +#define LTE_IPADDR_MAX_LEN (40) /* Maximum length of the IP address */ + +/* Invalid Session ID */ + +#define LTE_PDN_SESSIONID_INVALID_ID (0) + +/* Minimum value of Session ID */ + +#define LTE_PDN_SESSIONID_MIN (LTE_PDN_SESSIONID_INVALID_ID) + +/* Maximum value of Session ID */ + +#define LTE_PDN_SESSIONID_MAX (255) + +#define LTE_PDN_DEACTIVE (0) /* PDN status: Not active */ +#define LTE_PDN_ACTIVE (1) /* PDN status: Active */ + +#define LTE_PDN_IPADDR_MAX_COUNT (2) /* Maximum number of IP addresses */ + +#define LTE_IMS_NOT_REGISTERED (0) /* IMS status: Not registered */ +#define LTE_IMS_REGISTERED (1) /* IMS status: Registered */ +#define LTE_DATA_DISALLOW (0) /* Data communication: Not allow */ +#define LTE_DATA_ALLOW (1) /* Data communication: Allow */ + +/* Modem restart cause: User initiated */ + +#define LTE_RESTART_USER_INITIATED (0) + +/* Modem restart cause: Modem initiated */ + +#define LTE_RESTART_MODEM_INITIATED (1) + +/* Error indicator for error code */ + +#define LTE_ERR_INDICATOR_ERRCODE (0x01) + +/* Error indicator for error number */ + +#define LTE_ERR_INDICATOR_ERRNO (0x02) + +/* Error indicator for error string */ + +#define LTE_ERR_INDICATOR_ERRSTR (0x04) + +/* Maximum length of the error string */ + +#define LTE_ERROR_STRING_MAX_LEN (64) + +/* Indicates to get for Mobile Country Code/Mobile Network Code of SIM */ + +#define LTE_SIMINFO_GETOPT_MCCMNC (1 << 0) + +/* Indicates to get for SPN of SIM */ + +#define LTE_SIMINFO_GETOPT_SPN (1 << 1) + +/* Indicates to get for ICCID of SIM */ + +#define LTE_SIMINFO_GETOPT_ICCID (1 << 2) + +/* Indicates to get for IMSI of SIM */ + +#define LTE_SIMINFO_GETOPT_IMSI (1 << 3) + +/* Indicates to get for GID1(Group Identifier Level 1) of SIM */ + +#define LTE_SIMINFO_GETOPT_GID1 (1 << 4) + +/* Indicates to get for GID2(Group Identifier Level 2) of SIM */ + +#define LTE_SIMINFO_GETOPT_GID2 (1 << 5) + +/* Digit number of mcc + * deprecated. Use LTE_MCC_DIGIT instead. + */ + +#define LTE_SIMINFO_MCC_DIGIT LTE_MCC_DIGIT + +/* Max digit number of mnc + * deprecated. Use LTE_MNC_DIGIT_MAX instead. + */ + +#define LTE_SIMINFO_MNC_DIGIT_MAX LTE_MNC_DIGIT_MAX + +#define LTE_SIMINFO_SPN_LEN (16) /* Maximum length of SPN */ +#define LTE_SIMINFO_ICCID_LEN (10) /* Maximum length of ICCCID */ +#define LTE_SIMINFO_IMSI_LEN (15) /* Maximum length of IMSI */ +#define LTE_SIMINFO_GID_LEN (128) /* Maximum length of GID */ + +/* Maximum length of phone number + * that includes a null terminater + */ + +#define LTE_PHONENO_LEN (41) + +/* Maximum length of IMEI + * that includes a null terminater + */ + +#define LTE_IMEI_LEN (16) + +/* Maximum length of network operator + * that includes a null terminater + */ + +#define LTE_OPERATOR_LEN (17) + +/* Maximum length of IMSI + * that includes a null terminater + */ + +#define LTE_IMSI_LEN (LTE_SIMINFO_IMSI_LEN + 1) + +/* Indicates that the global cell ID can be referenced */ + +#define LTE_CELLINFO_OPT_GCID (1 << 0) + +/* Indicates that the tracking area code can be referenced */ + +#define LTE_CELLINFO_OPT_AREACODE (1 << 1) + +/* Indicates that the sub frame number can be referenced */ + +#define LTE_CELLINFO_OPT_SFN (1 << 2) + +/* Indicates that the RSRP can be referenced */ + +#define LTE_CELLINFO_OPT_RSRP (1 << 3) + +/* Indicates that the RSRQ can be referenced */ + +#define LTE_CELLINFO_OPT_RSRQ (1 << 4) + +/* Indicates that the time difference index can be referenced */ + +#define LTE_CELLINFO_OPT_TIMEDIFFIDX (1 << 5) + +/* Indicates that the timing advance can be referenced */ + +#define LTE_CELLINFO_OPT_TA (1 << 6) + +/* Indicates that the neighbor cell can be referenced */ + +#define LTE_CELLINFO_OPT_NEIGHBOR (1 << 7) + +#define LTE_NEIGHBOR_CELL_MAX (32) /* Maximum number of neighbor cells */ + +#define LTE_RAT_CATM (2) /* RAT type: Cat-M */ +#define LTE_RAT_NBIOT (3) /* RAT type: NB-IoT */ + +#define LTE_RAT_MODE_SINGLE (0) /* Modem only supports single RAT */ +#define LTE_RAT_MODE_MULTIPLE (1) /* Modem supports multiple RAT */ + +/* RAT has not changed since the last modem boot. */ + +#define LTE_RAT_SOURCE_DEFAULT (0) + +/* The current RAT was determined by host. */ + +#define LTE_RAT_SOURCE_HOST (1) + +/* The current RAT was determined by LWM2M. */ + +#define LTE_RAT_SOURCE_LWM2M (2) + +/* Maximum length of AT command */ + +#define LTE_AT_COMMAND_MAX_LEN (2048) + +/* Inject delta image from the beginning. */ + +#define LTEFW_INJECTION_MODE_NEW (0) + +/* Inject delta image from the continuation. */ + +#define LTEFW_INJECTION_MODE_APPEND (1) + +/* LTEFW result code */ + +/* OK */ + +#define LTEFW_RESULT_OK (0x0000) + +/* Not enough space for storage for injection */ + +#define LTEFW_RESULT_NOT_ENOUGH_INJECTSTORAGE (-1) + +/* CRC check error in header part of delta image */ + +#define LTEFW_RESULT_DELTAIMAGE_HDR_CRC_ERROR (-2) + +/* Unsupported header type of delta image */ + +#define LTEFW_RESULT_DELTAIMAGE_HDR_UNSUPPORTED (-3) + +/* Failed to set delta image */ + +#define LTEFW_RESULT_PRECHK_SET_DELTAIMAGE_FAILED (-4) + +/* Failed to delta update */ + +#define LTEFW_RESULT_DELTAUPDATE_FAILED (-5) + +/* Not found delta image */ + +#define LTEFW_RESULT_PRECHK_DELTAIMAGE_MISSING (-6) + +/* Out of memory that prepare for update */ + +#define LTEFW_RESULT_PRECHK_OOM (-7) + +/* Invalid size of delta image */ + +#define LTEFW_RESULT_PRECHK_SIZE_ERROR (-8) + +/* Wrong delta image package */ + +#define LTEFW_RESULT_PRECHK_PKG_ERROR (-9) + +/* CRC check error in delta image */ + +#define LTEFW_RESULT_PRECHK_CRC_ERROR (-10) + +/* There is no update result */ + +#define LTEFW_RESULT_DELTAUPDATE_NORESULT (-11) + +/* Length of LTE modem log file name */ + +#define LTE_LOG_NAME_LEN 32 + +/* Number of LTE modem logs saved */ + +#define LTE_LOG_LIST_SIZE 3 + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* Definition of version information of the modem. + * This is notified by get_ver_cb_t + */ + +typedef struct lte_version +{ + /* BB product version. It is terminated with '\0'. */ + + char bb_product[LTE_VER_BB_PRODUCT_LEN]; + + /* NP package version. It is terminated with '\0'. */ + + char np_package[LTE_VER_NP_PACKAGE_LEN]; +} lte_version_t; + +/* Definition of PIN setting information. + * This is notified by get_pinset_cb_t + */ + +typedef struct lte_getpin +{ + /* PIN enable. Definition is as below. + * - LTE_ENABLE + * - LTE_DISABLE + */ + + uint8_t enable; + + /* PIN status. Refer to the this parameter only + * when enable is @ref LTE_ENABLE. + */ + + uint8_t status; + + /* PIN attempts left */ + + uint8_t pin_attemptsleft; + + /* PUK attempts left */ + + uint8_t puk_attemptsleft; + + /* PIN2 attempts left */ + + uint8_t pin2_attemptsleft; + + /* PUK2 attempts left */ + + uint8_t puk2_attemptsleft; +} lte_getpin_t; + +/* Definition of local time. This is notified by + * get_localtime_cb_t and localtime_report_cb_t + */ + +typedef struct lte_localtime +{ + int32_t year; /* Years (0-99) */ + int32_t mon; /* Month (1-12) */ + int32_t mday; /* Day of the month (1-31) */ + int32_t hour; /* Hours (0-23) */ + int32_t min; /* Minutes (0-59) */ + int32_t sec; /* Seconds (0-59) */ + int32_t tz_sec; /* Time zone in seconds (-86400-86400) */ +} lte_localtime_t; + +/* Definition of parameters for quality information. + * This is reported by quality_report_cb_t + * and notified by get_quality_cb_t + */ + +typedef struct lte_quality +{ + /* Valid flag. Definition is as below. + * - LTE_VALID + * - LTE_INVALID + * + * Refer to the following parameters only when this flag + * is LTE_VALID. This is because valid parameters can not be + * acquired when RF function is OFF and so on + */ + + bool valid; + + /* RSRP in dBm (-140-0) */ + + int16_t rsrp; + + /* RSRQ in dBm (-60-0) */ + + int16_t rsrq; + + /* SINR in dBm (-128-40) */ + + int16_t sinr; + + /* RSSI in dBm */ + + int16_t rssi; +} lte_quality_t; + +/* Definition of parameters for neighbor cell information. + * This is reported by cellinfo_report_cb_t + */ + +typedef struct lte_neighbor_cell +{ + /* Indicates which parameters can be referenced. + * Bit setting definition is as below. + * - LTE_CELLINFO_OPT_SFN + * - LTE_CELLINFO_OPT_RSRP + * - LTE_CELLINFO_OPT_RSRQ + */ + + uint8_t option; + + /* Physical cell ID (1-503) */ + + uint32_t phycell_id; + + /* EARFCN (1-262143) */ + + uint32_t earfcn; + + /* Sub Frame Number (0-1023). It can be referenced when + * LTE_CELLINFO_OPT_SFN is set in option field. + */ + + uint16_t sfn; + + /* RSRP in dBm (-140-0). It can be referenced when + * LTE_CELLINFO_OPT_RSRP is set in option field. + */ + + int16_t rsrp; + + /* RSRQ in dBm (-60-0). It can be referenced when + * LTE_CELLINFO_OPT_RSRQ is set in option field. + */ + + int16_t rsrq; +} lte_neighbor_cell_t; + +/* Definition of parameters for cell information. + * This is reported by cellinfo_report_cb_t + */ + +typedef struct lte_cellinfo +{ + /* Valid flag. Definition is as below. + * - LTE_VALID + * - LTE_INVALID + * + * Refer to the following parameters only when this flag + * is LTE_VALID. This is because valid parameters can not be + * acquired when RF function is OFF and so on + */ + + bool valid; + + /* Physical cell ID (1-503) */ + + uint32_t phycell_id; + + /* EARFCN (1-262143) */ + + uint32_t earfcn; + + /* Mobile Country Code (000-999) */ + + uint8_t mcc[LTE_MCC_DIGIT]; + + /* Digit number of Mobile Network Code(2-3) */ + + uint8_t mnc_digit; + + /* Mobile Network Code (00-999) */ + + uint8_t mnc[LTE_MNC_DIGIT_MAX]; + + /* Indicates which parameters can be referenced. + * Bit setting definition is as below. + * - LTE_CELLINFO_OPT_GCID + * - LTE_CELLINFO_OPT_AREACODE + * - LTE_CELLINFO_OPT_SFN + * - LTE_CELLINFO_OPT_RSRP + * - LTE_CELLINFO_OPT_RSRQ + * - LTE_CELLINFO_OPT_TIMEDIFFIDX + * - LTE_CELLINFO_OPT_TA + * - LTE_CELLINFO_OPT_NEIGHBOR + */ + + uint8_t option; + + /* Global Cell ID. It can be referenced when + * LTE_CELLINFO_OPT_GCID is set in option field. + */ + + uint32_t gcid; + + /* Tracking Area Code (1-65535). It can be referenced when + * LTE_CELLINFO_OPT_AREACODE is set in option field. + */ + + uint16_t area_code; + + /* Sub Frame Number (0-1023). It can be referenced when + * LTE_CELLINFO_OPT_SFN is set in option field. + */ + + uint16_t sfn; + + /* RSRP in dBm (-140-0). It can be referenced when + * LTE_CELLINFO_OPT_RSRP is set in option field. + */ + + int16_t rsrp; + + /* RSRQ in dBm (-60-0). It can be referenced when + * LTE_CELLINFO_OPT_RSRQ is set in option field. + */ + + int16_t rsrq; + + /* Time difference index (0-4095). It can be referenced when + * LTE_CELLINFO_OPT_TIMEDIFFIDX is set in option field. + */ + + uint16_t time_diffidx; + + /* Timing Advance (0-1282). It can be referenced when + * LTE_CELLINFO_OPT_TA is set in option field. + */ + + uint16_t ta; + + /* Number of neighbor cells (0-32). It can be referenced when + * LTE_CELLINFO_OPT_NEIGHBOR is set in option field. + * + * When using lte_get_cellinfo_sync, need to specify the number + * of neighbor cells to get. Then, prepare a memory area for + * the specified number of neighbor cells and set it to + * neighbors. + */ + + uint8_t nr_neighbor; + + /* Pointer to neighbor cells. It can be referenced when + * LTE_CELLINFO_OPT_NEIGHBOR is set in option field. + * + * When using the lte_get_cellinfo_sync, prepare a memory + * area for the specified number of neighbor cells. + */ + + lte_neighbor_cell_t *neighbors; +} lte_cellinfo_t; + +/* Definition of eDRX settings used in lte_set_edrx(). + * This is notified by get_edrx_cb_t + */ + +typedef struct lte_edrx_setting +{ + /* eDRX act type. Definition is as below. + * - LTE_EDRX_ACTTYPE_WBS1 + * - LTE_EDRX_ACTTYPE_NBS1 + * - LTE_EDRX_ACTTYPE_ECGSMIOT + * - LTE_EDRX_ACTTYPE_GSM + * - LTE_EDRX_ACTTYPE_IU + * - LTE_EDRX_ACTTYPE_NOTUSE + */ + + uint8_t act_type; + + /* eDRX enable. Definition is as below. + * - LTE_ENABLE + * - LTE_DISABLE + */ + + bool enable; + + /* eDRX cycle. + * This variable is not vaild when LTE_EDRX_ACTTYPE_NOTUSE + * is set to act_type. + * Definitions are below: + * - LTE_EDRX_CYC_512 + * - LTE_EDRX_CYC_1024 + * - LTE_EDRX_CYC_2048 + * - LTE_EDRX_CYC_4096 + * - LTE_EDRX_CYC_6144 + * - LTE_EDRX_CYC_8192 + * - LTE_EDRX_CYC_10240 + * - LTE_EDRX_CYC_12288 + * - LTE_EDRX_CYC_14336 + * - LTE_EDRX_CYC_16384 + * - LTE_EDRX_CYC_32768 + * - LTE_EDRX_CYC_65536 + * - LTE_EDRX_CYC_131072 + * - LTE_EDRX_CYC_262144 + */ + + uint32_t edrx_cycle; + + /* Paging time window. + * This variable is not vaild when LTE_EDRX_ACTTYPE_NOTUSE + * is set to act_type. + * Definitions are below: + * - LTE_EDRX_PTW_128 + * - LTE_EDRX_PTW_256 + * - LTE_EDRX_PTW_384 + * - LTE_EDRX_PTW_512 + * - LTE_EDRX_PTW_640 + * - LTE_EDRX_PTW_768 + * - LTE_EDRX_PTW_896 + * - LTE_EDRX_PTW_1024 + * - LTE_EDRX_PTW_1152 + * - LTE_EDRX_PTW_1280 + * - LTE_EDRX_PTW_1408 + * - LTE_EDRX_PTW_1536 + * - LTE_EDRX_PTW_1664 + * - LTE_EDRX_PTW_1792 + * - LTE_EDRX_PTW_1920 + * - LTE_EDRX_PTW_2048 + */ + + uint32_t ptw_val; +} lte_edrx_setting_t; + +/* Definition of timer information for PSM + */ + +typedef struct lte_psm_timeval +{ + /* Unit of timer value. Definition is as below. + * - When kind of timer is Requested Active Time + * - LTE_PSM_T3324_UNIT_2SEC + * - LTE_PSM_T3324_UNIT_1MIN + * - LTE_PSM_T3324_UNIT_6MIN + * - LTE_PSM_T3324_UNIT_DEACT + * + * - When kind of timer is Extended periodic TAU Time + * - LTE_PSM_T3412_UNIT_2SEC + * - LTE_PSM_T3412_UNIT_30SEC + * - LTE_PSM_T3412_UNIT_1MIN + * - LTE_PSM_T3412_UNIT_10MIN + * - LTE_PSM_T3412_UNIT_1HOUR + * - LTE_PSM_T3412_UNIT_10HOUR + * - LTE_PSM_T3412_UNIT_320HOUR + * - LTE_PSM_T3412_UNIT_DEACT + */ + + uint8_t unit; + + /* Timer value (0-31) */ + + uint8_t time_val; +} lte_psm_timeval_t; + +/* Definition of PSM settings used in lte_set_psm(). + * This is notified by get_psm_cb_t + */ + +typedef struct lte_psm_setting +{ + /* PSM enable. Definition is as below. + * - LTE_ENABLE + * - LTE_DISABLE + */ + + bool enable; + + /* Requested Active Time value(T3324). See lte_psm_timeval_t */ + + lte_psm_timeval_t req_active_time; + + /* Extended periodic TAU value(T3412). See lte_psm_timeval_t */ + + lte_psm_timeval_t ext_periodic_tau_time; +} lte_psm_setting_t; + +/* Definition of APN setting used in lte_activate_pdn(). + */ + +typedef struct lte_apn_setting +{ + /* Access point name. It is terminated with '\0'. + * Maximum length is LTE_APN_LEN including '\0'. + */ + + char *apn; + + /* Type of IP for APN. Definition is as below. + * - LTE_IPTYPE_V4 + * - LTE_IPTYPE_V6 + * - LTE_IPTYPE_V4V6 + * - LTE_IPTYPE_NON + */ + + uint8_t ip_type; + + /* Type of Authentication. Definition is as below. + * - LTE_APN_AUTHTYPE_NONE + * - LTE_APN_AUTHTYPE_PAP + * - LTE_APN_AUTHTYPE_CHAP + */ + + uint8_t auth_type; + + /* Type of APN. Bit setting definition is as below. + * - LTE_APN_TYPE_UNKNOWN + * - LTE_APN_TYPE_DEFAULT + * - LTE_APN_TYPE_MMS + * - LTE_APN_TYPE_SUPL + * - LTE_APN_TYPE_DUN + * - LTE_APN_TYPE_HIPRI + * - LTE_APN_TYPE_FOTA + * - LTE_APN_TYPE_IMS + * - LTE_APN_TYPE_CBS + * - LTE_APN_TYPE_IA + * - LTE_APN_TYPE_EMERGENCY + */ + + uint32_t apn_type; + + /* User name. It is terminated with '\0'. + * Maximum length is LTE_APN_USER_NAME_LEN including '\0'. + */ + + char *user_name; + + /* Password. It is terminated with '\0'. + * Maximum length is LTE_APN_PASSWD_LEN including '\0'. + */ + + char *password; +} lte_apn_setting_t; + +/* Definition of ip address used in lte_pdn_t. + */ + +typedef struct lte_ipaddr +{ + /* Type of IP address. Definition is as below. + * - LTE_IPTYPE_V4 + * - LTE_IPTYPE_V6 + */ + + uint8_t ip_type; + + /* IP address. It is terminated with '\0'. + * eg. (IPv4) 192.0.2.1, (IPv6) 2001:db8:85a3:0:0:8a2e:370:7334 + */ + + char address[LTE_IPADDR_MAX_LEN]; +} lte_ipaddr_t; + +/* Definition of pdn information used in activate_pdn_cb_t. + */ + +typedef struct lte_pdn +{ + /* PDN session id. The range is from + * LTE_PDN_SESSIONID_MIN to LTE_PDN_SESSIONID_MAX. + */ + + uint8_t session_id; + + /* PDN active status. Definition is as below. + * - LTE_PDN_ACTIVE + * - LTE_PDN_DEACTIVE + */ + + uint8_t active; + + /* APN type of PDN. Bit setting definition is as below. + * - LTE_APN_TYPE_UNKNOWN + * - LTE_APN_TYPE_DEFAULT + * - LTE_APN_TYPE_MMS + * - LTE_APN_TYPE_SUPL + * - LTE_APN_TYPE_DUN + * - LTE_APN_TYPE_HIPRI + * - LTE_APN_TYPE_FOTA + * - LTE_APN_TYPE_IMS + * - LTE_APN_TYPE_CBS + * - LTE_APN_TYPE_IA + * - LTE_APN_TYPE_EMERGENCY + */ + + uint32_t apn_type; + + /* Number of valid ip addresses */ + + uint8_t ipaddr_num; + + /* IP address information. See @ref lte_ipaddr_t */ + + lte_ipaddr_t address[LTE_PDN_IPADDR_MAX_COUNT]; + + /* IMS registored status. + * This is valid when LTE_APN_TYPE_IMS is set in apn_type. + * Definition is as below. + * - LTE_IMS_NOT_REGISTERED + * - LTE_IMS_REGISTERED + */ + + uint8_t ims_register; + + /* Status of data communication enability. Definition is as below. + * - LTE_DATA_ALLOW + * - LTE_DATA_DISALLOW + */ + + uint8_t data_allow; + + /* Status of roaming data communication enability. + * Definition is as below. + * - LTE_DATA_ALLOW + * - LTE_DATA_DISALLOW + */ + + uint8_t data_roaming_allow; +} lte_pdn_t; + +/* Definition of LTE network reject cause used in lte_nw_err_info_t. + */ + +typedef struct lte_reject_cause +{ + /* Category of reject cause. Definition is as below. + * - LTE_REJECT_CATEGORY_EMM + * - LTE_REJECT_CATEGORY_ESM + */ + + uint8_t category; + + /* Value of LTE network reject cause. + * Definition is See 3GPP TS 24.008 13.7.0 + */ + + uint8_t value; +} lte_reject_cause_t; + +/* Definition of LTE network error information used in lte_netinfo_t. + */ + +typedef struct lte_nw_err_info +{ + /* Type of LTE network error. Definition is as below. + * - LTE_NETERR_MAXRETRY + * - LTE_NETERR_REJECT + * - LTE_NETERR_NWDTCH + */ + + uint8_t err_type; + + /* LTE network attach request reject cause. It can be referenced when + * LTE_NETERR_REJECT is see in err_type field + * See lte_reject_cause_t + */ + + lte_reject_cause_t reject_cause; +} lte_nw_err_info_t; + +/* Definition of lte network information used in get_netinfo_cb_t. + */ + +typedef struct lte_netinfo +{ + /* LTE network status. Definition is as below. + * - LTE_NETSTAT_NOT_REG_NOT_SEARCHING + * - LTE_NETSTAT_REG_HOME + * - LTE_NETSTAT_NOT_REG_SEARCHING + * - LTE_NETSTAT_REG_DENIED + * - LTE_NETSTAT_UNKNOWN + * - LTE_NETSTAT_REG_ROAMING + * - LTE_NETSTAT_REG_SMS_ONLY_HOME + * - LTE_NETSTAT_REG_SMS_ONLY_ROAMING + * - LTE_NETSTAT_NOT_REG_EMERGENCY + * - LTE_NETSTAT_REG_CSFB_NOT_PREF_HOME + * - LTE_NETSTAT_REG_CSFB_NOT_PREF_ROAMING + */ + + uint8_t nw_stat; + + /* LTE network error information. It can be referenced when + * LTE_NETSTAT_REG_DENIED is set in nw_stat field. + * See lte_nw_err_info_t + */ + + lte_nw_err_info_t nw_err; + + /* Number of PDN status informations. + * The maximum number of PDNs is LTE_SESSION_ID_MAX. + */ + + uint8_t pdn_num; + + /* List of PDN status. See lte_pdn_t + * + * When using the lte_getnetinfo, + * the maximum number of PDNs status areas must be allocated. + */ + + lte_pdn_t *pdn_stat; +} lte_netinfo_t; + +/* Definition of error information used in lte_get_errinfo(). + */ + +typedef struct lte_error_info +{ + /* Enable error indicator. Bit setting definition is as below. + * - LTE_ERR_INDICATOR_ERRCODE + * - LTE_ERR_INDICATOR_ERRNO + * - LTE_ERR_INDICATOR_ERRSTR + */ + + uint8_t err_indicator; + + /* Last error code. See 3GPP TS 27.007 9.2 */ + + int32_t err_result_code; + + /* Last error no. See */ + + int32_t err_no; + + /* Error string use debug only */ + + char err_string[LTE_ERROR_STRING_MAX_LEN]; +} lte_errinfo_t; + +/* Definition of CE settings used in lte_set_ce(). + * This is notified by get_ce_cb_t + */ + +typedef struct lte_ce_setting +{ + /* Mode A enable. Definition is as below. + * - LTE_ENABLE + * - LTE_DISABLE + */ + + bool mode_a_enable; + + /* Mode B enable. Definition is as below. + * - LTE_ENABLE + * - LTE_DISABLE + */ + + bool mode_b_enable; +} lte_ce_setting_t; + +/* Definition of parameters for SIM information. + * This is notified by get_siminfo_cb_t + */ + +typedef struct lte_siminfo +{ + /* Indicates which parameter to get. + * Bit setting definition is as below. + * - LTE_SIMINFO_GETOPT_MCCMNC + * - LTE_SIMINFO_GETOPT_SPN + * - LTE_SIMINFO_GETOPT_ICCID + * - LTE_SIMINFO_GETOPT_IMSI + * - LTE_SIMINFO_GETOPT_GID1 + * - LTE_SIMINFO_GETOPT_GID2 + */ + + uint32_t option; + + /* Mobile Country Code (000-999). It can be referenced when + * LTE_SIMINFO_GETOPT_MCCMNC is set in option field. + */ + + char mcc[LTE_MCC_DIGIT]; + + /* Digit number of Mobile Network Code(2-3). It can be referenced when + * LTE_SIMINFO_GETOPT_MCCMNC is set in option field. + */ + + uint8_t mnc_digit; + + /* Mobile Network Code (00-999). It can be referenced when + * LTE_SIMINFO_GETOPT_MCCMNC is set in option field. + */ + + char mnc[LTE_MNC_DIGIT_MAX]; + + /* Length of Service provider name. It can be referenced when + * LTE_SIMINFO_GETOPT_SPN is set in option field. + */ + + uint8_t spn_len; + + /* Service provider name. It can be referenced when + * LTE_SIMINFO_GETOPT_SPN is set in option field. + */ + + char spn[LTE_SIMINFO_SPN_LEN]; + + /* Length of ICCID. It can be referenced when + * LTE_SIMINFO_GETOPT_ICCID is set in option field. + */ + + uint8_t iccid_len; + + /* ICCID. It can be referenced when + * LTE_SIMINFO_GETOPT_ICCID is set in option field. + * If the ICCID is 19 digits, "F" is set to the 20th digit. + */ + + uint8_t iccid[LTE_SIMINFO_ICCID_LEN]; + + /* Length of IMSI. It can be referenced when + * LTE_SIMINFO_GETOPT_IMSI is set in option field. + */ + + uint8_t imsi_len; + + /* International Mobile Subscriber Identity. It can be referenced when + * LTE_SIMINFO_GETOPT_IMSI is set in option field. + */ + + char imsi[LTE_SIMINFO_IMSI_LEN]; + + /* Length of GID1. It can be referenced when + * LTE_SIMINFO_GETOPT_GID1 is set in option field. + */ + + uint8_t gid1_len; + + /* Group Identifier Level 1. It can be referenced when + * LTE_SIMINFO_GETOPT_GID1 is set in option field. + */ + + char gid1[LTE_SIMINFO_GID_LEN]; + + /* Length of GID2. It can be referenced when + * LTE_SIMINFO_GETOPT_GID2 is set in option field. + */ + + uint8_t gid2_len; + + /* Group Identifier Level 1. It can be referenced when + * LTE_SIMINFO_GETOPT_GID2 is set in option field. + */ + + char gid2[LTE_SIMINFO_GID_LEN]; +} lte_siminfo_t; + +/* Definition of parameters for RAT information. + */ + +typedef struct lte_ratinfo +{ + /* RAT type. Definition is as below. + * - LTE_RAT_CATM + * - LTE_RAT_NBIOT + */ + + uint8_t rat; + + /* Flag that indicates whether the modem supports multiple RATs. + * Definition is as below. + * - LTE_ENABLE + * - LTE_DISABLE + */ + + bool multi_rat_support; + + /* Source that determined the current RAT. + * Definition is as below. + * - LTE_RAT_SOURCE_DEFAULT + * - LTE_RAT_SOURCE_HOST + * - LTE_RAT_SOURCE_LWM2M + */ + + uint8_t source; +} lte_ratinfo_t; + +/* Definition of delta image setting to inject. + */ + +struct ltefw_injectdata_s +{ + /* The pointer of delta image to inject */ + + uint8_t *data; + + /* The length of image to inject. */ + + uint32_t data_len; + + /* Delta image injection mode. + * As below value stored. + * - LTEFW_INJECTION_MODE_NEW + * - LTEFW_INJECTION_MODE_APPEND + */ + + uint8_t inject_mode; +}; + +/* Definition of callback function. + * + * Since lte_get_version() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_version(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] version : The version information of the modem. + * See @ref lte_version_t + */ + +typedef void (*get_ver_cb_t)(uint32_t result, lte_version_t *version); + +/* Definition of callback function. + * + * Since lte_get_phoneno() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_phoneno(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] errcause : Error cause. It is set only if the result is + * not successful. As below value stored. + * - LTE_ERR_WAITENTERPIN + * - LTE_ERR_UNEXPECTED + * + * [in] phoneno : A character string indicating phone number. + * It is terminated with '\0' + */ + +typedef void (*get_phoneno_cb_t)(uint32_t result, uint8_t errcause, + char *phoneno); + +/* Definition of callback function. + * + * Since lte_get_imsi() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_imsi(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] errcause : Error cause. It is set only if the result is + * not successful. As below value stored. + * - LTE_ERR_WAITENTERPIN + * - LTE_ERR_UNEXPECTED + * [in] imsi : A character string indicating IMSI. + * It is terminated with '\0' + */ + +typedef void (*get_imsi_cb_t)(uint32_t result, uint8_t errcause, + char *imsi); + +/* Definition of callback function. + * + * Since lte_get_imei() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_imei(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] imei : A character string indicating IMEI. + * It is terminated with '\0' + */ + +typedef void (*get_imei_cb_t)(uint32_t result, char *imei); + +/* Definition of callback function. + * + * Since lte_get_pinset() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_pinset(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] pinset : PIN settings information. + * See lte_getpin_t + */ + +typedef void (*get_pinset_cb_t)(uint32_t result, lte_getpin_t *pinset); + +/* Definition of callback function. + * + * Since lte_set_pinenable() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_set_pinenable(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] attemptsleft : Number of attempts left. + * It is set only if the result is not successful. + */ + +typedef void (*set_pinenable_cb_t)(uint32_t result, uint8_t attemptsleft); + +/* Definition of callback function. + * + * Since lte_change_pin() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_change_pin(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] attemptsleft : Number of attempts left. + * It is set only if the result is not successful. + */ + +typedef void (*change_pin_cb_t)(uint32_t result, uint8_t attemptsleft); + +/* Definition of callback function. + * + * Since lte_enter_pin() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_enter_pin(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] simstat : State after PIN enter. + * As below value stored. + * - LTE_PINSTAT_READY + * - LTE_PINSTAT_SIM_PIN + * - LTE_PINSTAT_SIM_PUK + * - LTE_PINSTAT_PH_SIM_PIN + * - LTE_PINSTAT_PH_FSIM_PIN + * - LTE_PINSTAT_PH_FSIM_PUK + * - LTE_PINSTAT_SIM_PIN2 + * - LTE_PINSTAT_SIM_PUK2 + * - LTE_PINSTAT_PH_NET_PIN + * - LTE_PINSTAT_PH_NET_PUK + * - LTE_PINSTAT_PH_NETSUB_PIN + * - LTE_PINSTAT_PH_NETSUB_PUK + * - LTE_PINSTAT_PH_SP_PIN + * - LTE_PINSTAT_PH_SP_PUK + * - LTE_PINSTAT_PH_CORP_PIN + * - LTE_PINSTAT_PH_CORP_PUK + * + * [in] attemptsleft : Number of attempts left. + * It is set only if the result is not successful. + * If simstat is other than PIN, PUK, PIN2, PUK2, + * set the number of PIN. + */ + +typedef void (*enter_pin_cb_t)(uint32_t result, + uint8_t simstat, + uint8_t attemptsleft); + +/* Definition of callback function. + * + * Since lte_get_localtime() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_localtime(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] localtime : Local time. See lte_localtime_t + */ + +typedef void (*get_localtime_cb_t)(uint32_t result, + lte_localtime_t *localtime); + +/* Definition of callback function. + * + * Since lte_get_operator() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_operator(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] oper : A character string indicating network operator. + * It is terminated with '\0' If it is not connected, + * the first character is '\0'. + */ + +typedef void (*get_operator_cb_t)(uint32_t result, char *oper); + +/* Definition of callback function. + * + * Since lte_get_edrx() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_edrx(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] settings : eDRX settings. See lte_edrx_setting_t + */ + +typedef void (*get_edrx_cb_t)(uint32_t result, lte_edrx_setting_t *settings); + +/* Definition of callback function. + * + * Since lte_set_edrx() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_set_edrx(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + */ + +typedef void (*set_edrx_cb_t)(uint32_t result); + +/* Definition of callback function. + * + * Since lte_get_psm() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_psm(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] settings : PSM settings. See lte_psm_setting_t + */ + +typedef void (*get_psm_cb_t)(uint32_t result, lte_psm_setting_t *settings); + +/* Definition of callback function. + * + * Since lte_set_psm() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_set_psm(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + */ + +typedef void (*set_psm_cb_t)(uint32_t result); + +/* Definition of callback function. + * + * Since lte_get_ce() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_ce(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] settings : CE settings. See lte_ce_setting_t + */ + +typedef void (*get_ce_cb_t)(uint32_t result, lte_ce_setting_t *settings); + +/* Definition of callback function. + * + * Since lte_set_ce() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_set_ce(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + */ + +typedef void (*set_ce_cb_t)(uint32_t result); + +/* Definition of callback function. + * + * When the SIM state changes, the SIM state is + * reported by this function. + * + * [in] simstat : The SIM state. + * As below value stored. + * - LTE_SIMSTAT_REMOVAL + * - LTE_SIMSTAT_INSERTION + * - LTE_SIMSTAT_WAIT_PIN_UNLOCK + * - LTE_SIMSTAT_PERSONAL_FAILED + * - LTE_SIMSTAT_ACTIVATE + * - LTE_SIMSTAT_DEACTIVATE + */ + +typedef void (*simstat_report_cb_t)(uint32_t simstat); + +/* Definition of callback function. + * + * When the local time changes, the local time is + * reported by this function. + * + * [in] localtime : Local time. See lte_localtime_t + */ + +typedef void (*localtime_report_cb_t)(lte_localtime_t *localtime); + +/* Definition of callback function. + * + * The quality information is reported by this function. It is reported + * at intervals of the set report period. + * + * [in] quality : Quality information. See lte_quality_t + */ + +typedef void (*quality_report_cb_t)(lte_quality_t *quality); + +/* Definition of callback function. + * + * The cell information is reported by this function. It is reported + * at intervals of the set report period. + * + * [in] cellinfo : Cell information. See lte_cellinfo_t + */ + +typedef void (*cellinfo_report_cb_t)(lte_cellinfo_t *cellinfo); + +/* Definition of callback function. + * + * Since lte_radio_on() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_radio_on(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + */ + +typedef void (*radio_on_cb_t)(uint32_t result); + +/* Definition of callback function. + * + * Since lte_radio_off() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_radio_off(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + */ + +typedef void (*radio_off_cb_t)(uint32_t result); + +/* Definition of callback function. + * + * Since lte_get_netinfo() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_netinfo(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] info : Pointer of LTE network information. + * See lte_netinfo_t + */ + +typedef void (*get_netinfo_cb_t)(uint32_t result, lte_netinfo_t *info); + +/* Definition of callback function. + * + * Since lte_get_imscap() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_imscap. + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] imscap : The IMS capability. + * As below value stored. + * - LTE_ENABLE + * - LTE_DISABLE + */ + +typedef void (*get_imscap_cb_t)(uint32_t result, bool imscap); + +/* Definition of callback function. + * + * Since lte_activate_pdn() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_activate_pdn. + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * - LTE_RESULT_CANCEL + * + * [in] pdn : The connect pdn information. See lte_pdn_t + */ + +typedef void (*activate_pdn_cb_t)(uint32_t result, lte_pdn_t *pdn); + +/* Definition of callback function. + * + * Since lte_deactivate_pdn() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_deactivate_pdn. + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + */ + +typedef void (*deactivate_pdn_cb_t)(uint32_t result); + +/* Definition of callback function. + * + * Since lte_dataallow() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_dataallow. + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + */ + +typedef void (*data_allow_cb_t)(uint32_t result); + +/* Definition of callback function. + * + * The modem restart is reported by this function. It is reported + * at modem reset. + * + * [in] reason : Reason of modem restart. + * As below value stored. + * - LTE_RESTART_USER_INITIATED + * - LTE_RESTART_MODEM_INITIATED + */ + +typedef void (*restart_report_cb_t)(uint32_t reason); + +/* Definition of callback function. + * + * The change LTE network information is reported by this function. + * It is reported at LTE network connection status. + * + * [in] info : Pointer of LTE network information. + * See lte_netinfo_t + */ + +typedef void (*netinfo_report_cb_t)(lte_netinfo_t *info); + +/* Definition of callback function. + * + * Since lte_get_siminfo() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_siminfo(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] siminfo : SIM information. See lte_siminfo_t + */ + +typedef void (*get_siminfo_cb_t)(uint32_t result, lte_siminfo_t *siminfo); + +/* Definition of callback function. + * + * Since lte_get_dynamic_edrx_param() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_dynamic_edrx_param(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] param : eDRX dynamic parameter. See lte_edrx_setting_t. + */ + +typedef void (*get_dynamic_edrx_param_cb_t)(uint32_t result, + lte_edrx_setting_t *param); + +/* Definition of callback function. + * + * Since lte_get_dynamic_psm_param() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_dynamic_psm_param(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] param : PSM dynamic parameter. See lte_psm_setting_t + */ + +typedef void (*get_dynamic_psm_param_cb_t)(uint32_t result, + lte_psm_setting_t *param); + +/* Definition of callback function. + * + * Since lte_get_current_edrx() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_current_edrx(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] settings : Current eDRX settings. See lte_edrx_setting_t. + */ + +typedef void (*get_current_edrx_cb_t)(uint32_t result, + lte_edrx_setting_t *settings); + +/* Definition of callback function. + * + * Since lte_get_current_psm() is an asynchronous API, + * the result is notified by this function. + * + * [in] result : The result of lte_get_current_psm(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] settings : Current PSM settings. See lte_psm_setting_t + */ + +typedef void (*get_current_psm_cb_t)(uint32_t result, + lte_psm_setting_t *settings); + +/* Definition of callback function. + * + * Since lte_get_quality() is an asynchronous API, + * the quality information is notified by this function. + * + * [in] result : The result of lte_get_quality(). + * As below value stored. + * - LTE_RESULT_OK + * - LTE_RESULT_ERROR + * + * [in] quality : Quality information. See lte_quality_t + */ + +typedef void (*get_quality_cb_t)(uint32_t result, + lte_quality_t *quality); + +#endif /* __INCLUDE_NUTTX_WIRELESS_LTE_LTE_H */ diff --git a/include/nuttx/wireless/lte/lte_ioctl.h b/include/nuttx/wireless/lte/lte_ioctl.h new file mode 100644 index 00000000000..821ce9db7a9 --- /dev/null +++ b/include/nuttx/wireless/lte/lte_ioctl.h @@ -0,0 +1,371 @@ +/**************************************************************************** + * include/nuttx/wireless/lte/lte_ioctl.h + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_WIRELESS_LTE_LTE_IOCTL_H +#define __INCLUDE_NUTTX_WIRELESS_LTE_LTE_IOCTL_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include +#include +#include +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* LTE network device IOCTL commands. */ + +/* SIOCLTECMD + * Description: Perform LTE command + */ + +#define SIOCLTECMD _LTEIOC(0) + +/* SIOCSMSENSTREP + * Description: Enable or disable the function to confirm whether or not + * the SMS has been delivered to the destination device. + */ + +#define SIOCSMSENSTREP _LTEIOC(1) + +/* SIOCSMSGREFID + * Description: Obtain the ID associated with the submitted SMS. + * If the submitted SMS is a concatenated SMS, multiple IDs + * will be obtained; + * otherwise, a single ID will be obtained. + */ + +#define SIOCSMSGREFID _LTEIOC(2) + +/* SIOCSMSSSCA + * Description: Set the service center address of the destination. + */ + +#define SIOCSMSSSCA _LTEIOC(3) + +/* for cmdid */ + +#define _CMDOPT_LSB (28) +#define _CMDOPT_MASK (0xf << (_CMDOPT_LSB)) +#define _CMDGRP_LSB (24) +#define _CMDGRP_MASK (0xf << (_CMDGRP_LSB)) +#define _CMDGRP_SHIFT(nr) ((nr) << (_CMDGRP_LSB)) +#define _CMDGRP_NORMAL(nr) (_CMDGRP_SHIFT(0) | (nr)) +#define _CMDGRP_EVENT(nr) (_CMDGRP_SHIFT(1) | (nr)) +#define _CMDGRP_NOMDM(nr) (_CMDGRP_SHIFT(2) | (nr)) +#define _CMDGRP_POWER(nr) (_CMDGRP_SHIFT(3) | (nr)) +#define _CMDGRP_FWUPDATE(nr) (_CMDGRP_SHIFT(4) | (nr)) +#define _CMDGRP_EXTEND(nr) (_CMDGRP_SHIFT(5) | (nr)) +#define _CMDGRP_LWM2M(nr) (_CMDGRP_SHIFT(6) | (nr)) +#define LTE_CMDOPT_ASYNC_BIT (0x1 << (_CMDOPT_LSB)) +#define LTE_IS_ASYNC_CMD(cid) ((cid) & LTE_CMDOPT_ASYNC_BIT) +#define LTE_PURE_CMDID(cid) ((cid) & ~LTE_CMDOPT_ASYNC_BIT) +#define LTE_ISCMDGRP_NORMAL(cmd) ((cmd & _CMDGRP_MASK) == _CMDGRP_NORMAL(0)) +#define LTE_ISCMDGRP_EVENT(cmd) ((cmd & _CMDGRP_MASK) == _CMDGRP_EVENT(0)) +#define LTE_ISCMDGRP_NOMDM(cmd) ((cmd & _CMDGRP_MASK) == _CMDGRP_NOMDM(0)) +#define LTE_ISCMDGRP_POWER(cmd) ((cmd & _CMDGRP_MASK) == _CMDGRP_POWER(0)) +#define LTE_ISCMDGRP_FWUPDATE(cmd) ((cmd & _CMDGRP_MASK) == _CMDGRP_FWUPDATE(0)) +#define LTE_ISCMDGRP_EXTEND(cmd) ((cmd & _CMDGRP_MASK) == _CMDGRP_EXTEND(0)) +#define LTE_ISCMDGRP_LWM2M(cmd) ((cmd & _CMDGRP_MASK) == _CMDGRP_LWM2M(0)) + +#define LTE_CMDID_POWERON _CMDGRP_POWER(0x00) +#define LTE_CMDID_POWEROFF _CMDGRP_POWER(0x01) +#define LTE_CMDID_FIN _CMDGRP_POWER(0x02) +#define LTE_CMDID_SETEVTCTX _CMDGRP_NOMDM(0x03) +#define LTE_CMDID_SETRESTART _CMDGRP_NOMDM(0x04) +#define LTE_CMDID_GETERRINFO _CMDGRP_NOMDM(0x05) +#define LTE_CMDID_GETVER _CMDGRP_NORMAL(0x06) +#define LTE_CMDID_RADIOON _CMDGRP_NORMAL(0x07) +#define LTE_CMDID_RADIOOFF _CMDGRP_NORMAL(0x08) +#define LTE_CMDID_ACTPDN _CMDGRP_NORMAL(0x09) +#define LTE_CMDID_ACTPDNCAN _CMDGRP_NORMAL(0x0a) +#define LTE_CMDID_DEACTPDN _CMDGRP_NORMAL(0x0b) +#define LTE_CMDID_GETNETINFO _CMDGRP_NORMAL(0x0c) +#define LTE_CMDID_IMSCAP _CMDGRP_NORMAL(0x0d) +#define LTE_CMDID_GETPHONE _CMDGRP_NORMAL(0x0e) +#define LTE_CMDID_GETIMSI _CMDGRP_NORMAL(0x0f) +#define LTE_CMDID_GETIMEI _CMDGRP_NORMAL(0x10) +#define LTE_CMDID_GETPINSET _CMDGRP_NORMAL(0x11) +#define LTE_CMDID_PINENABLE _CMDGRP_NORMAL(0x12) +#define LTE_CMDID_CHANGEPIN _CMDGRP_NORMAL(0x13) +#define LTE_CMDID_ENTERPIN _CMDGRP_NORMAL(0x14) +#define LTE_CMDID_GETLTIME _CMDGRP_NORMAL(0x15) +#define LTE_CMDID_GETOPER _CMDGRP_NORMAL(0x16) +#define LTE_CMDID_GETEDRX _CMDGRP_NORMAL(0x17) +#define LTE_CMDID_SETEDRX _CMDGRP_NORMAL(0x18) +#define LTE_CMDID_GETPSM _CMDGRP_NORMAL(0x19) +#define LTE_CMDID_SETPSM _CMDGRP_NORMAL(0x1a) +#define LTE_CMDID_GETCE _CMDGRP_NORMAL(0x1b) +#define LTE_CMDID_SETCE _CMDGRP_NORMAL(0x1c) +#define LTE_CMDID_GETSIMINFO _CMDGRP_NORMAL(0x1d) +#define LTE_CMDID_GETCEDRX _CMDGRP_NORMAL(0x1e) +#define LTE_CMDID_GETCPSM _CMDGRP_NORMAL(0x1f) +#define LTE_CMDID_GETQUAL _CMDGRP_NORMAL(0x20) +#define LTE_CMDID_GETCELL _CMDGRP_NORMAL(0x21) +#define LTE_CMDID_GETRAT _CMDGRP_NORMAL(0x22) +#define LTE_CMDID_SETRAT _CMDGRP_NORMAL(0x23) +#define LTE_CMDID_GETRATINFO _CMDGRP_NORMAL(0x24) +#define LTE_CMDID_REPNETINFO _CMDGRP_EVENT(0x25) +#define LTE_CMDID_REPSIMSTAT _CMDGRP_EVENT(0x26) +#define LTE_CMDID_REPLTIME _CMDGRP_EVENT(0x27) +#define LTE_CMDID_REPQUAL _CMDGRP_EVENT(0x28) +#define LTE_CMDID_REPCELL _CMDGRP_EVENT(0x29) +#define LTE_CMDID_SAVEAPN _CMDGRP_NOMDM(0x2a) +#define LTE_CMDID_GETAPN _CMDGRP_NOMDM(0x2b) +#define LTE_CMDID_TAKEWLOCK _CMDGRP_POWER(0x2c) +#define LTE_CMDID_GIVEWLOCK _CMDGRP_POWER(0x2d) +#define LTE_CMDID_SENDATCMD _CMDGRP_NORMAL(0x2e) +#define LTE_CMDID_INJECTIMAGE _CMDGRP_FWUPDATE(0x2f) +#define LTE_CMDID_GETIMAGELEN _CMDGRP_FWUPDATE(0x30) +#define LTE_CMDID_EXEUPDATE _CMDGRP_FWUPDATE(0x31) +#define LTE_CMDID_GETUPDATERES _CMDGRP_NORMAL(0x32) +#define LTE_CMDID_FACTORY_RESET _CMDGRP_EXTEND(0x33) +#define LTE_CMDID_SAVE_LOG _CMDGRP_NORMAL(0x34) +#define LTE_CMDID_GET_LOGLIST _CMDGRP_NORMAL(0x35) +#define LTE_CMDID_LOGOPEN _CMDGRP_NORMAL(0x36) +#define LTE_CMDID_LOGCLOSE _CMDGRP_NORMAL(0x37) +#define LTE_CMDID_LOGREAD _CMDGRP_NORMAL(0x38) +#define LTE_CMDID_LOGLSEEK _CMDGRP_NORMAL(0x39) +#define LTE_CMDID_LOGREMOVE _CMDGRP_NORMAL(0x3a) + +#define LTE_CMDID_ACCEPT _CMDGRP_NORMAL(0x50) +#define LTE_CMDID_BIND _CMDGRP_NORMAL(0x51) +#define LTE_CMDID_CLOSE _CMDGRP_NORMAL(0x52) +#define LTE_CMDID_CONNECT _CMDGRP_NORMAL(0x53) +#define LTE_CMDID_FCNTL _CMDGRP_NORMAL(0x54) +#define LTE_CMDID_GETADDRINFO _CMDGRP_NORMAL(0x55) +#define LTE_CMDID_GETHOSTBYNAME _CMDGRP_NORMAL(0x56) +#define LTE_CMDID_GETHOSTBYNAMER _CMDGRP_NORMAL(0x57) +#define LTE_CMDID_GETSOCKNAME _CMDGRP_NORMAL(0x58) +#define LTE_CMDID_GETSOCKOPT _CMDGRP_NORMAL(0x59) +#define LTE_CMDID_LISTEN _CMDGRP_NORMAL(0x5a) +#define LTE_CMDID_RECV _CMDGRP_NORMAL(0x5b) +#define LTE_CMDID_RECVFROM _CMDGRP_NORMAL(0x5c) +#define LTE_CMDID_SELECT _CMDGRP_NORMAL(0x5d) +#define LTE_CMDID_SEND _CMDGRP_NORMAL(0x5e) +#define LTE_CMDID_SENDTO _CMDGRP_NORMAL(0x5f) +#define LTE_CMDID_SHUTDOWN _CMDGRP_NORMAL(0x60) +#define LTE_CMDID_SOCKET _CMDGRP_NORMAL(0x61) +#define LTE_CMDID_SETSOCKOPT _CMDGRP_NORMAL(0x62) + +#define LTE_CMDID_SMS_INIT _CMDGRP_NORMAL(0x65) +#define LTE_CMDID_SMS_FIN _CMDGRP_NORMAL(0x66) +#define LTE_CMDID_SMS_SEND _CMDGRP_NORMAL(0x67) +#define LTE_CMDID_SMS_DELETE _CMDGRP_NORMAL(0x68) +#define LTE_CMDID_SMS_REPORT_RECV _CMDGRP_EVENT(0x69) + +#define LTE_CMDID_TLS_SSL_INIT _CMDGRP_NORMAL(0x80) +#define LTE_CMDID_TLS_SSL_FREE _CMDGRP_NORMAL(0x81) +#define LTE_CMDID_TLS_SSL_SETUP _CMDGRP_NORMAL(0x82) +#define LTE_CMDID_TLS_SSL_HOSTNAME _CMDGRP_NORMAL(0x83) +#define LTE_CMDID_TLS_SSL_BIO _CMDGRP_NORMAL(0x84) +#define LTE_CMDID_TLS_SSL_HANDSHAKE _CMDGRP_NORMAL(0x85) +#define LTE_CMDID_TLS_SSL_WRITE _CMDGRP_NORMAL(0x86) +#define LTE_CMDID_TLS_SSL_READ _CMDGRP_NORMAL(0x87) +#define LTE_CMDID_TLS_SSL_CLOSE_NOTIFY _CMDGRP_NORMAL(0x88) +#define LTE_CMDID_TLS_SSL_VERSION _CMDGRP_NORMAL(0x89) +#define LTE_CMDID_TLS_SSL_CIPHERSUITE _CMDGRP_NORMAL(0x8a) +#define LTE_CMDID_TLS_SSL_CIPHERSUITE_ID _CMDGRP_NORMAL(0x8b) +#define LTE_CMDID_TLS_SSL_RECORD_EXPANSION _CMDGRP_NORMAL(0x8c) +#define LTE_CMDID_TLS_SSL_VERIFY_RESULT _CMDGRP_NORMAL(0x8d) +#define LTE_CMDID_TLS_SSL_TIMER_CB _CMDGRP_NORMAL(0x8e) +#define LTE_CMDID_TLS_SSL_PEER_CERT _CMDGRP_NORMAL(0x8f) +#define LTE_CMDID_TLS_SSL_BYTES_AVAIL _CMDGRP_NORMAL(0x90) +#define LTE_CMDID_TLS_CONFIG_INIT _CMDGRP_NORMAL(0x91) +#define LTE_CMDID_TLS_CONFIG_FREE _CMDGRP_NORMAL(0x92) +#define LTE_CMDID_TLS_CONFIG_DEFAULTS _CMDGRP_NORMAL(0x93) +#define LTE_CMDID_TLS_CONFIG_AUTHMODE _CMDGRP_NORMAL(0x94) +#define LTE_CMDID_TLS_CONFIG_RNG _CMDGRP_NORMAL(0x95) +#define LTE_CMDID_TLS_CONFIG_CA_CHAIN _CMDGRP_NORMAL(0x96) +#define LTE_CMDID_TLS_CONFIG_OWN_CERT _CMDGRP_NORMAL(0x97) +#define LTE_CMDID_TLS_CONFIG_READ_TIMEOUT _CMDGRP_NORMAL(0x98) +#define LTE_CMDID_TLS_CONFIG_VERIFY _CMDGRP_EVENT(0x99) +#define LTE_CMDID_TLS_CONFIG_VERIFY_CALLBACK _CMDGRP_NORMAL(0x9a) +#define LTE_CMDID_TLS_CONFIG_ALPN_PROTOCOLS _CMDGRP_NORMAL(0x9b) +#define LTE_CMDID_TLS_CONFIG_CIPHERSUITES _CMDGRP_NORMAL(0x9c) +#define LTE_CMDID_TLS_SESSION_INIT _CMDGRP_NORMAL(0x9d) +#define LTE_CMDID_TLS_SESSION_FREE _CMDGRP_NORMAL(0x9e) +#define LTE_CMDID_TLS_SESSION_GET _CMDGRP_NORMAL(0x9f) +#define LTE_CMDID_TLS_SESSION_SET _CMDGRP_NORMAL(0xa0) +#define LTE_CMDID_TLS_SESSION_RESET _CMDGRP_NORMAL(0xa1) +#define LTE_CMDID_TLS_X509_CRT_INIT _CMDGRP_NORMAL(0xa2) +#define LTE_CMDID_TLS_X509_CRT_FREE _CMDGRP_NORMAL(0xa3) +#define LTE_CMDID_TLS_X509_CRT_PARSE_FILE _CMDGRP_NORMAL(0xa4) +#define LTE_CMDID_TLS_X509_CRT_PARSE_DER _CMDGRP_NORMAL(0xa5) +#define LTE_CMDID_TLS_X509_CRT_PARSE _CMDGRP_NORMAL(0xa6) +#define LTE_CMDID_TLS_X509_CRT_INFO _CMDGRP_NORMAL(0xa7) +#define LTE_CMDID_TLS_X509_CRT_VERIFY_INFO _CMDGRP_NORMAL(0xa8) +#define LTE_CMDID_TLS_PK_INIT _CMDGRP_NORMAL(0xa9) +#define LTE_CMDID_TLS_PK_FREE _CMDGRP_NORMAL(0xaa) +#define LTE_CMDID_TLS_PK_PARSE_KEYFILE _CMDGRP_NORMAL(0xab) +#define LTE_CMDID_TLS_PK_PARSE_KEY _CMDGRP_NORMAL(0xac) +#define LTE_CMDID_TLS_PK_CHECK_PAIR _CMDGRP_NORMAL(0xad) +#define LTE_CMDID_TLS_PK_SETUP _CMDGRP_NORMAL(0xae) +#define LTE_CMDID_TLS_PK_INFO_FROM_TYPE _CMDGRP_NORMAL(0xaf) +#define LTE_CMDID_TLS_PK_WRITE_KEY_PEM _CMDGRP_NORMAL(0xb0) +#define LTE_CMDID_TLS_PK_WRITE_KEY_DER _CMDGRP_NORMAL(0xb1) +#define LTE_CMDID_TLS_PK_RSA _CMDGRP_NORMAL(0xb2) +#define LTE_CMDID_TLS_CTR_DRBG_INIT _CMDGRP_NORMAL(0xb3) +#define LTE_CMDID_TLS_CTR_DRBG_FREE _CMDGRP_NORMAL(0xb4) +#define LTE_CMDID_TLS_CTR_DRBG_SEED _CMDGRP_NORMAL(0xb5) +#define LTE_CMDID_TLS_ENTROPY_INIT _CMDGRP_NORMAL(0xb6) +#define LTE_CMDID_TLS_ENTROPY_FREE _CMDGRP_NORMAL(0xb7) +#define LTE_CMDID_TLS_CIPHER_INIT _CMDGRP_NORMAL(0xb8) +#define LTE_CMDID_TLS_CIPHER_FREE _CMDGRP_NORMAL(0xb9) +#define LTE_CMDID_TLS_CIPHER_INFO_FROM_STRING _CMDGRP_NORMAL(0xba) +#define LTE_CMDID_TLS_CIPHER_SETUP _CMDGRP_NORMAL(0xbb) +#define LTE_CMDID_TLS_CIPHER_SETKEY _CMDGRP_NORMAL(0xbc) +#define LTE_CMDID_TLS_CIPHER_SET_IV _CMDGRP_NORMAL(0xbd) +#define LTE_CMDID_TLS_CIPHER_UPDATE _CMDGRP_NORMAL(0xbe) +#define LTE_CMDID_TLS_MD_INFO_FROM_TYPE _CMDGRP_NORMAL(0xbf) +#define LTE_CMDID_TLS_MD_GET_SIZE _CMDGRP_NORMAL(0xc0) +#define LTE_CMDID_TLS_MD _CMDGRP_NORMAL(0xc1) +#define LTE_CMDID_TLS_MD_DIGEST _CMDGRP_NORMAL(0xc2) +#define LTE_CMDID_TLS_BASE64_ENCODE _CMDGRP_NORMAL(0xc3) +#define LTE_CMDID_TLS_SHA1 _CMDGRP_NORMAL(0xc4) +#define LTE_CMDID_TLS_SSL_EXPORT_SRTP_KEYS _CMDGRP_NORMAL(0xc5) +#define LTE_CMDID_TLS_SSL_USE_SRTP _CMDGRP_NORMAL(0xc6) +#define LTE_CMDID_TLS_SSL_SRTP_PROFILE _CMDGRP_NORMAL(0xc7) +#define LTE_CMDID_TLS_SSL_TURN _CMDGRP_NORMAL(0xc8) +#define LTE_CMDID_TLS_MPI_INIT _CMDGRP_NORMAL(0xc9) +#define LTE_CMDID_TLS_MPI_FREE _CMDGRP_NORMAL(0xca) +#define LTE_CMDID_TLS_MPI_READ_STRING _CMDGRP_NORMAL(0xcb) +#define LTE_CMDID_TLS_MPI_WRITE_STRING _CMDGRP_NORMAL(0xcc) +#define LTE_CMDID_TLS_X509_CSR_INIT _CMDGRP_NORMAL(0xcd) +#define LTE_CMDID_TLS_X509_CSR_FREE _CMDGRP_NORMAL(0xce) +#define LTE_CMDID_TLS_X509_CSR_PARSE_FILE _CMDGRP_NORMAL(0xcf) +#define LTE_CMDID_TLS_X509_CSR_PARSE_DER _CMDGRP_NORMAL(0xd0) +#define LTE_CMDID_TLS_X509_CSR_PARSE _CMDGRP_NORMAL(0xd1) +#define LTE_CMDID_TLS_X509_DN_GETS_CRT _CMDGRP_NORMAL(0xd2) +#define LTE_CMDID_TLS_X509_DN_GETS_CSR _CMDGRP_NORMAL(0xd3) +#define LTE_CMDID_TLS_X509WRITE_CRT_INIT _CMDGRP_NORMAL(0xd4) +#define LTE_CMDID_TLS_X509WRITE_CRT_FREE _CMDGRP_NORMAL(0xd5) +#define LTE_CMDID_TLS_X509WRITE_CRT_DER _CMDGRP_NORMAL(0xd6) +#define LTE_CMDID_TLS_X509WRITE_CRT_PEM _CMDGRP_NORMAL(0xd7) +#define LTE_CMDID_TLS_X509WRITE_CRT_SUBJECT_KEY _CMDGRP_NORMAL(0xd8) +#define LTE_CMDID_TLS_X509WRITE_CRT_ISSUER_KEY _CMDGRP_NORMAL(0xd9) +#define LTE_CMDID_TLS_X509WRITE_CRT_SUBJECT_NAME _CMDGRP_NORMAL(0xda) +#define LTE_CMDID_TLS_X509WRITE_CRT_ISSUER_NAME _CMDGRP_NORMAL(0xdb) +#define LTE_CMDID_TLS_X509WRITE_CRT_VERSION _CMDGRP_NORMAL(0xdc) +#define LTE_CMDID_TLS_X509WRITE_CRT_MD_ALG _CMDGRP_NORMAL(0xdd) +#define LTE_CMDID_TLS_X509WRITE_CRT_SERIAL _CMDGRP_NORMAL(0xde) +#define LTE_CMDID_TLS_X509WRITE_CRT_VALIDITY _CMDGRP_NORMAL(0xdf) +#define LTE_CMDID_TLS_X509WRITE_CRT_CONSTRAINTS _CMDGRP_NORMAL(0xe0) +#define LTE_CMDID_TLS_X509WRITE_CRT_SUBJECT_ID _CMDGRP_NORMAL(0xe1) +#define LTE_CMDID_TLS_X509WRITE_CRT_AUTHORITY_ID _CMDGRP_NORMAL(0xe2) +#define LTE_CMDID_TLS_X509WRITE_CRT_KEY_USAGE _CMDGRP_NORMAL(0xe3) +#define LTE_CMDID_TLS_X509WRITE_CRT_NS_CERT_TYPE _CMDGRP_NORMAL(0xe4) +#define LTE_CMDID_TLS_RSA_INIT _CMDGRP_NORMAL(0xe5) +#define LTE_CMDID_TLS_RSA_FREE _CMDGRP_NORMAL(0xe6) +#define LTE_CMDID_TLS_RSA_GEN_KEY _CMDGRP_NORMAL(0xe7) + +/* for LwM2M stub */ + +#define LTE_CMDID_LWM2M_URC_DUMMY _CMDGRP_EVENT(0x0101) +#define LTE_CMDID_LWM2M_READ_EVT _CMDGRP_EVENT(0x0102) +#define LTE_CMDID_LWM2M_WRITE_EVT _CMDGRP_EVENT(0x0103) +#define LTE_CMDID_LWM2M_EXEC_EVT _CMDGRP_EVENT(0x0104) +#define LTE_CMDID_LWM2M_OVSTART_EVT _CMDGRP_EVENT(0x0105) +#define LTE_CMDID_LWM2M_OVSTOP_EVT _CMDGRP_EVENT(0x0106) +#define LTE_CMDID_LWM2M_SERVEROP_EVT _CMDGRP_EVENT(0x0107) +#define LTE_CMDID_LWM2M_FWUP_EVT _CMDGRP_EVENT(0x0108) + +#define LTE_CMDID_LWM2M_GETEP _CMDGRP_LWM2M(0x0109) +#define LTE_CMDID_LWM2M_SETEP _CMDGRP_LWM2M(0x010A) +#define LTE_CMDID_LWM2M_GETSRVNUM _CMDGRP_LWM2M(0x010B) +#define LTE_CMDID_LWM2M_GETSRVINFO _CMDGRP_LWM2M(0x010C) +#define LTE_CMDID_LWM2M_SETSRVINFO _CMDGRP_LWM2M(0x010D) +#define LTE_CMDID_LWM2M_GETACTIVEOBJNUM _CMDGRP_LWM2M(0x010E) +#define LTE_CMDID_LWM2M_GETACTIVEOBJ _CMDGRP_LWM2M(0x010F) +#define LTE_CMDID_LWM2M_SETACTIVEOBJ _CMDGRP_LWM2M(0x0110) +#define LTE_CMDID_LWM2M_APPLY_SETTING _CMDGRP_LWM2M(0x0111) +#define LTE_CMDID_LWM2M_GETOBJRESNUM _CMDGRP_LWM2M(0x0112) +#define LTE_CMDID_LWM2M_GETOBJRESOURCE _CMDGRP_LWM2M(0x0113) +#define LTE_CMDID_LWM2M_SETOBJRESOURCE _CMDGRP_LWM2M(0x0114) + +#define LTE_CMDID_LWM2M_CONNECT _CMDGRP_LWM2M(0x0115) +#define LTE_CMDID_LWM2M_READRESP _CMDGRP_LWM2M(0x0116) +#define LTE_CMDID_LWM2M_WRITERESP _CMDGRP_LWM2M(0x0117) +#define LTE_CMDID_LWM2M_OBSERVERESP _CMDGRP_LWM2M(0x0118) +#define LTE_CMDID_LWM2M_EXECRESP _CMDGRP_LWM2M(0x0119) +#define LTE_CMDID_LWM2M_OBSERVEUPDATE _CMDGRP_LWM2M(0x011A) + +#define IS_LWM2M_EVENT(cid) (\ + ((cid) == LTE_CMDID_LWM2M_READ_EVT) || \ + ((cid) == LTE_CMDID_LWM2M_WRITE_EVT) || \ + ((cid) == LTE_CMDID_LWM2M_EXEC_EVT) || \ + ((cid) == LTE_CMDID_LWM2M_OVSTART_EVT) || \ + ((cid) == LTE_CMDID_LWM2M_OVSTOP_EVT) || \ + ((cid) == LTE_CMDID_LWM2M_SERVEROP_EVT) || \ + ((cid) == LTE_CMDID_LWM2M_FWUP_EVT) ) + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +typedef void (*lte_evthndl_t)(uint64_t evtbitmap); + +/* for SIOCLTECMD IOCTL command */ + +struct lte_ioctl_data_s +{ + uint32_t cmdid; /* Command ID */ + FAR void **inparam; /* Pointer to input parameter */ + size_t inparamlen; /* Length of input parameter */ + FAR void **outparam; /* Pointer to output parameter */ + size_t outparamlen; /* Length of output parameter */ + FAR void *cb; /* Pointer to callback function */ +}; + +struct lte_evtctx_in_s +{ + FAR const char *mqname; +}; + +struct lte_evtctx_out_s +{ + lte_evthndl_t handle; +}; + +/* for IOCTL related SMS */ + +struct lte_smsreq_s +{ + union + { + /* Using for SIOCSMSENSTREP command */ + + bool enable; + + /* Using for SIOCSMSGREFID command */ + + struct sms_refids_s refid; + + /* Using for SIOCSMSSSCA command */ + + struct sms_sc_addr_s scaddr; + } smsru; +}; + +#endif /* __INCLUDE_NUTTX_WIRELESS_LTE_LTE_IOCTL_H */