diff --git a/boards/arm/cxd56xx/common/src/cxd56_alt1250.c b/boards/arm/cxd56xx/common/src/cxd56_alt1250.c index 84cfa01343..df1460d18a 100644 --- a/boards/arm/cxd56xx/common/src/cxd56_alt1250.c +++ b/boards/arm/cxd56xx/common/src/cxd56_alt1250.c @@ -38,6 +38,7 @@ #include #include +#include #include "cxd56_spi.h" #include "cxd56_dmac.h" @@ -79,6 +80,8 @@ static struct spi_dev_s *alt1250_poweron(void); static void alt1250_poweroff(void); +static bool alt1250_powerstatus(void); +static int alt1250_hibernation_mode(bool enable); static void alt1250_reset(void); static void alt1250_irqattach(xcpt_t handler); static void alt1250_irqenable(bool enable); @@ -95,6 +98,8 @@ static const struct alt1250_lower_s g_alt1250_lower = { .poweron = alt1250_poweron, .poweroff = alt1250_poweroff, + .powerstatus = alt1250_powerstatus, + .hiber_mode = alt1250_hibernation_mode, .reset = alt1250_reset, .irqattach = alt1250_irqattach, .irqenable = alt1250_irqenable, @@ -292,6 +297,43 @@ static void alt1250_poweroff(void) board_alt1250_poweroff(); } +/**************************************************************************** + * Name: alt1250_powerstatus + * + * Description: + * Get the power status for the Altair modem device on the board. + * + ****************************************************************************/ + +static bool alt1250_powerstatus(void) +{ + return board_alt1250_powerstatus(); +} + +/**************************************************************************** + * Name: alt1250_hibernation_mode + * + * Description: + * Set power manager for entering hibernation mode. + * + ****************************************************************************/ + +static int alt1250_hibernation_mode(bool enable) +{ + uint32_t bootmask = 0; + + if (enable) + { + /* Set GPIO interrupt for wake-up */ + + bootmask = up_pm_get_bootmask(); + bootmask |= PM_BOOT_COLD_GPIO; + up_pm_set_bootmask(bootmask); + } + + return board_alt1250_powerkeep(enable); +} + /**************************************************************************** * Name: alt1250_reset * diff --git a/boards/arm/cxd56xx/spresense/include/cxd56_alt1250.h b/boards/arm/cxd56xx/spresense/include/cxd56_alt1250.h index 379b449537..ebeb909b59 100644 --- a/boards/arm/cxd56xx/spresense/include/cxd56_alt1250.h +++ b/boards/arm/cxd56xx/spresense/include/cxd56_alt1250.h @@ -56,7 +56,7 @@ extern "C" * ****************************************************************************/ -int board_alt1250_initialize(const char *devpath); +int board_alt1250_initialize(FAR const char *devpath); /**************************************************************************** * Name: board_alt1250_uninitialize @@ -88,6 +88,26 @@ void board_alt1250_poweron(void); void board_alt1250_poweroff(void); +/**************************************************************************** + * Name: board_alt1250_powerstatus + * + * Description: + * Get the power status for the Altair modem device on the board. + * + ****************************************************************************/ + +bool board_alt1250_powerstatus(void); + +/**************************************************************************** + * Name: board_alt1250_powerkeep + * + * Description: + * Set Modem power keep mode when turning off the board. + * + ****************************************************************************/ + +int board_alt1250_powerkeep(bool enable); + /**************************************************************************** * Name: board_alt1250_reset * diff --git a/boards/arm/cxd56xx/spresense/src/cxd56_alt1250_power.c b/boards/arm/cxd56xx/spresense/src/cxd56_alt1250_power.c index 29b0e9fb59..fc3a612192 100644 --- a/boards/arm/cxd56xx/spresense/src/cxd56_alt1250_power.c +++ b/boards/arm/cxd56xx/spresense/src/cxd56_alt1250_power.c @@ -65,14 +65,6 @@ static sem_t g_wd_wait; void board_alt1250_poweron(void) { - /* Power on altair modem device */ - - cxd56_gpio_config(ALT1250_LTE_POWER_BUTTON, false); - cxd56_gpio_write(ALT1250_LTE_POWER_BUTTON, false); - - cxd56_gpio_config(ALT1250_SHUTDOWN, false); - cxd56_gpio_write(ALT1250_SHUTDOWN, true); - board_power_control(POWER_LTE, true); } @@ -86,12 +78,40 @@ void board_alt1250_poweron(void) void board_alt1250_poweroff(void) { - /* Power off Altair modem device */ - board_power_control(POWER_LTE, false); +} - cxd56_gpio_write(ALT1250_SHUTDOWN, false); - cxd56_gpio_write(ALT1250_LTE_POWER_BUTTON, false); +/**************************************************************************** + * Name: board_alt1250_powerstatus + * + * Description: + * Get the power status for the Altair modem device on the board. + * + ****************************************************************************/ + +bool board_alt1250_powerstatus(void) +{ + return board_power_monitor(POWER_LTE); +} + +/**************************************************************************** + * Name: board_alt1250_powerkeep + * + * Description: + * Set Modem power keep mode when turning off the board. + * + ****************************************************************************/ + +int board_alt1250_powerkeep(bool enable) +{ + if (enable) + { + return board_unset_reset_gpo(POWER_LTE); + } + else + { + return board_set_reset_gpo(POWER_LTE); + } } /**************************************************************************** @@ -124,7 +144,7 @@ void board_alt1250_reset(void) /* Reset Altair modem device */ - cxd56_gpio_write(ALT1250_SHUTDOWN, false); + board_alt1250_poweroff(); /* ALT1250_SHUTDOWN should be low in the range 101usec to 100msec */ @@ -135,7 +155,7 @@ void board_alt1250_reset(void) nxsem_wait_uninterruptible(&g_wd_wait); - cxd56_gpio_write(ALT1250_SHUTDOWN, true); + board_alt1250_poweron(); nxsem_destroy(&g_wd_wait); } diff --git a/drivers/modem/alt1250/Kconfig b/drivers/modem/alt1250/Kconfig index 74c89b8868..fb81a525c1 100644 --- a/drivers/modem/alt1250/Kconfig +++ b/drivers/modem/alt1250/Kconfig @@ -14,6 +14,34 @@ menuconfig MODEM_ALT1250 if MODEM_ALT1250 +menuconfig MODEM_ALT1250_RESTRICTIONS + bool "ALT1250 modem restrictions [Attention. See help]" + default n + ---help--- + Enable restrict the modem function is at your own risk. + If you don't have enough knowledge of this firmware, + you may get unexpected situation. + +if MODEM_ALT1250_RESTRICTIONS + +config MODEM_ALT1250_DISABLE_PV1 + bool "Disable PV1" + default n + ---help--- + Enable restrict the modem function is at your own risk. + If you don't have enough knowledge of this firmware, + you may get unexpected situation. + +config MODEM_ALT1250_DISABLE_PV4 + bool "Disable PV4" + default n + ---help--- + Enable restrict the modem function is at your own risk. + If you don't have enough knowledge of this firmware, + you may get unexpected situation. + +endif + config MODEM_ALT1250_ADDITIONAL_FUNC bool default n diff --git a/drivers/modem/alt1250/Make.defs b/drivers/modem/alt1250/Make.defs index f1864cdf7f..70daac0906 100644 --- a/drivers/modem/alt1250/Make.defs +++ b/drivers/modem/alt1250/Make.defs @@ -24,7 +24,19 @@ ifeq ($(CONFIG_MODEM_ALT1250),y) CSRCS += alt1250.c CSRCS += altcom_pkt.c CSRCS += altcom_hdlr.c +CSRCS += altcom_hdlr_pdn.c +CSRCS += altcom_hdlr_radio.c +CSRCS += altcom_hdlr_net.c +CSRCS += altcom_hdlr_psave.c +CSRCS += altcom_hdlr_sim.c +CSRCS += altcom_hdlr_pin.c +CSRCS += altcom_hdlr_socket.c +CSRCS += altcom_hdlr_sms.c +CSRCS += altcom_hdlr_firmware.c +CSRCS += altcom_hdlr_log.c +CSRCS += altcom_hdlr_other.c CSRCS += altcom_lwm2m_hdlr.c +CSRCS += altcom_errno.c CSRCS += altmdm.c CSRCS += altmdm_event.c CSRCS += altmdm_spi.c diff --git a/drivers/modem/alt1250/alt1250.c b/drivers/modem/alt1250/alt1250.c index 73ed186539..dcd8a6db6d 100644 --- a/drivers/modem/alt1250/alt1250.c +++ b/drivers/modem/alt1250/alt1250.c @@ -25,11 +25,15 @@ #include #include +#include #include #include #include +#include +#include #include #include +#include #include #include "altcom_pkt.h" @@ -45,6 +49,16 @@ #define rel_evtbufinst(inst, dev) unlock_evtbufinst(inst, dev) +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct alt1250_res_s +{ + sem_t sem; + int code; +}; + /**************************************************************************** * Private Function Prototypes ****************************************************************************/ @@ -60,8 +74,15 @@ 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); +compose_handler_t alt1250_additional_composehdlr(uint32_t, + FAR uint8_t *, size_t); + +#ifdef CONFIG_PM +static int alt1250_pm_prepare(struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate); +static void alt1250_pm_notify(struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate); +#endif /**************************************************************************** * Private Data @@ -84,6 +105,18 @@ static const struct file_operations g_alt1250fops = static uint8_t g_recvbuff[ALTCOM_RX_PKT_SIZE_MAX]; static uint8_t g_sendbuff[ALTCOM_PKT_SIZE_MAX]; +static struct alt1250_dev_s *g_alt1250_dev; + +#ifdef CONFIG_PM +static struct pm_callback_s g_alt1250pmcb = +{ + .notify = alt1250_pm_notify, + .prepare = alt1250_pm_prepare, +}; + +static struct alt1250_res_s g_alt1250_res_s; +#endif + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -244,7 +277,8 @@ static ssize_t read_data(FAR struct alt1250_dev_s *dev, ****************************************************************************/ static void write_evtbitmap(FAR struct alt1250_dev_s *dev, - uint64_t bitmap) + uint64_t bitmap, + FAR struct alt_container_s *container) { nxmutex_lock(&dev->evtmaplock); @@ -255,28 +289,12 @@ static void write_evtbitmap(FAR struct alt1250_dev_s *dev, 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) + if (container) { - dev->evtbitmap = ALT1250_EVTBIT_RESET; + add_list(&dev->replylist, container); } - add_list(&dev->replylist, container); + m_info("write bitmap: 0x%llx\n", bitmap); nxmutex_unlock(&dev->evtmaplock); } @@ -496,8 +514,11 @@ static void write_restart_param(FAR void *outp[], FAR void *buff) * Name: pollnotify ****************************************************************************/ -static void pollnotify(FAR struct alt1250_dev_s *dev) +static void pollnotify(FAR struct alt1250_dev_s *dev, uint64_t bitmap, + FAR struct alt_container_s *container) { + write_evtbitmap(dev, bitmap, container); + nxmutex_lock(&dev->pfdlock); if (dev->pfd != NULL) @@ -551,6 +572,40 @@ parse_handler_t get_parsehdlr(uint16_t altcid, uint8_t altver) return ret; } +#ifdef CONFIG_PM +/**************************************************************************** + * Name: alt1250_send_daemon_request + ****************************************************************************/ + +static int alt1250_send_daemon_request(uint64_t bitmap) +{ + /* Send event for daemon */ + + pollnotify(g_alt1250_dev, bitmap, NULL); + + /* Waiting for daemon response */ + + nxsem_wait_uninterruptible(&g_alt1250_res_s.sem); + + return g_alt1250_res_s.code; +} + +/**************************************************************************** + * Name: alt1250_receive_daemon_response + ****************************************************************************/ + +static void alt1250_receive_daemon_response(FAR struct alt_power_s *req) +{ + /* Store daemon response code */ + + g_alt1250_res_s.code = req->resp; + + /* Post request semaphore */ + + nxsem_post(&g_alt1250_res_s.sem); +} +#endif + /**************************************************************************** * Name: alt1250_power_control ****************************************************************************/ @@ -578,6 +633,25 @@ static int alt1250_power_control(FAR struct alt1250_dev_s *dev, ret = altmdm_give_wlock(); break; + case LTE_CMDID_COUNTWLOCK: + ret = altmdm_count_wlock(); + break; + +#ifdef CONFIG_PM + case LTE_CMDID_STOPAPI: + case LTE_CMDID_SUSPEND: + alt1250_receive_daemon_response(req); + break; +#endif + + case LTE_CMDID_RETRYDISABLE: + ret = altmdm_set_pm_event(EVENT_RETRYREQ, false); + break; + + case LTE_CMDID_GET_POWER_STAT: + ret = altmdm_get_powersupply(dev->lower); + break; + default: ret = -EINVAL; break; @@ -731,23 +805,144 @@ static int exchange_selectcontainer(FAR struct alt1250_dev_s *dev, return OK; } +/**************************************************************************** + * Name: parse_altcompkt + ****************************************************************************/ + +static int parse_altcompkt(FAR struct alt1250_dev_s *dev, FAR uint8_t *pkt, + int pktlen, FAR uint64_t *bitmap, + FAR struct alt_container_s **container) +{ + int ret; + FAR struct altcom_cmdhdr_s *h = (FAR struct altcom_cmdhdr_s *)pkt; + uint16_t cid = parse_cid(h); + uint16_t tid = parse_tid(h); + parse_handler_t parser; + FAR alt_evtbuf_inst_t *inst; + FAR void **outparam; + size_t outparamlen; + + m_info("receive cid:0x%04x tid:0x%04x\n", cid, tid); + + parser = get_parsehdlr(cid, get_altver(h)); + if (is_errind(cid)) + { + /* Get ALTCOM command ID and transaction ID + * from payload + */ + + cid = parse_cid4errind(h); + tid = parse_tid4errind(h); + m_err("ALT1250 does not support this command. cid:0x%04x tid:0x%04x\n", + cid, tid); + cid |= ALTCOM_CMDID_REPLY_BIT; + } + + *container = remove_list(&dev->waitlist, cid, tid); + + m_info("container %sfound. cid:0x%04x tid:0x%04x\n", + *container == NULL ? "not " : "", cid, tid); + + if (parser == NULL) + { + m_err("parser is not found\n"); + + /* If there is a container, use the container to notify + * daemon of the event. Otherwise, discard the event. + */ + + if (*container) + { + (*container)->result = -ENOSYS; + } + + return *container == NULL ? ERROR: OK; + } + + /* Obtain outparam and bitmap required for parser execution arguments. */ + + if (*container) + { + outparam = (*container)->outparam; + outparamlen = (*container)->outparamlen; + *bitmap = get_bitmap(dev, cid, get_altver(h)); + } + else + { + /* The outparam is updated in the parser. Lock until the parser + * returns to prevent outparam from being updated by other tasks. + */ + + inst = get_evtbuffinst_withlock(dev, cid, get_altver(h), bitmap); + if (inst) + { + outparam = inst->outparam; + outparamlen = inst->outparamlen; + } + else + { + /* Error return means that the event will be discarded. */ + + return ERROR; + } + } + + ret = parser(dev, get_payload(h), get_payload_len(h), get_altver(h), + outparam, outparamlen, bitmap); + + if (*container) + { + (*container)->result = ret; + if (LTE_IS_ASYNC_CMD((*container)->cmdid)) + { + /* Asynchronous types need to call the callback corresponding + * to the received event, so the REPLY bit is added to the + * received event. + */ + + *bitmap |= ALT1250_EVTBIT_REPLY; + } + else + { + /* Synchronous types do not call a callback, + * so only the REPLY bit is needed. + */ + + *bitmap = ALT1250_EVTBIT_REPLY; + } + } + else + { + /* Unlock outparam because it has been updated. */ + + unlock_evtbufinst(inst, dev); + if (ret < 0) + { + /* Error return means that the event will be discarded */ + + return ERROR; + } + } + + /* OK return means that the event will be notified to the daemon. */ + + return OK; +} + /**************************************************************************** * Name: altcom_recvthread ****************************************************************************/ -static void altcom_recvthread(FAR void *arg) +static int altcom_recvthread(int argc, FAR char *argv[]) { int ret; - FAR struct alt1250_dev_s *dev = (FAR struct alt1250_dev_s *)arg; + FAR struct alt1250_dev_s *dev = g_alt1250_dev; 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; + uint32_t reason; m_info("recv thread start\n"); @@ -767,7 +962,21 @@ static void altcom_recvthread(FAR void *arg) recvedlen += ret; ret = altcom_is_pkt_ok(g_recvbuff, recvedlen); - if (ret > 0) + if (ret == 0) + { + ret = parse_altcompkt(dev, g_recvbuff, recvedlen, &bitmap, + &container); + if (ret == OK) + { + pollnotify(dev, bitmap, container); + } + else + { + dev->discardcnt++; + m_err("discard event %lu\n", dev->discardcnt); + } + } + else if (ret > 0) { /* Cases in which fragmented packets are received. * Therefore, the receive process is performed again. @@ -777,8 +986,7 @@ static void altcom_recvthread(FAR void *arg) ret); continue; } - - if (ret < 0) + else { /* Forced reset of modem due to packet format error detected */ @@ -786,213 +994,125 @@ static void altcom_recvthread(FAR void *arg) altmdm_reset(); } - else + } + else if (ret == ALTMDM_RETURN_RESET_PKT) + { + m_info("recieve ALTMDM_RETURN_RESET_PKT\n"); + set_senddisable(dev, true); + } + else if (ret == ALTMDM_RETURN_RESET_V1 || + ret == ALTMDM_RETURN_RESET_V4) + { + reason = altmdm_get_reset_reason(); + + m_info("recieve ALTMDM_RETURN_RESET_V%s reason: %d\n", + (ret == ALTMDM_RETURN_RESET_V1) ? "1" : "4", + reason); + +#if defined(CONFIG_MODEM_ALT1250_DISABLE_PV1) && \ + defined(CONFIG_MODEM_ALT1250_DISABLE_PV4) +# error Unsupported configuration. Do not disable both PV1 and PV4. +#endif + +#ifdef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (ret == ALTMDM_RETURN_RESET_V1) { - bool is_discard = false; + m_err("Unsupported ALTCOM Version: V1\n"); + reason = LTE_RESTART_VERSION_ERROR; + } +#endif - /* parse ALTCOM command ID and transaction ID from header */ +#ifdef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (ret == ALTMDM_RETURN_RESET_V4) + { + m_err("Unsupported ALTCOM Version: V4\n"); + reason = LTE_RESTART_VERSION_ERROR; + } +#endif - 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); + ret = write_evtbuff_byidx(dev, 0, write_restart_param, + (FAR void *)&reason); - m_info("receive cid:0x%04x tid:0x%04x\n", cid, tid); + /* If there is a waiting list, + * replace it with the replay list. + */ - /* 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. + head = remove_list_all(&dev->waitlist); + pollnotify(dev, ALT1250_EVTBIT_RESET, head); + } + else if (ret == ALTMDM_RETURN_SUSPENDED) + { + m_info("recieve ALTMDM_RETURN_SUSPENDED\n"); + nxsem_post(&dev->rxthread_sem); + while (1) + { + /* After receiving a suspend event, the ALT1250 driver + * does not accept any requests and must stay alive. */ - 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); - } + sleep(1); } } + else if (ret == ALTMDM_RETURN_EXIT) + { + m_info("recieve ALTMDM_RETURN_EXIT\n"); + is_running = false; + } 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; - } + DEBUGASSERT(0); } recvedlen = 0; } + nxsem_post(&dev->rxthread_sem); + m_info("recv thread end\n"); - pthread_exit(0); + return 0; +} + +/**************************************************************************** + * Name: alt1250_start_rxthread + ****************************************************************************/ + +static int alt1250_start_rxthread(FAR struct alt1250_dev_s *dev, + bool senddisable) +{ + int ret = OK; + + nxmutex_init(&dev->waitlist.lock); + nxmutex_init(&dev->replylist.lock); + nxmutex_init(&dev->evtmaplock); + nxmutex_init(&dev->pfdlock); + nxmutex_init(&dev->senddisablelock); + nxmutex_init(&dev->select_inst.stat_lock); + + sq_init(&dev->waitlist.queue); + sq_init(&dev->replylist.queue); + + dev->senddisable = senddisable; + + ret = kthread_create("altcom_recvthread", + SCHED_PRIORITY_DEFAULT, + CONFIG_DEFAULT_TASK_STACKSIZE, + altcom_recvthread, + (FAR char * const *)NULL); + + if (ret < 0) + { + m_err("kthread create failed: %d\n", errno); + + nxmutex_destroy(&dev->waitlist.lock); + nxmutex_destroy(&dev->replylist.lock); + nxmutex_destroy(&dev->evtmaplock); + nxmutex_destroy(&dev->pfdlock); + nxmutex_destroy(&dev->senddisablelock); + nxmutex_destroy(&dev->select_inst.stat_lock); + } + + return ret; } /**************************************************************************** @@ -1017,7 +1137,8 @@ static int alt1250_open(FAR struct file *filep) if (dev->crefs > 0) { - ret = -EPERM; + nxmutex_unlock(&dev->refslock); + return -EPERM; } /* Increment the count of open references on the driver */ @@ -1026,43 +1147,17 @@ static int alt1250_open(FAR struct file *filep) nxmutex_unlock(&dev->refslock); - if (ret == OK) + if (dev->rxthread_pid < 0) { - nxmutex_init(&dev->waitlist.lock); - nxmutex_init(&dev->replylist.lock); - nxmutex_init(&dev->evtmaplock); - nxmutex_init(&dev->pfdlock); - nxmutex_init(&dev->senddisablelock); - nxmutex_init(&dev->select_inst.stat_lock); + dev->rxthread_pid = alt1250_start_rxthread(dev, true); + } - 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; - - nxmutex_destroy(&dev->waitlist.lock); - nxmutex_destroy(&dev->replylist.lock); - nxmutex_destroy(&dev->evtmaplock); - nxmutex_destroy(&dev->pfdlock); - nxmutex_destroy(&dev->senddisablelock); - nxmutex_destroy(&dev->select_inst.stat_lock); - - nxmutex_lock(&dev->refslock); - dev->crefs--; - nxmutex_unlock(&dev->refslock); - } - else - { - pthread_setname_np(dev->recvthread, "altcom_recvthread"); - } + if (dev->rxthread_pid < 0) + { + ret = dev->rxthread_pid; + nxmutex_lock(&dev->refslock); + dev->crefs--; + nxmutex_unlock(&dev->refslock); } return ret; @@ -1076,7 +1171,6 @@ 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 */ @@ -1090,31 +1184,28 @@ static int alt1250_close(FAR struct file *filep) if (dev->crefs == 0) { - ret = -EPERM; + nxmutex_unlock(&dev->refslock); + return -EPERM; } - else - { - /* Decrement the count of open references on the driver */ - dev->crefs--; - } + /* Decrement the count of open references on the driver */ + + dev->crefs--; nxmutex_unlock(&dev->refslock); - if (ret == OK) - { - nxmutex_destroy(&dev->waitlist.lock); - nxmutex_destroy(&dev->replylist.lock); - nxmutex_destroy(&dev->evtmaplock); - nxmutex_destroy(&dev->pfdlock); - nxmutex_destroy(&dev->senddisablelock); - nxmutex_destroy(&dev->select_inst.stat_lock); + nxmutex_destroy(&dev->waitlist.lock); + nxmutex_destroy(&dev->replylist.lock); + nxmutex_destroy(&dev->evtmaplock); + nxmutex_destroy(&dev->pfdlock); + nxmutex_destroy(&dev->senddisablelock); + nxmutex_destroy(&dev->select_inst.stat_lock); - altmdm_fin(); - pthread_join(dev->recvthread, NULL); - } + altmdm_fin(); + dev->rxthread_pid = -1; + nxsem_wait_uninterruptible(&dev->rxthread_sem); - return ret; + return OK; } /**************************************************************************** @@ -1262,6 +1353,91 @@ errout: return ret; } +#ifdef CONFIG_PM +/**************************************************************************** + * Name: alt1250_pm_prepare + ****************************************************************************/ + +static int alt1250_pm_prepare(struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate) +{ + int ret = OK; + bool power = false; + + /* ALT1250's power management only support BOARD_PM_APPS */ + + if (domain != BOARD_PM_APPS) + { + return OK; + } + + if (pmstate == PM_SLEEP) + { + power = altmdm_get_powersupply(g_alt1250_dev->lower); + + if (!power) + { + /* If the modem doesn't turned on, system can enter sleep */ + + return OK; + } + + ret = alt1250_send_daemon_request(ALT1250_EVTBIT_STOPAPI); + + if (ret) + { + return ERROR; + } + else + { + return OK; + } + } + + return ret; +} + +/**************************************************************************** + * Name: alt1250_pm_notify + ****************************************************************************/ + +static void alt1250_pm_notify(struct pm_callback_s *cb, int domain, + enum pm_state_e pmstate) +{ + bool power; + + /* ALT1250's power management only supports BOARD_PM_APPS */ + + if ((domain == BOARD_PM_APPS) && (pmstate == PM_SLEEP)) + { + power = altmdm_get_powersupply(g_alt1250_dev->lower); + + if (power) + { + /* Set retry mode for SPI driver */ + + altmdm_set_pm_event(EVENT_RETRYREQ, true); + + /* Send suspend request to daemon */ + + alt1250_send_daemon_request(ALT1250_EVTBIT_SUSPEND); + + /* Set suspend mode for SPI driver */ + + altmdm_set_pm_event(EVENT_SUSPEND, true); + + /* Waiting for entering sleep state */ + + nxsem_wait_uninterruptible(&g_alt1250_dev->rxthread_sem); + + /* Enable LTE hibernation mode for wakeup from LTE */ + + g_alt1250_dev->lower->hiber_mode(true); + } + } +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -1288,6 +1464,23 @@ FAR void *alt1250_register(FAR const char *devpath, nxmutex_init(&priv->refslock); + nxsem_init(&priv->rxthread_sem, 0, 0); + + g_alt1250_dev = priv; + +#ifdef CONFIG_PM + ret = pm_register(&g_alt1250pmcb); + + if (ret != OK) + { + m_err("Failed to register PM: %d\n", ret); + kmm_free(priv); + return NULL; + } + + nxsem_init(&g_alt1250_res_s.sem, 0, 0); +#endif + ret = register_driver(devpath, &g_alt1250fops, 0666, priv); if (ret < 0) { @@ -1296,7 +1489,16 @@ FAR void *alt1250_register(FAR const char *devpath, return NULL; } - return priv; + priv->rxthread_pid = -1; + +#ifdef CONFIG_PM + if (altmdm_get_powersupply(priv->lower)) + { + priv->rxthread_pid = alt1250_start_rxthread(priv, false); + } +#endif + + return (FAR void *)priv; } uint64_t get_event_lapibuffer(FAR struct alt1250_dev_s *dev, diff --git a/drivers/modem/alt1250/altcom_cmd.h b/drivers/modem/alt1250/altcom_cmd.h index 3f476b7fde..53e669c1b9 100644 --- a/drivers/modem/alt1250/altcom_cmd.h +++ b/drivers/modem/alt1250/altcom_cmd.h @@ -30,43 +30,23 @@ #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_CELLINFO_CELLID_MAX (503) +#define APICMD_CELLINFO_EARFCN_MAX (262143) +#define APICMD_CELLINFO_DIGIT_NUM_MIN (0) +#define APICMD_CELLINFO_DIGIT_NUM_MAX (9) +#define APICMD_CELLINFO_MNC_DIGIT_MIN (2) +#define APICMD_CELLINFO_GCID_MAX (16) +#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_EDRX_ACTTYPE_NOTUSE (0) /* eDRX is not running */ #define APICMD_EDRX_ACTTYPE_ECGSMIOT (1) /* EC-GSM-IoT (A/Gb mode) */ @@ -81,157 +61,63 @@ #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_IMSCAP_ENABLE (0) +#define APICMD_IMSCAP_DISABLE (1) #define APICMD_NETINFO_PDNCOUNT_MAX (5) -#define APICMD_OPERATOR_LEN 17 -#define APICMD_OPERATOR_LEN_V4 33 +#define APICMD_OPERATOR_LEN_V4 33 -#define APICMD_PDN_IMS_REG (0) -#define APICMD_PDN_IMS_UNREG (1) +#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_DATAALLOW_ALLOW (0) +#define APICMD_PDN_DATAALLOW_DISALLOW (1) -#define APICMD_PDN_DATAROAMALLOW_ALLOW (0) -#define APICMD_PDN_DATAROAMALLOW_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_PDN_DNSCOUNT_MAX (4) +#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_PHONENO_LEN 41 +#define APICMD_SET_REP_EVT_DISABLE (0) +#define APICMD_SET_REP_EVT_ENABLE (1) -#define APICMD_PSM_TIMER_MIN (1) -#define APICMD_PSM_TIMER_MAX (31) +#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_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_SET_REP_EVT_RES_OK (0) +#define APICMD_SET_REP_EVT_RES_ERR (1) -#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_REPORT_EVT_TYPE_LTIME (0) +#define APICMD_REPORT_EVT_TYPE_SIMD (1) +#define APICMD_REPORT_EVT_TYPE_SIMSTATE (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_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 @@ -240,9 +126,6 @@ #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) @@ -258,7 +141,7 @@ begin_packed_struct struct apicmd_ipaddr_s { uint8_t iptype; - uint8_t address[APICMD_PDN_IPADDR_MAXLEN]; + uint8_t address[LTE_IPADDR_MAX_LEN]; } end_packed_struct; begin_packed_struct struct apicmd_pdnset_s @@ -268,7 +151,7 @@ begin_packed_struct struct apicmd_pdnset_s uint32_t apntype; uint8_t ipaddr_num; struct apicmd_ipaddr_s - ip_address[APICMD_PDN_IPCOUNT_MAX]; + ip_address[LTE_PDN_IPADDR_MAX_COUNT]; uint8_t imsregister; uint8_t dataallow; uint8_t dararoamingallow; @@ -281,7 +164,7 @@ begin_packed_struct struct apicmd_pdnset_v4_s uint32_t apntype; uint8_t ipaddr_num; struct apicmd_ipaddr_s - ip_address[APICMD_PDN_IPCOUNT_MAX]; + ip_address[LTE_PDN_IPADDR_MAX_COUNT]; uint8_t imsregister; uint8_t dataallow; uint8_t dararoamingallow; @@ -375,10 +258,10 @@ begin_packed_struct struct apicmd_cmddat_activatepdn_s { uint32_t apntype; uint8_t iptype; - uint8_t apnname[APICMD_ACTIVATEPDN_APNNAME_MAXLEN]; + uint8_t apnname[LTE_APN_LEN]; uint8_t authtype; - uint8_t username[APICMD_ACTIVATEPDN_USERNAME_MAXLEN]; - uint8_t password[APICMD_ACTIVATEPDN_PASSWORD_MAXLEN]; + uint8_t username[LTE_APN_USER_NAME_LEN]; + uint8_t password[LTE_APN_PASSWD_LEN]; } end_packed_struct; begin_packed_struct struct apicmd_cmddat_activatepdnres_s @@ -407,9 +290,9 @@ 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 mcc[LTE_MCC_DIGIT]; uint8_t mnc_digit; - uint8_t mnc[APICMD_CELLINFO_MNC_DIGIT_MAX]; + uint8_t mnc[LTE_MNC_DIGIT_MAX]; } end_packed_struct; begin_packed_struct struct apicmd_cmddat_cellinfo_v4_s @@ -417,9 +300,9 @@ 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 mcc[LTE_MCC_DIGIT]; uint8_t mnc_digit; - uint8_t mnc[APICMD_CELLINFO_MNC_DIGIT_MAX]; + uint8_t mnc[LTE_MNC_DIGIT_MAX]; uint8_t cgid[APICMD_CELLINFO_GCID_MAX + 1]; uint16_t tac; uint16_t time_diffidx; @@ -429,7 +312,7 @@ begin_packed_struct struct apicmd_cmddat_cellinfo_v4_s int16_t rsrq; uint8_t neighbor_num; struct apicmd_cmddat_neighbor_cell_s - neighbor_cell[APICMD_CELLINFO_NEIGHBOR_CELL_NUM_MAX]; + neighbor_cell[LTE_NEIGHBOR_CELL_MAX]; } end_packed_struct; /* structure for APICMDID_DATA_ALLOW */ @@ -602,19 +485,19 @@ 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 mcc[LTE_MCC_DIGIT]; uint8_t mnc_digit; - uint8_t mnc[APICMD_GETSIMINFO_MNC_DIXIT_MAX]; + uint8_t mnc[LTE_MNC_DIGIT_MAX]; uint8_t spn_len; - uint8_t spn[APICMD_GETSIMINFO_SPN_MAX_LEN]; + uint8_t spn[LTE_SIMINFO_SPN_LEN]; uint8_t iccid_len; - uint8_t iccid[APICMD_GETSIMINFO_ICCID_MAX_LEN]; + uint8_t iccid[LTE_SIMINFO_ICCID_LEN]; uint8_t imsi_len; - uint8_t imsi[APICMD_GETSIMINFO_IMSI_LEN]; + uint8_t imsi[LTE_SIMINFO_IMSI_LEN]; uint8_t gid1_len; - uint8_t gid1[APICMD_GETSIMINFO_GID_LEN]; + uint8_t gid1[LTE_SIMINFO_GID_LEN]; uint8_t gid2_len; - uint8_t gid2[APICMD_GETSIMINFO_GID_LEN]; + uint8_t gid2[LTE_SIMINFO_GID_LEN]; } end_packed_struct; /* structure for APICMDID_GET_IMEI */ @@ -622,7 +505,7 @@ begin_packed_struct struct apicmd_cmddat_getsiminfo_res_s begin_packed_struct struct apicmd_cmddat_getimeires_s { uint8_t result; - uint8_t imei[APICMD_IMEI_LEN]; + uint8_t imei[LTE_IMEI_LEN]; } end_packed_struct; /* structure for APICMDID_GET_IMSI */ @@ -631,7 +514,7 @@ begin_packed_struct struct apicmd_cmddat_getimsires_s { uint8_t result; uint8_t errcause; - uint8_t imsi[APICMD_IMSI_LEN]; + uint8_t imsi[LTE_IMSI_LEN]; } end_packed_struct; /* structure for APICMDID_GET_LTIME */ @@ -647,7 +530,7 @@ begin_packed_struct struct apicmd_cmddat_getltimeres_s begin_packed_struct struct apicmd_cmddat_getoperatorres_s { uint8_t result; - uint8_t oper[APICMD_OPERATOR_LEN]; + uint8_t oper[LTE_OPERATOR_LEN]; } end_packed_struct; begin_packed_struct struct apicmd_cmddat_getoperatorres_v4_s @@ -662,7 +545,7 @@ begin_packed_struct struct apicmd_cmddat_phonenores_s { uint8_t result; uint8_t errcause; - uint8_t phoneno[APICMD_PHONENO_LEN]; + uint8_t phoneno[LTE_PHONENO_LEN]; } end_packed_struct; /* structure for APICMDID_RADIO_OFF */ @@ -928,8 +811,8 @@ begin_packed_struct struct apicmd_cmddat_setpsmres_s 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]; + uint8_t bb_product[LTE_VER_BB_PRODUCT_LEN]; + uint8_t np_package[LTE_VER_NP_PACKAGE_LEN]; } end_packed_struct; /* structure for APICMDID_FW_INJECTDELTAIMG */ diff --git a/drivers/modem/alt1250/altcom_errno.c b/drivers/modem/alt1250/altcom_errno.c new file mode 100644 index 0000000000..d52e4ec6ec --- /dev/null +++ b/drivers/modem/alt1250/altcom_errno.c @@ -0,0 +1,217 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_errno.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_errno.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef ARRAY_SZ +# define ARRAY_SZ(array) (sizeof(array)/sizeof(array[0])) +#endif + +#define TABLE_CONTENT(errno_name) { ALTCOM_##errno_name, errno_name } + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +struct converrno_s +{ + int altcom_errno; + int nuttx_errno; +}; + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct converrno_s g_converrno_tbl[] = +{ + TABLE_CONTENT(E2BIG), + TABLE_CONTENT(EACCES), + TABLE_CONTENT(EADDRINUSE), + TABLE_CONTENT(EADDRNOTAVAIL), + TABLE_CONTENT(EADV), + TABLE_CONTENT(EAFNOSUPPORT), + TABLE_CONTENT(EAGAIN), + TABLE_CONTENT(EALREADY), + TABLE_CONTENT(EBADE), + TABLE_CONTENT(EBADF), + TABLE_CONTENT(EBADFD), + TABLE_CONTENT(EBADMSG), + TABLE_CONTENT(EBADR), + TABLE_CONTENT(EBADRQC), + TABLE_CONTENT(EBADSLT), + TABLE_CONTENT(EBFONT), + TABLE_CONTENT(EBUSY), + TABLE_CONTENT(ECANCELED), + TABLE_CONTENT(ECASECLASH), + TABLE_CONTENT(ECHILD), + TABLE_CONTENT(ECHRNG), + TABLE_CONTENT(ECOMM), + TABLE_CONTENT(ECONNABORTED), + TABLE_CONTENT(ECONNREFUSED), + TABLE_CONTENT(ECONNRESET), + TABLE_CONTENT(EDEADLK), + TABLE_CONTENT(EDEADLOCK), + TABLE_CONTENT(EDESTADDRREQ), + TABLE_CONTENT(EDOM), + TABLE_CONTENT(EDOTDOT), + TABLE_CONTENT(EDQUOT), + TABLE_CONTENT(EEXIST), + TABLE_CONTENT(EFAULT), + TABLE_CONTENT(EFBIG), + TABLE_CONTENT(EFTYPE), + TABLE_CONTENT(EHOSTDOWN), + TABLE_CONTENT(EHOSTUNREACH), + TABLE_CONTENT(EIDRM), + TABLE_CONTENT(EILSEQ), + TABLE_CONTENT(EINPROGRESS), + TABLE_CONTENT(EINTR), + TABLE_CONTENT(EINVAL), + TABLE_CONTENT(EIO), + TABLE_CONTENT(EISCONN), + TABLE_CONTENT(EISDIR), + TABLE_CONTENT(EL2HLT), + TABLE_CONTENT(EL2NSYNC), + TABLE_CONTENT(EL3HLT), + TABLE_CONTENT(EL3RST), + TABLE_CONTENT(ELBIN), + TABLE_CONTENT(ELIBACC), + TABLE_CONTENT(ELIBBAD), + TABLE_CONTENT(ELIBEXEC), + TABLE_CONTENT(ELIBMAX), + TABLE_CONTENT(ELIBSCN), + TABLE_CONTENT(ELNRNG), + TABLE_CONTENT(ELOOP), + TABLE_CONTENT(EMFILE), + TABLE_CONTENT(EMLINK), + TABLE_CONTENT(EMSGSIZE), + TABLE_CONTENT(EMULTIHOP), + TABLE_CONTENT(ENAMETOOLONG), + TABLE_CONTENT(ENETDOWN), + TABLE_CONTENT(ENETRESET), + TABLE_CONTENT(ENETUNREACH), + TABLE_CONTENT(ENFILE), + TABLE_CONTENT(ENMFILE), + TABLE_CONTENT(ENOANO), + TABLE_CONTENT(ENOBUFS), + TABLE_CONTENT(ENOCSI), + TABLE_CONTENT(ENODATA), + TABLE_CONTENT(ENODEV), + TABLE_CONTENT(ENOENT), + TABLE_CONTENT(ENOEXEC), + TABLE_CONTENT(ENOLCK), + TABLE_CONTENT(ENOLINK), + TABLE_CONTENT(ENOMEDIUM), + TABLE_CONTENT(ENOMEM), + TABLE_CONTENT(ENOMSG), + TABLE_CONTENT(ENONET), + TABLE_CONTENT(ENOPKG), + TABLE_CONTENT(ENOPROTOOPT), + TABLE_CONTENT(ENOSHARE), + TABLE_CONTENT(ENOSPC), + TABLE_CONTENT(ENOSR), + TABLE_CONTENT(ENOSTR), + TABLE_CONTENT(ENOSYS), + TABLE_CONTENT(ENOTBLK), + TABLE_CONTENT(ENOTCONN), + TABLE_CONTENT(ENOTDIR), + TABLE_CONTENT(ENOTEMPTY), + TABLE_CONTENT(ENOTRECOVERABLE), + TABLE_CONTENT(ENOTSOCK), + TABLE_CONTENT(ENOTSUP), + TABLE_CONTENT(ENOTTY), + TABLE_CONTENT(ENOTUNIQ), + TABLE_CONTENT(ENXIO), + TABLE_CONTENT(EOPNOTSUPP), + TABLE_CONTENT(EOVERFLOW), + TABLE_CONTENT(EOWNERDEAD), + TABLE_CONTENT(EPERM), + TABLE_CONTENT(EPFNOSUPPORT), + TABLE_CONTENT(EPIPE), + TABLE_CONTENT(EPROCLIM), + TABLE_CONTENT(EPROTO), + TABLE_CONTENT(EPROTONOSUPPORT), + TABLE_CONTENT(EPROTOTYPE), + TABLE_CONTENT(ERANGE), + TABLE_CONTENT(EREMCHG), + TABLE_CONTENT(EREMOTE), + TABLE_CONTENT(EROFS), + TABLE_CONTENT(ESHUTDOWN), + TABLE_CONTENT(ESOCKTNOSUPPORT), + TABLE_CONTENT(ESPIPE), + TABLE_CONTENT(ESRCH), + TABLE_CONTENT(ESRMNT), + TABLE_CONTENT(ESTALE), + TABLE_CONTENT(ESTRPIPE), + TABLE_CONTENT(ETIME), + TABLE_CONTENT(ETIMEDOUT), + TABLE_CONTENT(ETOOMANYREFS), + TABLE_CONTENT(ETXTBSY), + TABLE_CONTENT(EUNATCH), + TABLE_CONTENT(EUSERS), + TABLE_CONTENT(EXDEV), + TABLE_CONTENT(EXFULL) +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int altcom_errno2nuttx(int altcom_errno) +{ + int i; + + for (i = 0; i < ARRAY_SZ(g_converrno_tbl); i++) + { + if (g_converrno_tbl[i].altcom_errno == altcom_errno) + { + return g_converrno_tbl[i].nuttx_errno; + } + } + + return altcom_errno; +} + +int altcom_geterrcode(int32_t err_code) +{ + int err; + + err = ntohl(err_code); + if (err < 0) + { + err = altcom_errno2nuttx(-err); + err = -err; + } + + return err; +} + diff --git a/drivers/modem/alt1250/altcom_errno.h b/drivers/modem/alt1250/altcom_errno.h new file mode 100644 index 0000000000..102b6bc93e --- /dev/null +++ b/drivers/modem/alt1250/altcom_errno.h @@ -0,0 +1,201 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_errno.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_ERRNO_H +#define __DRIVERS_MODEM_ALT1250_ALTCOM_ERRNO_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define ALTCOM_EPERM 1 +#define ALTCOM_ENOENT 2 +#define ALTCOM_ESRCH 3 +#define ALTCOM_EINTR 4 +#define ALTCOM_EIO 5 +#define ALTCOM_ENXIO 6 +#define ALTCOM_E2BIG 7 +#define ALTCOM_ENOEXEC 8 +#define ALTCOM_EBADF 9 +#define ALTCOM_ECHILD 10 +#define ALTCOM_EAGAIN 11 +#define ALTCOM_ENOMEM 12 +#define ALTCOM_EACCES 13 +#define ALTCOM_EFAULT 14 +#define ALTCOM_ENOTBLK 15 +#define ALTCOM_EBUSY 16 +#define ALTCOM_EEXIST 17 +#define ALTCOM_EXDEV 18 +#define ALTCOM_ENODEV 19 +#define ALTCOM_ENOTDIR 20 +#define ALTCOM_EISDIR 21 +#define ALTCOM_EINVAL 22 +#define ALTCOM_ENFILE 23 +#define ALTCOM_EMFILE 24 +#define ALTCOM_ENOTTY 25 +#define ALTCOM_ETXTBSY 26 +#define ALTCOM_EFBIG 27 +#define ALTCOM_ENOSPC 28 +#define ALTCOM_ESPIPE 29 +#define ALTCOM_EROFS 30 +#define ALTCOM_EMLINK 31 +#define ALTCOM_EPIPE 32 +#define ALTCOM_EDOM 33 +#define ALTCOM_ERANGE 34 +#define ALTCOM_ENOMSG 35 +#define ALTCOM_EIDRM 36 +#define ALTCOM_ECHRNG 37 +#define ALTCOM_EL2NSYNC 38 +#define ALTCOM_EL3HLT 39 +#define ALTCOM_EL3RST 40 +#define ALTCOM_ELNRNG 41 +#define ALTCOM_EUNATCH 42 +#define ALTCOM_ENOCSI 43 +#define ALTCOM_EL2HLT 44 +#define ALTCOM_EDEADLK 45 +#define ALTCOM_ENOLCK 46 +#define ALTCOM_EBADE 50 +#define ALTCOM_EBADR 51 +#define ALTCOM_EXFULL 52 +#define ALTCOM_ENOANO 53 +#define ALTCOM_EBADRQC 54 +#define ALTCOM_EBADSLT 55 +#define ALTCOM_EDEADLOCK 56 +#define ALTCOM_EBFONT 57 +#define ALTCOM_ENOSTR 60 +#define ALTCOM_ENODATA 61 +#define ALTCOM_ETIME 62 +#define ALTCOM_ENOSR 63 +#define ALTCOM_ENONET 64 +#define ALTCOM_ENOPKG 65 +#define ALTCOM_EREMOTE 66 +#define ALTCOM_ENOLINK 67 +#define ALTCOM_EADV 68 +#define ALTCOM_ESRMNT 69 +#define ALTCOM_ECOMM 70 +#define ALTCOM_EPROTO 71 +#define ALTCOM_EMULTIHOP 74 +#define ALTCOM_ELBIN 75 +#define ALTCOM_EDOTDOT 76 +#define ALTCOM_EBADMSG 77 +#define ALTCOM_EFTYPE 79 +#define ALTCOM_ENOTUNIQ 80 +#define ALTCOM_EBADFD 81 +#define ALTCOM_EREMCHG 82 +#define ALTCOM_ELIBACC 83 +#define ALTCOM_ELIBBAD 84 +#define ALTCOM_ELIBSCN 85 +#define ALTCOM_ELIBMAX 86 +#define ALTCOM_ELIBEXEC 87 +#define ALTCOM_ENOSYS 88 +#define ALTCOM_ENMFILE 89 +#define ALTCOM_ENOTEMPTY 90 +#define ALTCOM_ENAMETOOLONG 91 +#define ALTCOM_ELOOP 92 +#define ALTCOM_EOPNOTSUPP 95 +#define ALTCOM_EPFNOSUPPORT 96 +#define ALTCOM_ECONNRESET 104 +#define ALTCOM_ENOBUFS 105 +#define ALTCOM_EAFNOSUPPORT 106 +#define ALTCOM_EPROTOTYPE 107 +#define ALTCOM_ENOTSOCK 108 +#define ALTCOM_ENOPROTOOPT 109 +#define ALTCOM_ESHUTDOWN 110 +#define ALTCOM_ECONNREFUSED 111 +#define ALTCOM_EADDRINUSE 112 +#define ALTCOM_ECONNABORTED 113 +#define ALTCOM_ENETUNREACH 114 +#define ALTCOM_ENETDOWN 115 +#define ALTCOM_ETIMEDOUT 116 +#define ALTCOM_EHOSTDOWN 117 +#define ALTCOM_EHOSTUNREACH 118 +#define ALTCOM_EINPROGRESS 119 +#define ALTCOM_EALREADY 120 +#define ALTCOM_EDESTADDRREQ 121 +#define ALTCOM_EMSGSIZE 122 +#define ALTCOM_EPROTONOSUPPORT 123 +#define ALTCOM_ESOCKTNOSUPPORT 124 +#define ALTCOM_EADDRNOTAVAIL 125 +#define ALTCOM_ENETRESET 126 +#define ALTCOM_EISCONN 127 +#define ALTCOM_ENOTCONN 128 +#define ALTCOM_ETOOMANYREFS 129 +#define ALTCOM_EPROCLIM 130 +#define ALTCOM_EUSERS 131 +#define ALTCOM_EDQUOT 132 +#define ALTCOM_ESTALE 133 +#define ALTCOM_ENOTSUP 134 +#define ALTCOM_ENOMEDIUM 135 +#define ALTCOM_ENOSHARE 136 +#define ALTCOM_ECASECLASH 137 +#define ALTCOM_EILSEQ 138 +#define ALTCOM_EOVERFLOW 139 +#define ALTCOM_ECANCELED 140 +#define ALTCOM_ENOTRECOVERABLE 141 +#define ALTCOM_EOWNERDEAD 142 +#define ALTCOM_ESTRPIPE 143 +#define ALTCOM_EWOULDBLOCK ALTCOM_EAGAIN + +#define ALTCOM_ERRNO_MIN ALTCOM_EPERM +#define ALTCOM_ERRNO_MAX ALTCOM_ESTRPIPE + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: altcom_errno2nuttx + * + * Description: + * Get Nuttx errno from ALTCOM errno. + * + * Input Parameters: + * altcom_errno - ALTCOM errno. + * + * Returned Value: + * Returns NuttX errno. + * + ****************************************************************************/ + +int altcom_errno2nuttx(int altcom_errno); + +/**************************************************************************** + * Name: altcom_geterrcode + * + * Description: + * Get Nuttx errno from ALTCOM paccket. + * + * Input Parameters: + * err_code - The err_code of the ALTCOM packet. + * + * Returned Value: + * Returns NuttX errno. + * + ****************************************************************************/ + +int altcom_geterrcode(int32_t err_code); + +#endif /* __DRIVERS_MODEM_ALT1250_ALTCOM_ERRNO_H */ diff --git a/drivers/modem/alt1250/altcom_hdlr.c b/drivers/modem/alt1250/altcom_hdlr.c index 17ccfcb1bf..453d447399 100644 --- a/drivers/modem/alt1250/altcom_hdlr.c +++ b/drivers/modem/alt1250/altcom_hdlr.c @@ -23,27 +23,24 @@ ****************************************************************************/ #include + #include -#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" +#include "altcom_hdlr_pdn.h" +#include "altcom_hdlr_radio.h" +#include "altcom_hdlr_net.h" +#include "altcom_hdlr_psave.h" +#include "altcom_hdlr_sim.h" +#include "altcom_hdlr_pin.h" +#include "altcom_hdlr_socket.h" +#include "altcom_hdlr_sms.h" +#include "altcom_hdlr_firmware.h" +#include "altcom_hdlr_log.h" +#include "altcom_hdlr_other.h" /**************************************************************************** * Pre-processor Definitions @@ -53,41 +50,6 @@ # define ARRAY_SZ(array) (sizeof(array)/sizeof(array[0])) #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 ****************************************************************************/ @@ -104,514 +66,6 @@ typedef struct parse_inst_s 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 ****************************************************************************/ @@ -623,5248 +77,152 @@ static int32_t logread_pkt_parse(FAR struct alt1250_dev_s *dev, 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), + CTABLE_CONTENT(GETVER, altcom_getver), + CTABLE_CONTENT(GETPHONE, altcom_getphone), + CTABLE_CONTENT(GETIMSI, altcom_getimsi), + CTABLE_CONTENT(GETIMEI, altcom_getimei), + CTABLE_CONTENT(GETPINSET, altcom_getpinset), + CTABLE_CONTENT(PINENABLE, altcom_setpinlock), + CTABLE_CONTENT(CHANGEPIN, altcom_setpincode), + CTABLE_CONTENT(ENTERPIN, altcom_enterpin), + CTABLE_CONTENT(GETLTIME, altcom_getltime), + CTABLE_CONTENT(GETOPER, altcom_getoper), + CTABLE_CONTENT(REPQUAL, altcom_setrepqual), + CTABLE_CONTENT(REPCELL, altcom_setrepcell), + CTABLE_CONTENT(REPSIMSTAT, altcom_setrepevt), + CTABLE_CONTENT(REPLTIME, altcom_setrepevt), + CTABLE_CONTENT(GETEDRX, altcom_getedrx), + CTABLE_CONTENT(SETEDRX, altcom_setedrx), + CTABLE_CONTENT(GETPSM, altcom_getpsm), + CTABLE_CONTENT(SETPSM, altcom_setpsm), + CTABLE_CONTENT(GETCE, altcom_getce), + CTABLE_CONTENT(SETCE, altcom_setce), + CTABLE_CONTENT(RADIOON, altcom_radioon), + CTABLE_CONTENT(RADIOOFF, altcom_radiooff), + CTABLE_CONTENT(ACTPDN, altcom_actpdn), + CTABLE_CONTENT(DEACTPDN, altcom_deactpdn), + CTABLE_CONTENT(GETNETINFO, altcom_getnetinfo), + CTABLE_CONTENT(IMSCAP, altcom_getimscap), + CTABLE_CONTENT(REPNETINFO, altcom_setrepnet), + CTABLE_CONTENT(GETSIMINFO, altcom_getsiminfo), + CTABLE_CONTENT(GETCEDRX, altcom_getdedrx), + CTABLE_CONTENT(GETCPSM, altcom_getdpsm), + CTABLE_CONTENT(GETQUAL, altcom_getqual), + CTABLE_CONTENT(ACTPDNCAN, altcom_actpdncancel), + CTABLE_CONTENT(GETCELL, altcom_getcell), + CTABLE_CONTENT(GETRAT, altcom_getrat), + CTABLE_CONTENT(GETRATINFO, altcom_getrat), + CTABLE_CONTENT(SETRAT, altcom_setrat), + CTABLE_CONTENT(ACCEPT, altcom_accept), + CTABLE_CONTENT(BIND, altcom_bind), + CTABLE_CONTENT(CLOSE, altcom_close), + CTABLE_CONTENT(CONNECT, altcom_connect), + CTABLE_CONTENT(FCNTL, altcom_fcntl), + CTABLE_CONTENT(GETSOCKNAME, altcom_getsockname), + CTABLE_CONTENT(GETSOCKOPT, altcom_getsockopt), + CTABLE_CONTENT(LISTEN, altcom_listen), + CTABLE_CONTENT(RECVFROM, altcom_recvfrom), + CTABLE_CONTENT(SELECT, altcom_select), + CTABLE_CONTENT(SENDTO, altcom_sendto), + CTABLE_CONTENT(SOCKET, altcom_socket), + CTABLE_CONTENT(SETSOCKOPT, altcom_setsockopt), + CTABLE_CONTENT(SENDATCMD, altcom_sendatcmd), + CTABLE_CONTENT(INJECTIMAGE, altcom_injectimage), + CTABLE_CONTENT(GETIMAGELEN, altcom_getimagelen), + CTABLE_CONTENT(EXEUPDATE, altcom_execupdate), + CTABLE_CONTENT(GETUPDATERES, altcom_getupdateres), + CTABLE_CONTENT(SMS_INIT, altcom_smsinit), + CTABLE_CONTENT(SMS_FIN, altcom_smsfin), + CTABLE_CONTENT(SMS_SEND, altcom_smssend), + CTABLE_CONTENT(SMS_DELETE, altcom_smsdelete), + CTABLE_CONTENT(SMS_REPORT_RECV, altcom_smsreportrecv), + CTABLE_CONTENT(SAVE_LOG, altcom_logsave), + CTABLE_CONTENT(GET_LOGLIST, altcom_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), + CTABLE_CONTENT(LOGOPEN, altcom_logopen), + CTABLE_CONTENT(LOGCLOSE, altcom_logclose), + CTABLE_CONTENT(LOGREAD, altcom_logread), + CTABLE_CONTENT(LOGLSEEK, altcom_loglseek), + CTABLE_CONTENT(LOGREMOVE, altcom_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), + PTABLE_CONTENT(ERRINFO, altcom_errinfo), + PTABLE_CONTENT(GET_VERSION, altcom_getver), + PTABLE_CONTENT(GET_PHONENO, altcom_getphone), + PTABLE_CONTENT(GET_IMSI, altcom_getimsi), + PTABLE_CONTENT(GET_IMEI, altcom_getimei), + PTABLE_CONTENT(GET_PINSET, altcom_getpinset), + PTABLE_CONTENT(SET_PIN_LOCK, altcom_setpinlock), + PTABLE_CONTENT(SET_PIN_CODE, altcom_setpincode), + PTABLE_CONTENT(ENTER_PIN, altcom_enterpin), + PTABLE_CONTENT(GET_LTIME, altcom_getltime), + PTABLE_CONTENT(GET_OPERATOR, altcom_getoper), + PTABLE_CONTENT(SET_REP_QUALITY, altcom_setrepqual), + PTABLE_CONTENT(SET_REP_CELLINFO, altcom_setrepcell), + PTABLE_CONTENT(SET_REP_EVT, altcom_setrepevt), + PTABLE_CONTENT(REPORT_EVT, altcom_repevt), + PTABLE_CONTENT(REPORT_QUALITY, altcom_repqual), + PTABLE_CONTENT(REPORT_CELLINFO, altcom_repcell), + PTABLE_CONTENT(GET_EDRX, altcom_getedrx), + PTABLE_CONTENT(SET_EDRX, altcom_setedrx), + PTABLE_CONTENT(GET_PSM, altcom_getpsm), + PTABLE_CONTENT(SET_PSM, altcom_setpsm), + PTABLE_CONTENT(GET_CE, altcom_getce), + PTABLE_CONTENT(SET_CE, altcom_setce), + PTABLE_CONTENT(RADIO_ON, altcom_radioon), + PTABLE_CONTENT(RADIO_OFF, altcom_radiooff), + PTABLE_CONTENT(ACTIVATE_PDN, altcom_actpdn), + PTABLE_CONTENT(DEACTIVATE_PDN, altcom_deactpdn), + PTABLE_CONTENT(GET_NETINFO, altcom_getnetinfo), + PTABLE_CONTENT(GET_IMS_CAP, altcom_getimscap), + PTABLE_CONTENT(SETREP_NETINFO, altcom_setrepnet), + PTABLE_CONTENT(REPORT_NETINFO, altcom_repnet), + PTABLE_CONTENT(GET_SIMINFO, altcom_getsiminfo), + PTABLE_CONTENT(GET_DYNAMICEDRX, altcom_getdedrx), + PTABLE_CONTENT(GET_DYNAMICPSM, altcom_getdpsm), + PTABLE_CONTENT(GET_QUALITY, altcom_getqual), + PTABLE_CONTENT(ACTIVATE_PDN_CANCEL, altcom_actpdncancel), + PTABLE_CONTENT(GET_CELLINFO, altcom_getcell), + PTABLE_CONTENT(GET_RAT, altcom_getrat), + PTABLE_CONTENT(SET_RAT, altcom_setrat), + PTABLE_CONTENT(SOCK_ACCEPT, altcom_scokaddr), + PTABLE_CONTENT(SOCK_BIND, altcom_sockcomm), + PTABLE_CONTENT(SOCK_CLOSE, altcom_sockcomm), + PTABLE_CONTENT(SOCK_CONNECT, altcom_sockcomm), + PTABLE_CONTENT(SOCK_FCNTL, altcom_sockcomm), + PTABLE_CONTENT(SOCK_GETSOCKNAME, altcom_scokaddr), + PTABLE_CONTENT(SOCK_GETSOCKOPT, altcom_getsockopt), + PTABLE_CONTENT(SOCK_LISTEN, altcom_sockcomm), + PTABLE_CONTENT(SOCK_RECVFROM, altcom_recvfrom), + PTABLE_CONTENT(SOCK_SELECT, altcom_select), + PTABLE_CONTENT(SOCK_SENDTO, altcom_sockcomm), + PTABLE_CONTENT(SOCK_SOCKET, altcom_sockcomm), + PTABLE_CONTENT(SOCK_SETSOCKOPT, altcom_sockcomm), + PTABLE_CONTENT(SEND_ATCMD, altcom_sendatcmd), + PTABLE_CONTENT(FW_INJECTDELTAIMG, altcom_fwcommon), + PTABLE_CONTENT(FW_GETDELTAIMGLEN, altcom_fwcommon), + PTABLE_CONTENT(FW_EXECDELTAUPDATE, altcom_fwcommon), + PTABLE_CONTENT(FW_GETUPDATERESULT, altcom_fwcommon), + PTABLE_CONTENT(SMS_INIT, altcom_smscommon), + PTABLE_CONTENT(SMS_FIN, altcom_smscommon), + PTABLE_CONTENT(SMS_SEND, altcom_smssend), + PTABLE_CONTENT(SMS_DELETE, altcom_smscommon), + PTABLE_CONTENT(SMS_REPORT_RECV, altcom_smsreportrecv), + PTABLE_CONTENT(URC_EVENT, altcom_urc_event), + PTABLE_CONTENT(CLOGS, altcom_logsave), + PTABLE_CONTENT(LOGLIST, altcom_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), + PTABLE_CONTENT(LOGOPEN, altcom_logcommon), + PTABLE_CONTENT(LOGCLOSE, altcom_logcommon), + PTABLE_CONTENT(LOGREAD, altcom_logread), + PTABLE_CONTENT(LOGLSEEK, altcom_logcommon), + PTABLE_CONTENT(LOGREMOVE, altcom_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; - strlcpy(lte_pdn->address[i].address, - (FAR char *)cmd_pdn->ip_address[i].address, - LTE_IPADDR_MAX_LEN); - } - - 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; - strlcpy(lte_pdn->address[i].address, - (FAR char *)cmd_pdn->ip_address[i].address, - LTE_IPADDR_MAX_LEN); - } - - 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; - } - - /* 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)); - strlcpy(version->bb_product, - (FAR const char *)resp->bb_product, LTE_VER_BB_PRODUCT_LEN); - strlcpy(version->np_package, - (FAR const char *)resp->np_package, LTE_VER_NP_PACKAGE_LEN); -} - -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) - { - strlcpy(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; - strlcpy((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; - } - - strlcpy((FAR char *)out->pincode, pincode, sizeof(out->pincode)); - strlcpy((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; - - strlcpy((FAR char *)out->pincode, pincode, sizeof(out->pincode)); - if (new_pincode) - { - out->newpincodeuse = APICMD_ENTERPIN_NEWPINCODE_USE; - strlcpy((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; - - strlcpy((FAR char *)out->apnname, (FAR const char *)apn->apn, - sizeof(out->apnname)); - if (apn->auth_type != LTE_APN_AUTHTYPE_NONE) - { - strlcpy((FAR char *)out->username, (FAR const char *)apn->user_name, - sizeof(out->username)); - strlcpy((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; - } - } - - strlcpy(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; - } - } - - strlcpy(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; - } - } - - strlcpy(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; - } - } - - strlcpy(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; - } - } - - strlcpy(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 ****************************************************************************/ diff --git a/drivers/modem/alt1250/altcom_hdlr_firmware.c b/drivers/modem/alt1250/altcom_hdlr_firmware.c new file mode 100644 index 0000000000..d3a4d8dd6d --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_firmware.c @@ -0,0 +1,257 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_firmware.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_cmd.h" +#include "altcom_errno.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +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); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int32_t altcom_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; +} + +int32_t altcom_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]; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + 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 +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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 +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_FW_GETDELTAIMGLEN; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_FW_GETDELTAIMGLEN_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_FW_EXECDELTAUPDATE; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_FW_EXECDELTAUPDATE_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_FW_GETUPDATERESULT; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_FW_GETUPDATERESULT_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; +} + +int32_t altcom_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 = altcom_geterrcode(in->api_result); + injection_retcode = ntohs(in->ltefw_result); + + return (injection_retcode != 0) ? -injection_retcode : result_cmd; +} diff --git a/drivers/modem/alt1250/altcom_hdlr_firmware.h b/drivers/modem/alt1250/altcom_hdlr_firmware.h new file mode 100644 index 0000000000..c8c6d079aa --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_firmware.h @@ -0,0 +1,65 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_firmware.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_FIRMWARE_H +#define __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_FIRMWARE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int32_t altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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); +int32_t altcom_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); + +#endif /* __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_FIRMWARE_H */ diff --git a/drivers/modem/alt1250/altcom_hdlr_log.c b/drivers/modem/alt1250/altcom_hdlr_log.c new file mode 100644 index 0000000000..93901c2b04 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_log.c @@ -0,0 +1,476 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_log.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 "altcom_cmd_log.h" +#include "altcom_errno.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +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 */ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int32_t altcom_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); + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_CLOGS; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_CLOGS_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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); + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_LOGLIST; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_LOGLIST_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +#ifdef CONFIG_MODEM_ALT1250_LOG_ACCESS + +int32_t altcom_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); + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_LOGOPEN; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_LOGOPEN_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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); + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_LOGCLOSE; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_LOGCLOSE_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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); + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_LOGREAD; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_LOGREAD_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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); + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_LOGLSEEK; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_LOGLSEEK_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; + } + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_LOGREMOVE; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_LOGREMOVE_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +#endif /* CONFIG_MODEM_ALT1250_LOG_ACCESS */ + +int32_t altcom_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 = altcom_geterrcode(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; +} + +int32_t altcom_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 = altcom_geterrcode(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 + +int32_t altcom_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); +} + +int32_t altcom_logread_pkt_parse(FAR struct alt1250_dev_s *dev, + FAR uint8_t *pktbuf, size_t pktsz, + int8_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 */ diff --git a/drivers/modem/alt1250/altcom_hdlr_log.h b/drivers/modem/alt1250/altcom_hdlr_log.h new file mode 100644 index 0000000000..24949eb212 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_log.h @@ -0,0 +1,82 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_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_HDLR_LOG_H +#define __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_LOG_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int32_t altcom_logsave_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 altcom_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 +int32_t altcom_logopen_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 altcom_logclose_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 altcom_logread_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 altcom_loglseek_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 altcom_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 */ +int32_t altcom_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); +int32_t altcom_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 +int32_t altcom_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); +int32_t altcom_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 */ + +#endif /* __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_LOG_H */ diff --git a/drivers/modem/alt1250/altcom_hdlr_net.c b/drivers/modem/alt1250/altcom_hdlr_net.c new file mode 100644 index 0000000000..3bfb9b2822 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_net.c @@ -0,0 +1,1262 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_net.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 "altcom_cmd.h" +#include "alt1250.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define ALTCOMBS_BASE_HEX 16 + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 +static uint16_t g_set_repevt = 0; +#endif + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +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 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; +} + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 +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; +} +#endif + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 +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); + } + } + } + } +} +#endif + +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 parse_ltime(FAR struct apicmd_cmddat_ltime_s *from, + FAR 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; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_LTIME; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_LTIME_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_OPERATOR; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_OPERATOR_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_QUALITY; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_QUALITY_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_CELLINFO_V4; + } + else +#endif + { + size = -ENOTSUP; + } + + return size; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_RAT_V4; + } + else +#endif + { + size = -ENOTSUP; + } + + return size; +} + +int32_t altcom_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; +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + FAR uint8_t *rat = (FAR uint8_t *)arg[0]; + FAR bool *persistent = (FAR bool *)arg[1]; +#endif + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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 +#endif + { + size = -ENOTSUP; + } + + return size; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_IMS_CAP; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_IMS_CAP_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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); + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_SET_REP_QUALITY; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_SET_REP_QUALITY_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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); + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_SET_REP_CELLINFO; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_SET_REP_CELLINFO_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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]; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + 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 + { + return -ENOSYS; + } + + out->event = g_set_repevt; + size = sizeof(struct apicmd_cmddat_setrepevt_s); + *altcid = APICMDID_SET_REP_EVT; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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) + { + out->event = htons(APICMD_SET_REP_EVT_SIMD | + APICMD_SET_REP_EVT_SIMSTATE); + } + else if(*id == LTE_CMDID_REPLTIME) + { + out->event = htons(APICMD_SET_REP_EVT_LTIME); + } + else + { + return -ENOSYS; + } + + out->enability = callback ? APICMD_SET_REP_EVT_ENABLE : + APICMD_SET_REP_EVT_DISABLE; + size = sizeof(struct apicmd_cmddat_setrepevt_v4_s); + *altcid = APICMDID_SET_REP_EVT_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; +} + +int32_t altcom_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]; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + 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 +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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); + } + } + else +#endif + { + return -ENOSYS; + } + + return 0; +} + +int32_t altcom_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]; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + 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 +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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); + } + else +#endif + { + return -ENOSYS; + } + + return 0; +} + +int32_t altcom_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) +{ +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + FAR int *ret = (FAR int *)arg[0]; + FAR lte_cellinfo_t *cellinfo = (FAR lte_cellinfo_t *)arg[1]; +#endif + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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; + } + else +#endif + { + return -ENOSYS; + } + + return 0; +} + +int32_t altcom_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) +{ +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + FAR int *ret = (FAR int *)arg[0]; + FAR lte_ratinfo_t *ratinfo = (FAR lte_ratinfo_t *)arg[1]; +#endif + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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; + } + } + else +#endif + { + return -ENOSYS; + } + + return 0; +} + +int32_t altcom_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) +{ +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + FAR int *ret = (FAR int *)arg[0]; +#endif + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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); + } + } + else +#endif + { + return -ENOSYS; + } + + return 0; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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]; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + 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 +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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); + } + else +#endif + { + return -ENOSYS; + } + + return 0; +} + +int32_t altcom_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]; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + 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 +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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; + } + else +#endif + { + return -ENOSYS; + } + + return 0; +} + +int32_t altcom_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 = -ENOTSUP; + alt_evtbuf_inst_t *inst; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + 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: + { + *bitmap = get_event_lapibuffer(dev, LTE_CMDID_REPLTIME, &inst); + if (*bitmap != 0ULL) + { + FAR lte_localtime_t *ltime = inst->outparam[0]; + parse_ltime(&in->u.ltime, ltime); + ret = 0; + } + } + break; + + case APICMD_REPORT_EVT_TYPE_SIMD: + case APICMD_REPORT_EVT_TYPE_SIMSTATE: + { + *bitmap = get_event_lapibuffer(dev, LTE_CMDID_REPSIMSTAT, + &inst); + if (*bitmap != 0ULL) + { + FAR uint32_t *simstat = inst->outparam[0]; + if (in->type == APICMD_REPORT_EVT_TYPE_SIMD) + { + ret = parse_simd(&in->u.simd, simstat); + } + else + { + ret = parse_simstate(&in->u.simstate, simstat); + } + } + } + break; + + default: + { + m_err("Unsupport event type. type:%d\n", in->type); + ret = -EILSEQ; + } + break; + } + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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: + { + *bitmap = get_event_lapibuffer(dev, LTE_CMDID_REPLTIME, &inst); + if (*bitmap != 0ULL) + { + FAR lte_localtime_t *ltime = inst->outparam[0]; + parse_ltime(&in->u.ltime, ltime); + ret = 0; + } + } + break; + + case APICMD_REPORT_EVT_TYPE_SIMD: + case APICMD_REPORT_EVT_TYPE_SIMSTATE: + { + *bitmap = get_event_lapibuffer(dev, LTE_CMDID_REPSIMSTAT, + &inst); + if (*bitmap != 0ULL) + { + FAR uint32_t *simstat = inst->outparam[0]; + if (ntohs(in->type) == APICMD_REPORT_EVT_TYPE_SIMD) + { + ret = parse_simd(&in->u.simd, simstat); + } + else + { + ret = parse_simstate(&in->u.simstate, simstat); + } + } + } + break; + + default: + { + m_err("Unsupport event type. type:%d\n", + ntohs(in->type)); + ret = -EILSEQ; + } + break; + } + } + else +#endif + { + return -ENOSYS; + } + + return ret; +} diff --git a/drivers/modem/alt1250/altcom_hdlr_net.h b/drivers/modem/alt1250/altcom_hdlr_net.h new file mode 100644 index 0000000000..6a4c41b601 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_net.h @@ -0,0 +1,125 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_net.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_NET_H +#define __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_NET_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int32_t altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); + +#endif /* __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_NET_H */ diff --git a/drivers/modem/alt1250/altcom_hdlr_other.c b/drivers/modem/alt1250/altcom_hdlr_other.c new file mode 100644 index 0000000000..ee463a4bb7 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_other.c @@ -0,0 +1,216 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_other.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 "alt1250.h" +#include "altcom_cmd.h" +#include "altcom_lwm2m_hdlr.h" +#include "altcom_errno.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define ATCMD_HEADER "AT" +#define ATCMD_HEADER_LEN (2) +#define ATCMD_FOOTER '\r' +#define ATCMD_FOOTER_LEN (1) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_IMEI; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_IMEI_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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'; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + size = -ENOTSUP; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_SEND_ATCMD_V4; + } + else +#endif + { + size = -ENOTSUP; + } + + return size; +} + +int32_t altcom_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 = altcom_errno2nuttx(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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + uint32_t lcmdid = 0; + alt_evtbuf_inst_t *inst; + lwm2mstub_hndl_t lwm2m_urc_handler; +#endif + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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); + } + } +#endif + + return ret; +} diff --git a/drivers/modem/alt1250/altcom_hdlr_other.h b/drivers/modem/alt1250/altcom_hdlr_other.h new file mode 100644 index 0000000000..22affad511 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_other.h @@ -0,0 +1,61 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_other.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_OTHER_H +#define __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_OTHER_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int32_t altcom_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 altcom_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 altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); + +#endif /* __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_OTHER_H */ diff --git a/drivers/modem/alt1250/altcom_hdlr_pdn.c b/drivers/modem/alt1250/altcom_hdlr_pdn.c new file mode 100644 index 0000000000..a664ec0a61 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_pdn.c @@ -0,0 +1,650 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_pdn.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_cmd.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 +static 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; +} +#endif + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 +static 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; +} +#endif + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 +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]); + } + } +} +#endif + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 +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); + } + } +} +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int32_t altcom_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); + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_ACTIVATE_PDN; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_ACTIVATE_PDN_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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); + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_DEACTIVATE_PDN; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_DEACTIVATE_PDN_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_ACTIVATE_PDN_CANCEL; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_ACTIVATE_PDN_CANCEL_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_NETINFO; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_NETINFO_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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); + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_SETREP_NETINFO; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_SETREP_NETINFO_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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]; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + 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 +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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; + } + } + else +#endif + { + return -ENOSYS; + } + + return 0; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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]; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + 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 +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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); + } + } + else +#endif + { + return -ENOSYS; + } + + return 0; +} + +int32_t altcom_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; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + 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 +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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); + } + } + } + } + else +#endif + { + return -ENOSYS; + } + + return 0; +} diff --git a/drivers/modem/alt1250/altcom_hdlr_pdn.h b/drivers/modem/alt1250/altcom_hdlr_pdn.h new file mode 100644 index 0000000000..458474a181 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_pdn.h @@ -0,0 +1,81 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_pdn.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_PDN_H +#define __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_PDN_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int32_t altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); + +#endif /* __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_PDN_H */ diff --git a/drivers/modem/alt1250/altcom_hdlr_pin.c b/drivers/modem/alt1250/altcom_hdlr_pin.c new file mode 100644 index 0000000000..e0c8648d11 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_pin.c @@ -0,0 +1,293 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_pin.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_cmd.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +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; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_PINSET; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_PINSET_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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); + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_SET_PIN_LOCK; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_SET_PIN_LOCK_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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); + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_SET_PIN_CODE; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_SET_PIN_CODE_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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); + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_ENTER_PIN; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_ENTER_PIN_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} diff --git a/drivers/modem/alt1250/altcom_hdlr_pin.h b/drivers/modem/alt1250/altcom_hdlr_pin.h new file mode 100644 index 0000000000..4745a90344 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_pin.h @@ -0,0 +1,70 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_pin.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_PIN_H +#define __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_PIN_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int32_t altcom_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 altcom_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 altcom_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 altcom_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 altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); + +#endif /* __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_PIN_H */ diff --git a/drivers/modem/alt1250/altcom_hdlr_psave.c b/drivers/modem/alt1250/altcom_hdlr_psave.c new file mode 100644 index 0000000000..08afb8acda --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_psave.c @@ -0,0 +1,781 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_psave.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_cmd.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#ifndef ARRAY_SZ +# define ARRAY_SZ(array) (sizeof(array)/sizeof(array[0])) +#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_EDRX_INVALID (255) + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +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 Functions + ****************************************************************************/ + +static int32_t altcombs_convert_api_edrx_value( + FAR lte_edrx_setting_t *api_edrx, + FAR 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; + } + + /* act_type check for version V4 or later */ + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + if (api_edrx->act_type == LTE_EDRX_ACTTYPE_WBS1) + { + cmd_edrx->acttype = APICMD_EDRX_ACTTYPE_WBS1; + } + else if (api_edrx->act_type == LTE_EDRX_ACTTYPE_NOTUSE) + { + cmd_edrx->acttype = APICMD_EDRX_ACTTYPE_NOTUSE; + } + else + { + m_err("Operation is not allowed[act_type : %d].\n", + api_edrx->act_type); + return -EPERM; + } + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + if (api_edrx->act_type == LTE_EDRX_ACTTYPE_WBS1) + { + cmd_edrx->acttype = APICMD_EDRX_ACTTYPE_WBS1; + } + else if (api_edrx->act_type == LTE_EDRX_ACTTYPE_NBS1) + { + cmd_edrx->acttype = APICMD_EDRX_ACTTYPE_NBS1; + } + else if (api_edrx->act_type == LTE_EDRX_ACTTYPE_NOTUSE) + { + cmd_edrx->acttype = APICMD_EDRX_ACTTYPE_NOTUSE; + } + else + { + m_err("Operation is not allowed[act_type : %d].\n", + api_edrx->act_type); + return -EPERM; + } + } + else +#endif + { + return -ENOSYS; + } + + if (api_edrx->enable) + { + cmd_edrx->enable = LTE_ENABLE; + + if (APICMD_EDRX_ACTTYPE_WBS1 == cmd_edrx->acttype) + { + if (api_edrx->edrx_cycle <= LTE_EDRX_CYC_262144) + { + cmd_edrx->edrx_cycle = api_edrx->edrx_cycle; + } + else + { + m_err("Invalid cycle :%ld\n", api_edrx->edrx_cycle); + return -EINVAL; + } + + if (api_edrx->ptw_val <= LTE_EDRX_PTW_2048) + { + cmd_edrx->ptw_val = api_edrx->ptw_val; + } + else + { + m_err("Invalid PTW :%ld\n", api_edrx->ptw_val); + return -EINVAL; + } + } + else if (APICMD_EDRX_ACTTYPE_NBS1 == cmd_edrx->acttype) + { + if (api_edrx->edrx_cycle <= LTE_EDRX_CYC_1048576 && + (api_edrx->edrx_cycle == LTE_EDRX_CYC_2048 || + api_edrx->edrx_cycle == LTE_EDRX_CYC_4096 || + api_edrx->edrx_cycle == LTE_EDRX_CYC_8192 || + api_edrx->edrx_cycle >= LTE_EDRX_CYC_16384)) + { + cmd_edrx->edrx_cycle = api_edrx->edrx_cycle; + } + else + { + 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 int32_t altcombs_convert_apicmd_edrx_value( + FAR struct apicmd_edrxset_s *cmd_edrx, FAR lte_edrx_setting_t *api_edrx) +{ + if (!cmd_edrx || !api_edrx) + { + m_err("null param\n"); + return -EINVAL; + } + + if (cmd_edrx->enable == LTE_ENABLE) + { + api_edrx->enable = LTE_ENABLE; + + if (cmd_edrx->acttype == APICMD_EDRX_ACTTYPE_NOTUSE) + { + api_edrx->act_type = LTE_EDRX_ACTTYPE_NOTUSE; + } + else if (cmd_edrx->acttype == APICMD_EDRX_ACTTYPE_WBS1) + { + api_edrx->act_type = LTE_EDRX_ACTTYPE_WBS1; + if (cmd_edrx->edrx_cycle >= ALTCOMBS_EDRX_CYCLE_WBS1_MIN && + cmd_edrx->edrx_cycle <= ALTCOMBS_EDRX_CYCLE_WBS1_MAX) + { + api_edrx->edrx_cycle = cmd_edrx->edrx_cycle; + } + else + { + m_err("Invalid cycle :%d\n", cmd_edrx->edrx_cycle); + return -EINVAL; + } + + if (cmd_edrx->ptw_val >= ALTCOMBS_EDRX_PTW_WBS1_MIN && + cmd_edrx->ptw_val <= ALTCOMBS_EDRX_PTW_WBS1_MAX) + { + api_edrx->ptw_val = cmd_edrx->ptw_val; + } + else + { + m_err("Invalid PTW :%d\n", cmd_edrx->ptw_val); + return -EINVAL; + } + } + else if (cmd_edrx->acttype == APICMD_EDRX_ACTTYPE_NBS1) + { + api_edrx->act_type = LTE_EDRX_ACTTYPE_NBS1; + if (cmd_edrx->edrx_cycle <= LTE_EDRX_CYC_1048576 && + (cmd_edrx->edrx_cycle == LTE_EDRX_CYC_2048 || + cmd_edrx->edrx_cycle == LTE_EDRX_CYC_4096 || + cmd_edrx->edrx_cycle == LTE_EDRX_CYC_8192 || + cmd_edrx->edrx_cycle >= LTE_EDRX_CYC_16384)) + { + api_edrx->edrx_cycle = cmd_edrx->edrx_cycle; + } + else + { + 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) + { + api_edrx->ptw_val = g_edrx_ptw_nbs1_table[cmd_edrx->ptw_val]; + } + else + { + m_err("Invalid PTW :%d\n", cmd_edrx->ptw_val); + return -EINVAL; + } + } + else + { + m_err("Invalid acttype :%d\n", cmd_edrx->acttype); + return -EINVAL; + } + } + else if (cmd_edrx->enable == LTE_DISABLE) + { + api_edrx->enable = LTE_DISABLE; + } + else + { + m_err("Invalid enable :%d\n", cmd_edrx->enable); + return -EINVAL; + } + + 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; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + size = 0; + *altcid = APICMDID_GET_EDRX; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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 +#endif + { + size = -ENOTSUP; + } + + return size; +} + +int32_t altcom_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; + } + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_SET_EDRX; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_SET_EDRX_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + size = 0; + *altcid = APICMDID_GET_DYNAMICEDRX; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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 +#endif + { + size = -ENOTSUP; + } + + return size; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + size = 0; + *altcid = APICMDID_GET_PSM; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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 +#endif + { + size = -ENOTSUP; + } + + return size; +} + +int32_t altcom_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); + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_SET_PSM; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_SET_PSM_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + size = 0; + *altcid = APICMDID_GET_DYNAMICPSM; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + 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 +#endif + { + size = -ENOTSUP; + } + + return size; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_CE; + } + else +#endif + { + size = -ENOTSUP; + } + + return size; +} + +int32_t altcom_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; +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + FAR lte_ce_setting_t *settings = (FAR lte_ce_setting_t *)arg[0]; +#endif + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + 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 +#endif + { + size = -ENOTSUP; + } + + return size; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} diff --git a/drivers/modem/alt1250/altcom_hdlr_psave.h b/drivers/modem/alt1250/altcom_hdlr_psave.h new file mode 100644 index 0000000000..359d56dcb7 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_psave.h @@ -0,0 +1,95 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_psave.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_PSAVE_H +#define __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_PSAVE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int32_t altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); +int32_t altcom_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); + +#endif /* __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_PSAVE_H */ diff --git a/drivers/modem/alt1250/altcom_hdlr_radio.c b/drivers/modem/alt1250/altcom_hdlr_radio.c new file mode 100644 index 0000000000..24ab28b966 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_radio.c @@ -0,0 +1,121 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_radio.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_cmd.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_RADIO_ON; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_RADIO_ON_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_RADIO_OFF; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_RADIO_OFF_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} diff --git a/drivers/modem/alt1250/altcom_hdlr_radio.h b/drivers/modem/alt1250/altcom_hdlr_radio.h new file mode 100644 index 0000000000..cf1791620b --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_radio.h @@ -0,0 +1,53 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_radio.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_RADIO_H +#define __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_RADIO_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int32_t altcom_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 altcom_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 altcom_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); +int32_t altcom_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); + +#endif /* __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_RADIO_H */ diff --git a/drivers/modem/alt1250/altcom_hdlr_sim.c b/drivers/modem/alt1250/altcom_hdlr_sim.c new file mode 100644 index 0000000000..5270dfbd97 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_sim.c @@ -0,0 +1,300 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_sim.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_cmd.h" + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +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); + } +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_PHONENO; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_PHONENO_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_IMSI; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_IMSI_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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); + +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV1 + if (altver == ALTCOM_VER1) + { + *altcid = APICMDID_GET_SIMINFO; + } + else +#endif +#ifndef CONFIG_MODEM_ALT1250_DISABLE_PV4 + if (altver == ALTCOM_VER4) + { + *altcid = APICMDID_GET_SIMINFO_V4; + } + else +#endif + { + size = -ENOSYS; + } + + return size; +} + +int32_t altcom_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; +} + +int32_t altcom_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 LTE_IMSI_LEN includes the null terminator. + */ + + if (*len < strnlen((FAR const char *)in->imsi, LTE_IMSI_LEN)) + { + return -ENOBUFS; + } + } + + strncpy(imsi, (FAR const char *)in->imsi, LTE_IMSI_LEN); + } + + return 0; +} + +int32_t altcom_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; +} diff --git a/drivers/modem/alt1250/altcom_hdlr_sim.h b/drivers/modem/alt1250/altcom_hdlr_sim.h new file mode 100644 index 0000000000..66be84ab72 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_sim.h @@ -0,0 +1,61 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_sim.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_SIM_H +#define __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_SIM_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int32_t altcom_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 altcom_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 altcom_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 altcom_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); +int32_t altcom_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); +int32_t altcom_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); + +#endif /* __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_SIM_H */ diff --git a/drivers/modem/alt1250/altcom_hdlr_sms.c b/drivers/modem/alt1250/altcom_hdlr_sms.c new file mode 100644 index 0000000000..d1b2718c86 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_sms.c @@ -0,0 +1,314 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_sms.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 "altcom_cmd_sms.h" +#include "altcom_errno.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int32_t altcom_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); +} + +int32_t altcom_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; +} + +int32_t altcom_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)) || + (scaddr->addrlen % 2) || (scaddr->addrlen > (SMS_MAX_ADDRLEN * 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; +} + +int32_t altcom_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); +} + +int32_t altcom_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); +} + +int32_t altcom_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 altcom_geterrcode(in->result); +} + +int32_t altcom_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 = altcom_geterrcode(in->result); + + if (sendresult >= 0) + { + refid->nrefid = in->mr_num; + memcpy(refid->refid, in->mr_list, sizeof(refid->refid)); + } + + return (sendresult < 0) ? sendresult : msglen; +} + +int32_t altcom_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; +} diff --git a/drivers/modem/alt1250/altcom_hdlr_sms.h b/drivers/modem/alt1250/altcom_hdlr_sms.h new file mode 100644 index 0000000000..064ccdc8f5 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_sms.h @@ -0,0 +1,67 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_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_HDLR_SMS_H +#define __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_SMS_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int32_t altcom_smsinit_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 altcom_smsfin_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 altcom_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 altcom_smsdelete_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 altcom_smsreportrecv_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 altcom_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); +int32_t altcom_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); +int32_t altcom_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); + +#endif /* __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_SMS_H */ diff --git a/drivers/modem/alt1250/altcom_hdlr_socket.c b/drivers/modem/alt1250/altcom_hdlr_socket.c new file mode 100644 index 0000000000..6556733662 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_socket.c @@ -0,0 +1,1325 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_socket.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 "altcom_cmd_sock.h" +#include "altcom_errno.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +#define READSET_BIT (1 << 0) +#define WRITESET_BIT (1 << 1) +#define EXCEPTSET_BIT (1 << 2) + +#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 Functions + ****************************************************************************/ + +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, FAR 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 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; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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; +} + +int32_t altcom_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 = altcom_errno2nuttx(ntohl(in->err_code)); + + return 0; +} + +int32_t altcom_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 = altcom_errno2nuttx(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; +} + +int32_t altcom_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 = altcom_errno2nuttx(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; +} + +int32_t altcom_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 = altcom_errno2nuttx(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; +} + +int32_t altcom_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 = altcom_errno2nuttx(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; +} diff --git a/drivers/modem/alt1250/altcom_hdlr_socket.h b/drivers/modem/alt1250/altcom_hdlr_socket.h new file mode 100644 index 0000000000..a409878948 --- /dev/null +++ b/drivers/modem/alt1250/altcom_hdlr_socket.h @@ -0,0 +1,101 @@ +/**************************************************************************** + * drivers/modem/alt1250/altcom_hdlr_socket.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_SOCKET_H +#define __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_SOCKET_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +int32_t altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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 altcom_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); +int32_t altcom_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 altcom_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 altcom_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 altcom_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); + +#endif /* __DRIVERS_MODEM_ALT1250_ALTCOM_HDLR_SOCKET_H */ diff --git a/drivers/modem/alt1250/altcom_pkt.h b/drivers/modem/alt1250/altcom_pkt.h index 531af08687..3894be9ffd 100644 --- a/drivers/modem/alt1250/altcom_pkt.h +++ b/drivers/modem/alt1250/altcom_pkt.h @@ -131,7 +131,7 @@ 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); + return ntohs(pkt->cmdid); } static inline uint16_t parse_tid4errind(FAR struct altcom_cmdhdr_s *hdr) @@ -139,7 +139,7 @@ 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); + return ntohs(pkt->transid); } static inline FAR uint8_t *get_payload(FAR struct altcom_cmdhdr_s *hdr) diff --git a/drivers/modem/alt1250/altmdm.c b/drivers/modem/alt1250/altmdm.c index 490b9cf4d6..9d42ac8304 100644 --- a/drivers/modem/alt1250/altmdm.c +++ b/drivers/modem/alt1250/altmdm.c @@ -45,15 +45,6 @@ * 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) @@ -147,6 +138,7 @@ typedef struct altmdm_dev_s int txreq_size; int is_destroy; uint32_t reset_reason; + int retry_mode; } altmdm_dev_t; /**************************************************************************** @@ -162,6 +154,7 @@ 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_hdrsreq(altmdm_state_t state); static int next_state_decidedelay(altmdm_state_t); static int next_state_destroy(altmdm_state_t); @@ -175,6 +168,7 @@ 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_gotsleep(void); static uint32_t waitevt_state_bodysreq(void); static uint32_t waitevt_state_sleeping(void); static uint32_t waitevt_state_delaynext(void); @@ -249,14 +243,14 @@ static const struct state_func_s g_state_func[] = 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(HDRSREQ, hdrsreq, 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(GOTSLEEP, common, gotsleep, gotsleep), TABLE_CONTENT(BACKTOIDLE, common, common, backtoidle), TABLE_CONTENT(RETRECV, common, common, retrecv), TABLE_CONTENT(FORCERST, common, common, forcerst), @@ -418,7 +412,8 @@ static void process_before_poweroff(void) /* clear event without EVENT_POWERON */ - altmdm_event_clear(&g_altmdm_dev.event, (allevt & ~(EVENT_POWERON))); + altmdm_event_clear(&g_altmdm_dev.event, + (allevt & ~(EVENT_POWERON | EVENT_DESTROY))); g_altmdm_dev.lower->irqenable(false); g_altmdm_dev.lower->set_wakeup(false); g_altmdm_dev.lower->set_mready(false); @@ -475,7 +470,7 @@ static int next_state_poweroff(altmdm_state_t state) static uint32_t waitevt_state_poweroff(void) { return altmdm_event_wait(&g_altmdm_dev.event, - EVENT_POWERON | EVENT_DESTROY, false, 0); + EVENT_POWERON | EVENT_DESTROY | EVENT_SUSPEND | EVENT_RESUME, false, 0); } static altmdm_state_t process_state_poweroff(uint32_t event, @@ -488,7 +483,7 @@ static altmdm_state_t process_state_poweroff(uint32_t event, altmdm_event_clear(&g_altmdm_dev.event, EVENT_DESTROY); state = ALTMDM_STATE_DESTORY; } - else if (event & EVENT_POWERON) + else if (event & (EVENT_POWERON | EVENT_SUSPEND | EVENT_RESUME)) { altmdm_event_clear(&g_altmdm_dev.event, EVENT_POWERON); usec2timespec(RESET_INTERVAL, &interval); @@ -510,8 +505,16 @@ static altmdm_state_t process_state_poweroff(uint32_t event, static int next_state_sleep(altmdm_state_t state) { + uint32_t evt = altmdm_event_refer(&g_altmdm_dev.event); + g_altmdm_dev.lower->set_wakeup(false); + if ((evt & EVENT_SUSPEND) != 0) + { + set_return_code(ALTMDM_RETURN_SUSPENDED); + return 1; + } + return 0; } @@ -526,7 +529,7 @@ static uint32_t waitevt_state_sleep(void) event = altmdm_event_wait(&g_altmdm_dev.event, EVENT_TXREQ | EVENT_RXREQ | EVENT_WLOCK | EVENT_POWEROFF | EVENT_RESET | - EVENT_DESTROY, false, 0); + EVENT_DESTROY | EVENT_SUSPEND, false, 0); return event; } @@ -534,6 +537,10 @@ static uint32_t waitevt_state_sleep(void) static altmdm_state_t process_state_sleep(uint32_t event, altmdm_state_t state) { + /* The order of checking the events is related to processing + * priority, so be careful when making changes. + */ + if (event & EVENT_DESTROY) { altmdm_event_clear(&g_altmdm_dev.event, EVENT_DESTROY); @@ -553,6 +560,10 @@ static altmdm_state_t process_state_sleep(uint32_t event, { state = ALTMDM_STATE_IDLE4RST; } + else if (event & EVENT_SUSPEND) + { + state = ALTMDM_STATE_SLEEP; + } else if (event & (EVENT_TXREQ | EVENT_RXREQ)) { state = ALTMDM_STATE_IDLEWTO; @@ -719,13 +730,17 @@ 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, + EVENT_POWEROFF | EVENT_RESET | EVENT_DESTROY | EVENT_SUSPEND, false, TIMEOUT_IDELEWTO_STATE); } static altmdm_state_t process_state_idlewto(uint32_t event, altmdm_state_t state) { + /* The order of checking the events is related to processing + * priority, so be careful when making changes. + */ + if (event & EVENT_DESTROY) { altmdm_event_clear(&g_altmdm_dev.event, EVENT_DESTROY); @@ -741,6 +756,10 @@ static altmdm_state_t process_state_idlewto(uint32_t event, altmdm_event_clear(&g_altmdm_dev.event, EVENT_RESET); state = ALTMDM_STATE_FORCERST; } + else if (event & EVENT_SUSPEND) + { + state = ALTMDM_STATE_SLEEPSET; + } else if (event & EVENT_TXREQ) { state = ALTMDM_STATE_TXPREPARE; @@ -972,6 +991,26 @@ static altmdm_state_t process_state_txreq(uint32_t event, * HDRSREQ state ****************************************************************************/ +static int next_state_hdrsreq(altmdm_state_t state) +{ + uint32_t evt = altmdm_event_refer(&g_altmdm_dev.event); + + if (get_vp() == VP_V4) + { + g_altmdm_dev.retry_mode = (evt & EVENT_RETRYREQ) ? 1 : 0; + if (g_altmdm_dev.retry_mode) + { + altmdm_set_retrypkt(&g_altmdm_dev.tx_pkt); + } + } + else + { + g_altmdm_dev.retry_mode = 0; + } + + return 0; +} + static uint32_t waitevt_state_hdrsreq(void) { return altmdm_event_wait(&g_altmdm_dev.event, @@ -1032,9 +1071,20 @@ static altmdm_state_t process_state_hdrtrx(uint32_t event, else { m_err("[altmdm] Header error. Current State is %d\n", state); - state = ALTMDM_STATE_FORCERST; + if (g_altmdm_dev.retry_mode) + { + state = ALTMDM_STATE_POWEROFF; + } + else + { + state = ALTMDM_STATE_FORCERST; + } } } + else if (is_reset_pkt(&g_altmdm_dev.rx_pkt) && g_altmdm_dev.retry_mode) + { + state = ALTMDM_STATE_POWEROFF; + } else if (is_sleep_pkt(&g_altmdm_dev.tx_pkt)) { state = ALTMDM_STATE_SLEEPPKT; @@ -1129,7 +1179,8 @@ static altmdm_state_t process_state_bodytrx(uint32_t event, { state = ALTMDM_STATE_GOTSLEEP; } - else if (pkt_total_size(&g_altmdm_dev.rx_pkt) != 0) + else if (pkt_total_size(&g_altmdm_dev.rx_pkt) != 0 && + g_altmdm_dev.retry_mode == 0) { state = ALTMDM_STATE_GOTRX; } @@ -1230,16 +1281,39 @@ static altmdm_state_t process_state_gotrst(uint32_t event, * GOTSLEEP state ****************************************************************************/ -static altmdm_state_t process_state_gotsleep(uint32_t event, - altmdm_state_t state) +static uint32_t waitevt_state_gotsleep(void) { - if (altmdm_is_sleeppkt_ok(&g_altmdm_dev.rx_pkt)) + uint32_t evt = altmdm_event_refer(&g_altmdm_dev.event); + + /* GOTSLEEP state only check current event flags for SUSPEND. */ + + if ((evt & EVENT_SUSPEND) != 0) { - state = ALTMDM_STATE_SLEEPING; + return EVENT_SUSPEND; } else { - state = ALTMDM_STATE_DECIDEDELAY; + return 0; + } +} + +static altmdm_state_t process_state_gotsleep(uint32_t event, + altmdm_state_t state) +{ + if (event & EVENT_SUSPEND) + { + state = ALTMDM_STATE_SLEEP; + } + else + { + if (altmdm_is_sleeppkt_ok(&g_altmdm_dev.rx_pkt)) + { + state = ALTMDM_STATE_SLEEPING; + } + else + { + state = ALTMDM_STATE_DECIDEDELAY; + } } return state; @@ -1445,48 +1519,46 @@ int altmdm_init(FAR struct spi_dev_s *spidev, 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; + g_altmdm_dev.retry_mode = 0; lower->irqattach(sready_isr); - next_state_poweroff(g_altmdm_dev.current_state); + if (altmdm_get_powersupply(lower)) + { + /* When the ALT1250 is turned on during initialization, + * it means that the ALT1250 has returned from hibernation. + * After recovery, ALTMDM state is Sleep. + * And this function is supported only when the protocol + * version is PV4. + */ + + g_altmdm_dev.current_state = ALTMDM_STATE_SLEEP; + g_altmdm_dev.vp = VP_V4; + 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); + + altmdm_set_pm_event(EVENT_RETRYREQ, true); + + next_state_sleep(g_altmdm_dev.current_state); + } + else + { + g_altmdm_dev.current_state = ALTMDM_STATE_POWEROFF; + g_altmdm_dev.vp = VP_NO_RESET; + + next_state_poweroff(g_altmdm_dev.current_state); + } return 0; } int altmdm_fin(void) { - int ret = OK; - uint32_t evt; + altmdm_event_set(&g_altmdm_dev.event, EVENT_DESTROY); - 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; + return OK; } int altmdm_poweron(void) @@ -1577,6 +1649,17 @@ int altmdm_poweroff(void) return ret; } +bool altmdm_get_powersupply(FAR const struct alt1250_lower_s *lower) +{ + if (!lower || !lower->powerstatus) + { + m_err("Lower driver not registered.\n"); + return false; + } + + return lower->powerstatus(); +} + int altmdm_reset(void) { nxsem_wait_uninterruptible(&g_altmdm_dev.lock_evt); @@ -1622,11 +1705,8 @@ int altmdm_read(FAR uint8_t *buff, int sz) /* 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); - } + 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); @@ -1723,6 +1803,11 @@ int altmdm_give_wlock(void) return cnt; } +int altmdm_count_wlock(void) +{ + return g_altmdm_dev.wcounter; +} + uint32_t altmdm_get_reset_reason(void) { return get_reset_reason(); @@ -1740,4 +1825,16 @@ uint8_t altmdm_get_protoversion(void) return (uint8_t)vp; } +int altmdm_set_pm_event(uint32_t event, bool enable) +{ + if (enable) + { + return altmdm_event_set(&g_altmdm_dev.event, event); + } + else + { + return altmdm_event_clear(&g_altmdm_dev.event, event); + } +} + #endif diff --git a/drivers/modem/alt1250/altmdm.h b/drivers/modem/alt1250/altmdm.h index b97140f05e..6697d5df7a 100644 --- a/drivers/modem/alt1250/altmdm.h +++ b/drivers/modem/alt1250/altmdm.h @@ -33,12 +33,25 @@ * 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 EVENT_SUSPEND (1 << 8) +#define EVENT_RESUME (1 << 9) +#define EVENT_RETRYREQ (1 << 10) + #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) +#define ALTMDM_RETURN_SUSPENDED (-7) /**************************************************************************** * Public Function Prototypes @@ -151,6 +164,22 @@ int altmdm_take_wlock(void); int altmdm_give_wlock(void); +/**************************************************************************** + * Name: altmdm_count_wlock + * + * Description: + * Returns the count of wakelocks currently acquired. + * + * Input Parameters: + * None + * + * Returned Value: + * Returns the count of wakelocks currently acquired. + * + ****************************************************************************/ + +int altmdm_count_wlock(void); + /**************************************************************************** * Name: altmdm_poweron * @@ -185,6 +214,22 @@ int altmdm_poweron(void); int altmdm_poweroff(void); +/**************************************************************************** + * Name: altmdm_get_powersupply + * + * Description: + * Get the power supply status of the ALT1250. + * + * Input Parameters: + * Lower driver context + * + * Returned Value: + * Returns true on turned on, false is turned off. + * + ****************************************************************************/ + +bool altmdm_get_powersupply(FAR const struct alt1250_lower_s *lower); + /**************************************************************************** * Name: altmdm_reset * @@ -237,4 +282,22 @@ uint32_t altmdm_get_reset_reason(void); uint8_t altmdm_get_protoversion(void); +/**************************************************************************** + * Name: altmdm_set_pm_event + * + * Description: + * Set PM event flag for alt1250 receive thread.. + * + * Input Parameters: + * event - Bitmap of the event to send/clear. + * enable - true: send, false: clear. + * + * Returned Value: + * Returns 0 on success. + * When an error occurs, a negative value is returned. + * + ****************************************************************************/ + +int altmdm_set_pm_event(uint32_t event, bool enable); + #endif /* __DRIVERS_MODEM_ALT1250_ALTMDM_H */ diff --git a/drivers/modem/alt1250/altmdm_spi.c b/drivers/modem/alt1250/altmdm_spi.c index 11132c1d5d..6b18b63330 100644 --- a/drivers/modem/alt1250/altmdm_spi.c +++ b/drivers/modem/alt1250/altmdm_spi.c @@ -87,6 +87,11 @@ void altmdm_set_sleeppkt(FAR altmdm_spipkt_t *pkt) pkt->header |= ALTSPI_SLEEP_BIT; } +void altmdm_set_retrypkt(FAR altmdm_spipkt_t *pkt) +{ + pkt->header |= ALTSPI_BUFFFULL_BIT; +} + bool altmdm_is_valid_spipkt_header(FAR altmdm_spipkt_t *pkt) { uint16_t actual_size; diff --git a/drivers/modem/alt1250/altmdm_spi.h b/drivers/modem/alt1250/altmdm_spi.h index 9f704040bc..d16e7bef7a 100644 --- a/drivers/modem/alt1250/altmdm_spi.h +++ b/drivers/modem/alt1250/altmdm_spi.h @@ -202,6 +202,22 @@ void altmdm_overwrite_body_size(FAR altmdm_spipkt_t *pkt, uint16_t sz); void altmdm_set_sleeppkt(FAR altmdm_spipkt_t *pkt); +/**************************************************************************** + * Name: altmdm_set_retrypkt + * + * Description: + * Set retry packet parameters to SPI packet structure. + * + * Input Parameters: + * pkt - Pointer to SPI packet structure. + * + * Returned Value: + * None + * + ****************************************************************************/ + +void altmdm_set_retrypkt(FAR altmdm_spipkt_t *pkt); + /**************************************************************************** * Name: altmdm_is_valid_spipkt_header * diff --git a/include/nuttx/modem/alt1250.h b/include/nuttx/modem/alt1250.h index 1c2643af50..91fdd7c438 100644 --- a/include/nuttx/modem/alt1250.h +++ b/include/nuttx/modem/alt1250.h @@ -58,8 +58,10 @@ #define ALT1250_IOC_SETEVTBUFF _MODEMIOC(3) #define ALT1250_IOC_EXCHGCONTAINER _MODEMIOC(4) -#define ALT1250_EVTBIT_RESET (1ULL << 63) -#define ALT1250_EVTBIT_REPLY (1ULL << 62) +#define ALT1250_EVTBIT_RESET (1ULL << 63) +#define ALT1250_EVTBIT_REPLY (1ULL << 62) +#define ALT1250_EVTBIT_STOPAPI (1ULL << 61) +#define ALT1250_EVTBIT_SUSPEND (1ULL << 60) /* Number of sockets */ @@ -257,6 +259,7 @@ struct alt_power_s { uint32_t cmdid; + int resp; }; typedef struct alt_container_s @@ -306,6 +309,8 @@ struct alt1250_lower_s { FAR struct spi_dev_s * (*poweron)(void); void (*poweroff)(void); + bool (*powerstatus)(void); + int (*hiber_mode)(bool); void (*reset)(void); void (*irqattach)(xcpt_t handler); void (*irqenable)(bool enable); @@ -339,7 +344,8 @@ struct alt1250_dev_s mutex_t evtmaplock; mutex_t pfdlock; FAR struct pollfd *pfd; - pthread_t recvthread; + int rxthread_pid; + sem_t rxthread_sem; FAR struct alt_evtbuffer_s *evtbuff; uint32_t discardcnt; mutex_t senddisablelock; diff --git a/include/nuttx/net/ioctl.h b/include/nuttx/net/ioctl.h index 9ba5635ab4..2bdfcfa3c7 100644 --- a/include/nuttx/net/ioctl.h +++ b/include/nuttx/net/ioctl.h @@ -122,6 +122,10 @@ #define SIOCACANSTDFILTER _SIOC(0x0030) /* Add hardware-level standard ID filter */ #define SIOCDCANSTDFILTER _SIOC(0x0031) /* Delete hardware-level standard ID filter */ +/* Network socket control ***************************************************/ + +#define SIOCDENYINETSOCK _SIOC(0x0033) /* Deny network socket. */ + /**************************************************************************** * Public Type Definitions ****************************************************************************/ diff --git a/include/nuttx/wireless/lte/lte.h b/include/nuttx/wireless/lte/lte.h index c9590d11d2..a279b0ca6d 100644 --- a/include/nuttx/wireless/lte/lte.h +++ b/include/nuttx/wireless/lte/lte.h @@ -119,24 +119,6 @@ * 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 */ @@ -213,18 +195,6 @@ #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) @@ -333,18 +303,6 @@ #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) */ @@ -485,6 +443,10 @@ #define LTE_RESTART_MODEM_INITIATED (1) +/* Modem restart cause: Modem firmware version error */ + +#define LTE_RESTART_VERSION_ERROR (2) + /* Error indicator for error code */ #define LTE_ERR_INDICATOR_ERRCODE (0x01) @@ -525,18 +487,6 @@ #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 */ @@ -2042,4 +1992,16 @@ typedef void (*get_current_psm_cb_t)(uint32_t result, typedef void (*get_quality_cb_t)(uint32_t result, lte_quality_t *quality); +/* Definition of callback function. + * + * This callback function is used for nitifying a daemon + * context data for resume. + * + * [in] data : Context data body. + * + * [in] size : Context data size + */ + +typedef void (*context_save_cb_t)(uint8_t *data, int size); + #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 index 1f77a658dc..457d531d3f 100644 --- a/include/nuttx/wireless/lte/lte_ioctl.h +++ b/include/nuttx/wireless/lte/lte_ioctl.h @@ -30,6 +30,7 @@ #include #include #include +#include /**************************************************************************** * Pre-processor Definitions @@ -149,6 +150,14 @@ #define LTE_CMDID_LOGREAD _CMDGRP_NORMAL(0x38) #define LTE_CMDID_LOGLSEEK _CMDGRP_NORMAL(0x39) #define LTE_CMDID_LOGREMOVE _CMDGRP_NORMAL(0x3a) +#define LTE_CMDID_STOPAPI _CMDGRP_NORMAL(0x3b) +#define LTE_CMDID_SUSPEND _CMDGRP_NORMAL(0x3c) +#define LTE_CMDID_RESUME _CMDGRP_NORMAL(0x3d) +#define LTE_CMDID_RETRYDISABLE _CMDGRP_POWER(0x3e) +#define LTE_CMDID_GET_POWER_STAT _CMDGRP_POWER(0x3f) +#define LTE_CMDID_SETCTXCB _CMDGRP_NOMDM(0x40) +#define LTE_CMDID_COUNTWLOCK _CMDGRP_POWER(0x41) +#define LTE_CMDID_REPEVT_DUMMY _CMDGRP_EVENT(0x42) #define LTE_CMDID_ACCEPT _CMDGRP_NORMAL(0x50) #define LTE_CMDID_BIND _CMDGRP_NORMAL(0x51) @@ -312,6 +321,12 @@ #define LTE_CMDID_LWM2M_EXECRESP _CMDGRP_LWM2M(0x0119) #define LTE_CMDID_LWM2M_OBSERVEUPDATE _CMDGRP_LWM2M(0x011A) +#define LTE_CMDID_LWM2M_CHANGERAT _CMDGRP_LWM2M(0x011B) +#define LTE_CMDID_LWM2M_GETRAT _CMDGRP_LWM2M(0x011C) + +#define LTE_CMDID_LWM2M_GETQMODE _CMDGRP_LWM2M(0x011D) +#define LTE_CMDID_LWM2M_SETQMODE _CMDGRP_LWM2M(0x011E) + #define IS_LWM2M_EVENT(cid) (\ ((cid) == LTE_CMDID_LWM2M_READ_EVT) || \ ((cid) == LTE_CMDID_LWM2M_WRITE_EVT) || \ @@ -321,6 +336,13 @@ ((cid) == LTE_CMDID_LWM2M_SERVEROP_EVT) || \ ((cid) == LTE_CMDID_LWM2M_FWUP_EVT) ) +#define IS_LTE_REPORT_EVENT(cid) (\ + ((cid) == LTE_CMDID_REPNETINFO) || \ + ((cid) == LTE_CMDID_REPSIMSTAT) || \ + ((cid) == LTE_CMDID_REPLTIME) || \ + ((cid) == LTE_CMDID_REPQUAL) || \ + ((cid) == LTE_CMDID_REPCELL) ) + /**************************************************************************** * Public Types ****************************************************************************/ diff --git a/include/sys/socket.h b/include/sys/socket.h index b27df12f68..d411cbff46 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -96,6 +96,9 @@ * when we just want a socket for performing driver * ioctls. This definition is not POSIX compliant. */ +#define SOCK_SMS 7 /* Support SMS(Short Message Service) socket. + * This definition is not POSIX compliant. + */ #define SOCK_PACKET 10 /* Obsolete and should not be used in new programs */ #define SOCK_CLOEXEC 02000000 /* Atomically set close-on-exec flag for the new @@ -292,6 +295,11 @@ #define SS_ALIGNSIZE (sizeof(FAR struct sockaddr *)) /* Implementation specific desired alignment */ +/* Network socket control */ + +#define DENY_INET_SOCK_ENABLE 0x01 /* Deny to create INET socket */ +#define DENY_INET_SOCK_DISABLE 0x02 /* Not deny to create INET socket */ + /**************************************************************************** * Type Definitions ****************************************************************************/ diff --git a/net/netdev/Kconfig b/net/netdev/Kconfig index d04b7a38ce..6aa4699b51 100644 --- a/net/netdev/Kconfig +++ b/net/netdev/Kconfig @@ -41,6 +41,14 @@ config NETDEV_WIRELESS_IOCTL ---help--- Enable support for wireless device ioctl() commands +config NETDEV_MODEM_LTE_IOCTL + bool "Enable LTE ioctl()" + default n + select NETDEV_IOCTL + depends on MODEM + ---help--- + Enable support for modem device ioctl() commands + config NETDEV_IFINDEX bool "Enable IF index support" default n diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index 638daf70ee..1a88d14c5d 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -70,6 +70,10 @@ # include #endif +#ifdef CONFIG_NETDEV_MODEM_LTE_IOCTL +# include +#endif + #include "arp/arp.h" #include "socket/socket.h" #include "netdev/netdev.h" @@ -1598,6 +1602,9 @@ ssize_t net_ioctl_arglen(int cmd) case SIOCDELRT: return sizeof(struct rtentry); + case SIOCDENYINETSOCK: + return sizeof(uint8_t); + default: #ifdef CONFIG_NETDEV_IOCTL # ifdef CONFIG_NETDEV_WIRELESS_IOCTL @@ -1627,6 +1634,20 @@ ssize_t net_ioctl_arglen(int cmd) return sizeof(struct btreq_s); } # endif + +# ifdef CONFIG_NETDEV_MODEM_LTE_IOCTL + if (_LTEIOCVALID(cmd)) + { + switch (cmd) + { + case SIOCLTECMD: + return sizeof(struct lte_ioctl_data_s); + + default: + return sizeof(struct lte_smsreq_s); + } + } +# endif #endif return -ENOTTY;