net: convert to using newly introduced integer sized types
Convert code to use u{8,16,32,64}_t and s{8,16,32,64}_t instead of C99 integer types. Jira: ZEP-2051 Change-Id: I4ec03eb2183d59ef86ea2c20d956e5d272656837 Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
parent
7f8d2d198b
commit
a509441210
178 changed files with 3306 additions and 3306 deletions
|
@ -23,13 +23,13 @@
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_ETHERNET_LEVEL
|
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_ETHERNET_LEVEL
|
||||||
#include <logging/sys_log.h>
|
#include <logging/sys_log.h>
|
||||||
|
|
||||||
static inline uint32_t eth_read(uint32_t base_addr, uint32_t offset)
|
static inline u32_t eth_read(u32_t base_addr, u32_t offset)
|
||||||
{
|
{
|
||||||
return sys_read32(base_addr + offset);
|
return sys_read32(base_addr + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void eth_write(uint32_t base_addr, uint32_t offset,
|
static inline void eth_write(u32_t base_addr, u32_t offset,
|
||||||
uint32_t val)
|
u32_t val)
|
||||||
{
|
{
|
||||||
sys_write32(val, base_addr + offset);
|
sys_write32(val, base_addr + offset);
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,9 @@ static inline void eth_write(uint32_t base_addr, uint32_t offset,
|
||||||
static void eth_rx(struct device *port)
|
static void eth_rx(struct device *port)
|
||||||
{
|
{
|
||||||
struct eth_runtime *context = port->driver_data;
|
struct eth_runtime *context = port->driver_data;
|
||||||
uint32_t base_addr = context->base_addr;
|
u32_t base_addr = context->base_addr;
|
||||||
struct net_buf *buf;
|
struct net_buf *buf;
|
||||||
uint32_t frm_len = 0;
|
u32_t frm_len = 0;
|
||||||
|
|
||||||
/* Check whether the RX descriptor is still owned by the device. If not,
|
/* Check whether the RX descriptor is still owned by the device. If not,
|
||||||
* process the received frame or an error that may have occurred.
|
* process the received frame or an error that may have occurred.
|
||||||
|
@ -97,7 +97,7 @@ release_desc:
|
||||||
static int eth_tx(struct device *port, struct net_buf *buf)
|
static int eth_tx(struct device *port, struct net_buf *buf)
|
||||||
{
|
{
|
||||||
struct eth_runtime *context = port->driver_data;
|
struct eth_runtime *context = port->driver_data;
|
||||||
uint32_t base_addr = context->base_addr;
|
u32_t base_addr = context->base_addr;
|
||||||
|
|
||||||
/* Wait until the TX descriptor is no longer owned by the device. */
|
/* Wait until the TX descriptor is no longer owned by the device. */
|
||||||
while (context->tx_desc.own == 1) {
|
while (context->tx_desc.own == 1) {
|
||||||
|
@ -135,8 +135,8 @@ static int eth_tx(struct device *port, struct net_buf *buf)
|
||||||
static void eth_dw_isr(struct device *port)
|
static void eth_dw_isr(struct device *port)
|
||||||
{
|
{
|
||||||
struct eth_runtime *context = port->driver_data;
|
struct eth_runtime *context = port->driver_data;
|
||||||
uint32_t base_addr = context->base_addr;
|
u32_t base_addr = context->base_addr;
|
||||||
uint32_t int_status;
|
u32_t int_status;
|
||||||
|
|
||||||
int_status = eth_read(base_addr, REG_ADDR_STATUS);
|
int_status = eth_read(base_addr, REG_ADDR_STATUS);
|
||||||
|
|
||||||
|
@ -186,14 +186,14 @@ static int eth_initialize(struct device *port)
|
||||||
{
|
{
|
||||||
struct eth_runtime *context = port->driver_data;
|
struct eth_runtime *context = port->driver_data;
|
||||||
const struct eth_config *config = port->config->config_info;
|
const struct eth_config *config = port->config->config_info;
|
||||||
uint32_t base_addr;
|
u32_t base_addr;
|
||||||
|
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
uint8_t bytes[6];
|
u8_t bytes[6];
|
||||||
uint8_t pad[2];
|
u8_t pad[2];
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
uint32_t words[2];
|
u32_t words[2];
|
||||||
} mac_addr;
|
} mac_addr;
|
||||||
|
|
||||||
if (!eth_setup(port))
|
if (!eth_setup(port))
|
||||||
|
@ -214,7 +214,7 @@ static int eth_initialize(struct device *port)
|
||||||
context->tx_desc.tdes0 = 0;
|
context->tx_desc.tdes0 = 0;
|
||||||
context->tx_desc.tdes1 = 0;
|
context->tx_desc.tdes1 = 0;
|
||||||
|
|
||||||
context->tx_desc.buf1_ptr = (uint8_t *)context->tx_buf;
|
context->tx_desc.buf1_ptr = (u8_t *)context->tx_buf;
|
||||||
context->tx_desc.tx_end_of_ring = 1;
|
context->tx_desc.tx_end_of_ring = 1;
|
||||||
context->tx_desc.first_seg_in_frm = 1;
|
context->tx_desc.first_seg_in_frm = 1;
|
||||||
context->tx_desc.last_seg_in_frm = 1;
|
context->tx_desc.last_seg_in_frm = 1;
|
||||||
|
@ -224,7 +224,7 @@ static int eth_initialize(struct device *port)
|
||||||
context->rx_desc.rdes0 = 0;
|
context->rx_desc.rdes0 = 0;
|
||||||
context->rx_desc.rdes1 = 0;
|
context->rx_desc.rdes1 = 0;
|
||||||
|
|
||||||
context->rx_desc.buf1_ptr = (uint8_t *)context->rx_buf;
|
context->rx_desc.buf1_ptr = (u8_t *)context->rx_buf;
|
||||||
context->rx_desc.own = 1;
|
context->rx_desc.own = 1;
|
||||||
context->rx_desc.first_desc = 1;
|
context->rx_desc.first_desc = 1;
|
||||||
context->rx_desc.last_desc = 1;
|
context->rx_desc.last_desc = 1;
|
||||||
|
@ -232,8 +232,8 @@ static int eth_initialize(struct device *port)
|
||||||
context->rx_desc.rx_end_of_ring = 1;
|
context->rx_desc.rx_end_of_ring = 1;
|
||||||
|
|
||||||
/* Install transmit and receive descriptors. */
|
/* Install transmit and receive descriptors. */
|
||||||
eth_write(base_addr, REG_ADDR_RX_DESC_LIST, (uint32_t)&context->rx_desc);
|
eth_write(base_addr, REG_ADDR_RX_DESC_LIST, (u32_t)&context->rx_desc);
|
||||||
eth_write(base_addr, REG_ADDR_TX_DESC_LIST, (uint32_t)&context->tx_desc);
|
eth_write(base_addr, REG_ADDR_TX_DESC_LIST, (u32_t)&context->tx_desc);
|
||||||
|
|
||||||
eth_write(base_addr, REG_ADDR_MAC_CONF,
|
eth_write(base_addr, REG_ADDR_MAC_CONF,
|
||||||
/* Set the RMII speed to 100Mbps */
|
/* Set the RMII speed to 100Mbps */
|
||||||
|
|
|
@ -23,7 +23,7 @@ extern "C" {
|
||||||
typedef void (*eth_config_irq_t)(struct device *port);
|
typedef void (*eth_config_irq_t)(struct device *port);
|
||||||
|
|
||||||
struct eth_config {
|
struct eth_config {
|
||||||
uint32_t irq_num;
|
u32_t irq_num;
|
||||||
eth_config_irq_t config_func;
|
eth_config_irq_t config_func;
|
||||||
|
|
||||||
#ifdef CONFIG_ETH_DW_SHARED_IRQ
|
#ifdef CONFIG_ETH_DW_SHARED_IRQ
|
||||||
|
@ -46,54 +46,54 @@ struct eth_tx_desc {
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
/* Only valid in half-duplex mode. */
|
/* Only valid in half-duplex mode. */
|
||||||
uint32_t deferred_bit : 1;
|
u32_t deferred_bit : 1;
|
||||||
uint32_t err_underflow : 1;
|
u32_t err_underflow : 1;
|
||||||
uint32_t err_excess_defer : 1;
|
u32_t err_excess_defer : 1;
|
||||||
uint32_t coll_cnt_slot_num : 4;
|
u32_t coll_cnt_slot_num : 4;
|
||||||
uint32_t vlan_frm : 1;
|
u32_t vlan_frm : 1;
|
||||||
uint32_t err_excess_coll : 1;
|
u32_t err_excess_coll : 1;
|
||||||
uint32_t err_late_coll : 1;
|
u32_t err_late_coll : 1;
|
||||||
uint32_t err_no_carrier : 1;
|
u32_t err_no_carrier : 1;
|
||||||
uint32_t err_carrier_loss : 1;
|
u32_t err_carrier_loss : 1;
|
||||||
uint32_t err_ip_payload : 1;
|
u32_t err_ip_payload : 1;
|
||||||
uint32_t err_frm_flushed : 1;
|
u32_t err_frm_flushed : 1;
|
||||||
uint32_t err_jabber_tout : 1;
|
u32_t err_jabber_tout : 1;
|
||||||
/* OR of all other error bits. */
|
/* OR of all other error bits. */
|
||||||
uint32_t err_summary : 1;
|
u32_t err_summary : 1;
|
||||||
uint32_t err_ip_hdr : 1;
|
u32_t err_ip_hdr : 1;
|
||||||
uint32_t tx_timestamp_stat : 1;
|
u32_t tx_timestamp_stat : 1;
|
||||||
uint32_t vlan_ins_ctrl : 2;
|
u32_t vlan_ins_ctrl : 2;
|
||||||
uint32_t addr2_chained : 1;
|
u32_t addr2_chained : 1;
|
||||||
uint32_t tx_end_of_ring : 1;
|
u32_t tx_end_of_ring : 1;
|
||||||
uint32_t chksum_ins_ctrl : 2;
|
u32_t chksum_ins_ctrl : 2;
|
||||||
uint32_t replace_crc : 1;
|
u32_t replace_crc : 1;
|
||||||
uint32_t tx_timestamp_en : 1;
|
u32_t tx_timestamp_en : 1;
|
||||||
uint32_t dis_pad : 1;
|
u32_t dis_pad : 1;
|
||||||
uint32_t dis_crc : 1;
|
u32_t dis_crc : 1;
|
||||||
uint32_t first_seg_in_frm : 1;
|
u32_t first_seg_in_frm : 1;
|
||||||
uint32_t last_seg_in_frm : 1;
|
u32_t last_seg_in_frm : 1;
|
||||||
uint32_t intr_on_complete : 1;
|
u32_t intr_on_complete : 1;
|
||||||
/* When set, descriptor is owned by DMA. */
|
/* When set, descriptor is owned by DMA. */
|
||||||
uint32_t own : 1;
|
u32_t own : 1;
|
||||||
};
|
};
|
||||||
uint32_t tdes0;
|
u32_t tdes0;
|
||||||
};
|
};
|
||||||
/* Second word of transmit descriptor */
|
/* Second word of transmit descriptor */
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
uint32_t tx_buf1_sz : 13;
|
u32_t tx_buf1_sz : 13;
|
||||||
uint32_t : 3;
|
u32_t : 3;
|
||||||
uint32_t tx_buf2_sz : 13;
|
u32_t tx_buf2_sz : 13;
|
||||||
uint32_t src_addr_ins_ctrl : 3;
|
u32_t src_addr_ins_ctrl : 3;
|
||||||
};
|
};
|
||||||
uint32_t tdes1;
|
u32_t tdes1;
|
||||||
};
|
};
|
||||||
/* Pointer to frame data buffer */
|
/* Pointer to frame data buffer */
|
||||||
uint8_t *buf1_ptr;
|
u8_t *buf1_ptr;
|
||||||
/* Unused, since this driver initializes only a single descriptor for each
|
/* Unused, since this driver initializes only a single descriptor for each
|
||||||
* direction.
|
* direction.
|
||||||
*/
|
*/
|
||||||
uint8_t *buf2_ptr;
|
u8_t *buf2_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Transmit descriptor */
|
/* Transmit descriptor */
|
||||||
|
@ -101,63 +101,63 @@ struct eth_rx_desc {
|
||||||
/* First word of receive descriptor */
|
/* First word of receive descriptor */
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
uint32_t ext_stat : 1;
|
u32_t ext_stat : 1;
|
||||||
uint32_t err_crc : 1;
|
u32_t err_crc : 1;
|
||||||
uint32_t err_dribble_bit : 1;
|
u32_t err_dribble_bit : 1;
|
||||||
uint32_t err_rx_mii : 1;
|
u32_t err_rx_mii : 1;
|
||||||
uint32_t err_rx_wdt : 1;
|
u32_t err_rx_wdt : 1;
|
||||||
uint32_t frm_type : 1;
|
u32_t frm_type : 1;
|
||||||
uint32_t err_late_coll : 1;
|
u32_t err_late_coll : 1;
|
||||||
uint32_t giant_frm : 1;
|
u32_t giant_frm : 1;
|
||||||
uint32_t last_desc : 1;
|
u32_t last_desc : 1;
|
||||||
uint32_t first_desc : 1;
|
u32_t first_desc : 1;
|
||||||
uint32_t vlan_tag : 1;
|
u32_t vlan_tag : 1;
|
||||||
uint32_t err_overflow : 1;
|
u32_t err_overflow : 1;
|
||||||
uint32_t length_err : 1;
|
u32_t length_err : 1;
|
||||||
uint32_t s_addr_filt_fail : 1;
|
u32_t s_addr_filt_fail : 1;
|
||||||
uint32_t err_desc : 1;
|
u32_t err_desc : 1;
|
||||||
uint32_t err_summary : 1;
|
u32_t err_summary : 1;
|
||||||
uint32_t frm_len : 14;
|
u32_t frm_len : 14;
|
||||||
uint32_t d_addr_filt_fail : 1;
|
u32_t d_addr_filt_fail : 1;
|
||||||
uint32_t own : 1;
|
u32_t own : 1;
|
||||||
};
|
};
|
||||||
uint32_t rdes0;
|
u32_t rdes0;
|
||||||
};
|
};
|
||||||
/* Second word of receive descriptor */
|
/* Second word of receive descriptor */
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
uint32_t rx_buf1_sz : 13;
|
u32_t rx_buf1_sz : 13;
|
||||||
uint32_t : 1;
|
u32_t : 1;
|
||||||
uint32_t addr2_chained : 1;
|
u32_t addr2_chained : 1;
|
||||||
uint32_t rx_end_of_ring : 1;
|
u32_t rx_end_of_ring : 1;
|
||||||
uint32_t rx_buf2_sz : 13;
|
u32_t rx_buf2_sz : 13;
|
||||||
uint32_t : 2;
|
u32_t : 2;
|
||||||
uint32_t dis_int_compl : 1;
|
u32_t dis_int_compl : 1;
|
||||||
};
|
};
|
||||||
uint32_t rdes1;
|
u32_t rdes1;
|
||||||
};
|
};
|
||||||
/* Pointer to frame data buffer */
|
/* Pointer to frame data buffer */
|
||||||
uint8_t *buf1_ptr;
|
u8_t *buf1_ptr;
|
||||||
/* Unused, since this driver initializes only a single descriptor for each
|
/* Unused, since this driver initializes only a single descriptor for each
|
||||||
* direction.
|
* direction.
|
||||||
*/
|
*/
|
||||||
uint8_t *buf2_ptr;
|
u8_t *buf2_ptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Driver metadata associated with each Ethernet device */
|
/* Driver metadata associated with each Ethernet device */
|
||||||
struct eth_runtime {
|
struct eth_runtime {
|
||||||
uint32_t base_addr;
|
u32_t base_addr;
|
||||||
#ifdef CONFIG_PCI
|
#ifdef CONFIG_PCI
|
||||||
struct pci_dev_info pci_dev;
|
struct pci_dev_info pci_dev;
|
||||||
#endif /* CONFIG_PCI */
|
#endif /* CONFIG_PCI */
|
||||||
/* Transmit descriptor */
|
/* Transmit descriptor */
|
||||||
volatile struct eth_tx_desc tx_desc;
|
volatile struct eth_tx_desc tx_desc;
|
||||||
/* Transmit DMA packet buffer */
|
/* Transmit DMA packet buffer */
|
||||||
volatile uint8_t tx_buf[UIP_BUFSIZE];
|
volatile u8_t tx_buf[UIP_BUFSIZE];
|
||||||
/* Receive descriptor */
|
/* Receive descriptor */
|
||||||
volatile struct eth_rx_desc rx_desc;
|
volatile struct eth_rx_desc rx_desc;
|
||||||
/* Receive DMA packet buffer */
|
/* Receive DMA packet buffer */
|
||||||
volatile uint8_t rx_buf[UIP_BUFSIZE];
|
volatile u8_t rx_buf[UIP_BUFSIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MMC_DEFAULT_MASK 0xffffffff
|
#define MMC_DEFAULT_MASK 0xffffffff
|
||||||
|
|
|
@ -28,15 +28,15 @@ static void enc28j60_thread_main(void *arg1, void *unused1, void *unused2);
|
||||||
static int eth_enc28j60_soft_reset(struct device *dev)
|
static int eth_enc28j60_soft_reset(struct device *dev)
|
||||||
{
|
{
|
||||||
struct eth_enc28j60_runtime *context = dev->driver_data;
|
struct eth_enc28j60_runtime *context = dev->driver_data;
|
||||||
uint8_t tx_buf[2] = {ENC28J60_SPI_SC, 0xFF};
|
u8_t tx_buf[2] = {ENC28J60_SPI_SC, 0xFF};
|
||||||
|
|
||||||
return spi_write(context->spi, tx_buf, 2);
|
return spi_write(context->spi, tx_buf, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void eth_enc28j60_set_bank(struct device *dev, uint16_t reg_addr)
|
static void eth_enc28j60_set_bank(struct device *dev, u16_t reg_addr)
|
||||||
{
|
{
|
||||||
struct eth_enc28j60_runtime *context = dev->driver_data;
|
struct eth_enc28j60_runtime *context = dev->driver_data;
|
||||||
uint8_t tx_buf[2];
|
u8_t tx_buf[2];
|
||||||
|
|
||||||
k_sem_take(&context->spi_sem, K_FOREVER);
|
k_sem_take(&context->spi_sem, K_FOREVER);
|
||||||
|
|
||||||
|
@ -53,11 +53,11 @@ static void eth_enc28j60_set_bank(struct device *dev, uint16_t reg_addr)
|
||||||
k_sem_give(&context->spi_sem);
|
k_sem_give(&context->spi_sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void eth_enc28j60_write_reg(struct device *dev, uint16_t reg_addr,
|
static void eth_enc28j60_write_reg(struct device *dev, u16_t reg_addr,
|
||||||
uint8_t value)
|
u8_t value)
|
||||||
{
|
{
|
||||||
struct eth_enc28j60_runtime *context = dev->driver_data;
|
struct eth_enc28j60_runtime *context = dev->driver_data;
|
||||||
uint8_t tx_buf[2];
|
u8_t tx_buf[2];
|
||||||
|
|
||||||
k_sem_take(&context->spi_sem, K_FOREVER);
|
k_sem_take(&context->spi_sem, K_FOREVER);
|
||||||
|
|
||||||
|
@ -69,12 +69,12 @@ static void eth_enc28j60_write_reg(struct device *dev, uint16_t reg_addr,
|
||||||
k_sem_give(&context->spi_sem);
|
k_sem_give(&context->spi_sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void eth_enc28j60_read_reg(struct device *dev, uint16_t reg_addr,
|
static void eth_enc28j60_read_reg(struct device *dev, u16_t reg_addr,
|
||||||
uint8_t *value)
|
u8_t *value)
|
||||||
{
|
{
|
||||||
struct eth_enc28j60_runtime *context = dev->driver_data;
|
struct eth_enc28j60_runtime *context = dev->driver_data;
|
||||||
uint8_t tx_size = 2;
|
u8_t tx_size = 2;
|
||||||
uint8_t tx_buf[3];
|
u8_t tx_buf[3];
|
||||||
|
|
||||||
k_sem_take(&context->spi_sem, K_FOREVER);
|
k_sem_take(&context->spi_sem, K_FOREVER);
|
||||||
|
|
||||||
|
@ -92,11 +92,11 @@ static void eth_enc28j60_read_reg(struct device *dev, uint16_t reg_addr,
|
||||||
k_sem_give(&context->spi_sem);
|
k_sem_give(&context->spi_sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void eth_enc28j60_set_eth_reg(struct device *dev, uint16_t reg_addr,
|
static void eth_enc28j60_set_eth_reg(struct device *dev, u16_t reg_addr,
|
||||||
uint8_t value)
|
u8_t value)
|
||||||
{
|
{
|
||||||
struct eth_enc28j60_runtime *context = dev->driver_data;
|
struct eth_enc28j60_runtime *context = dev->driver_data;
|
||||||
uint8_t tx_buf[2];
|
u8_t tx_buf[2];
|
||||||
|
|
||||||
k_sem_take(&context->spi_sem, K_FOREVER);
|
k_sem_take(&context->spi_sem, K_FOREVER);
|
||||||
|
|
||||||
|
@ -109,11 +109,11 @@ static void eth_enc28j60_set_eth_reg(struct device *dev, uint16_t reg_addr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void eth_enc28j60_clear_eth_reg(struct device *dev, uint16_t reg_addr,
|
static void eth_enc28j60_clear_eth_reg(struct device *dev, u16_t reg_addr,
|
||||||
uint8_t value)
|
u8_t value)
|
||||||
{
|
{
|
||||||
struct eth_enc28j60_runtime *context = dev->driver_data;
|
struct eth_enc28j60_runtime *context = dev->driver_data;
|
||||||
uint8_t tx_buf[2];
|
u8_t tx_buf[2];
|
||||||
|
|
||||||
k_sem_take(&context->spi_sem, K_FOREVER);
|
k_sem_take(&context->spi_sem, K_FOREVER);
|
||||||
|
|
||||||
|
@ -125,13 +125,13 @@ static void eth_enc28j60_clear_eth_reg(struct device *dev, uint16_t reg_addr,
|
||||||
k_sem_give(&context->spi_sem);
|
k_sem_give(&context->spi_sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void eth_enc28j60_write_mem(struct device *dev, uint8_t *data_buffer,
|
static void eth_enc28j60_write_mem(struct device *dev, u8_t *data_buffer,
|
||||||
uint16_t buf_len)
|
u16_t buf_len)
|
||||||
{
|
{
|
||||||
struct eth_enc28j60_runtime *context = dev->driver_data;
|
struct eth_enc28j60_runtime *context = dev->driver_data;
|
||||||
uint8_t *index_buf;
|
u8_t *index_buf;
|
||||||
uint16_t num_segments;
|
u16_t num_segments;
|
||||||
uint16_t num_remaining;
|
u16_t num_remaining;
|
||||||
|
|
||||||
index_buf = data_buffer;
|
index_buf = data_buffer;
|
||||||
num_segments = buf_len / MAX_BUFFER_LENGTH;
|
num_segments = buf_len / MAX_BUFFER_LENGTH;
|
||||||
|
@ -156,12 +156,12 @@ static void eth_enc28j60_write_mem(struct device *dev, uint8_t *data_buffer,
|
||||||
k_sem_give(&context->spi_sem);
|
k_sem_give(&context->spi_sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void eth_enc28j60_read_mem(struct device *dev, uint8_t *data_buffer,
|
static void eth_enc28j60_read_mem(struct device *dev, u8_t *data_buffer,
|
||||||
uint16_t buf_len)
|
u16_t buf_len)
|
||||||
{
|
{
|
||||||
struct eth_enc28j60_runtime *context = dev->driver_data;
|
struct eth_enc28j60_runtime *context = dev->driver_data;
|
||||||
uint16_t num_segments;
|
u16_t num_segments;
|
||||||
uint16_t num_remaining;
|
u16_t num_remaining;
|
||||||
|
|
||||||
num_segments = buf_len / MAX_BUFFER_LENGTH;
|
num_segments = buf_len / MAX_BUFFER_LENGTH;
|
||||||
num_remaining = buf_len - MAX_BUFFER_LENGTH * num_segments;
|
num_remaining = buf_len - MAX_BUFFER_LENGTH * num_segments;
|
||||||
|
@ -194,10 +194,10 @@ static void eth_enc28j60_read_mem(struct device *dev, uint8_t *data_buffer,
|
||||||
k_sem_give(&context->spi_sem);
|
k_sem_give(&context->spi_sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void eth_enc28j60_write_phy(struct device *dev, uint16_t reg_addr,
|
static void eth_enc28j60_write_phy(struct device *dev, u16_t reg_addr,
|
||||||
int16_t data)
|
s16_t data)
|
||||||
{
|
{
|
||||||
uint8_t data_mistat;
|
u8_t data_mistat;
|
||||||
|
|
||||||
eth_enc28j60_set_bank(dev, ENC28J60_REG_MIREGADR);
|
eth_enc28j60_set_bank(dev, ENC28J60_REG_MIREGADR);
|
||||||
eth_enc28j60_write_reg(dev, ENC28J60_REG_MIREGADR, reg_addr);
|
eth_enc28j60_write_reg(dev, ENC28J60_REG_MIREGADR, reg_addr);
|
||||||
|
@ -215,7 +215,7 @@ static void eth_enc28j60_write_phy(struct device *dev, uint16_t reg_addr,
|
||||||
|
|
||||||
static void eth_enc28j60_gpio_callback(struct device *dev,
|
static void eth_enc28j60_gpio_callback(struct device *dev,
|
||||||
struct gpio_callback *cb,
|
struct gpio_callback *cb,
|
||||||
uint32_t pins)
|
u32_t pins)
|
||||||
{
|
{
|
||||||
struct eth_enc28j60_runtime *context =
|
struct eth_enc28j60_runtime *context =
|
||||||
CONTAINER_OF(cb, struct eth_enc28j60_runtime, gpio_cb);
|
CONTAINER_OF(cb, struct eth_enc28j60_runtime, gpio_cb);
|
||||||
|
@ -225,7 +225,7 @@ static void eth_enc28j60_gpio_callback(struct device *dev,
|
||||||
|
|
||||||
static void eth_enc28j60_init_buffers(struct device *dev)
|
static void eth_enc28j60_init_buffers(struct device *dev)
|
||||||
{
|
{
|
||||||
uint8_t data_estat;
|
u8_t data_estat;
|
||||||
|
|
||||||
/* Reception buffers initialization */
|
/* Reception buffers initialization */
|
||||||
eth_enc28j60_set_bank(dev, ENC28J60_REG_ERXSTL);
|
eth_enc28j60_set_bank(dev, ENC28J60_REG_ERXSTL);
|
||||||
|
@ -273,7 +273,7 @@ static void eth_enc28j60_init_buffers(struct device *dev)
|
||||||
static void eth_enc28j60_init_mac(struct device *dev)
|
static void eth_enc28j60_init_mac(struct device *dev)
|
||||||
{
|
{
|
||||||
const struct eth_enc28j60_config *config = dev->config->config_info;
|
const struct eth_enc28j60_config *config = dev->config->config_info;
|
||||||
uint8_t data_macon;
|
u8_t data_macon;
|
||||||
|
|
||||||
eth_enc28j60_set_bank(dev, ENC28J60_REG_MACON1);
|
eth_enc28j60_set_bank(dev, ENC28J60_REG_MACON1);
|
||||||
|
|
||||||
|
@ -425,15 +425,15 @@ static int eth_enc28j60_init(struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int eth_enc28j60_tx(struct device *dev, struct net_pkt *pkt,
|
static int eth_enc28j60_tx(struct device *dev, struct net_pkt *pkt,
|
||||||
uint16_t len)
|
u16_t len)
|
||||||
{
|
{
|
||||||
struct eth_enc28j60_runtime *context = dev->driver_data;
|
struct eth_enc28j60_runtime *context = dev->driver_data;
|
||||||
uint16_t tx_bufaddr = ENC28J60_TXSTART;
|
u16_t tx_bufaddr = ENC28J60_TXSTART;
|
||||||
bool first_frag = true;
|
bool first_frag = true;
|
||||||
uint8_t per_packet_control;
|
u8_t per_packet_control;
|
||||||
uint16_t tx_bufaddr_end;
|
u16_t tx_bufaddr_end;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
uint8_t tx_end;
|
u8_t tx_end;
|
||||||
|
|
||||||
k_sem_take(&context->tx_rx_sem, K_FOREVER);
|
k_sem_take(&context->tx_rx_sem, K_FOREVER);
|
||||||
|
|
||||||
|
@ -462,8 +462,8 @@ static int eth_enc28j60_tx(struct device *dev, struct net_pkt *pkt,
|
||||||
eth_enc28j60_write_mem(dev, &per_packet_control, 1);
|
eth_enc28j60_write_mem(dev, &per_packet_control, 1);
|
||||||
|
|
||||||
for (frag = pkt->frags; frag; frag = frag->frags) {
|
for (frag = pkt->frags; frag; frag = frag->frags) {
|
||||||
uint8_t *data_ptr;
|
u8_t *data_ptr;
|
||||||
uint16_t data_len;
|
u16_t data_len;
|
||||||
|
|
||||||
if (first_frag) {
|
if (first_frag) {
|
||||||
data_ptr = net_pkt_ll(pkt);
|
data_ptr = net_pkt_ll(pkt);
|
||||||
|
@ -509,8 +509,8 @@ static int eth_enc28j60_rx(struct device *dev)
|
||||||
{
|
{
|
||||||
const struct eth_enc28j60_config *config = dev->config->config_info;
|
const struct eth_enc28j60_config *config = dev->config->config_info;
|
||||||
struct eth_enc28j60_runtime *context = dev->driver_data;
|
struct eth_enc28j60_runtime *context = dev->driver_data;
|
||||||
uint16_t lengthfr;
|
u16_t lengthfr;
|
||||||
uint8_t counter;
|
u8_t counter;
|
||||||
|
|
||||||
/* Errata 6. The Receive Packet Pending Interrupt Flag (EIR.PKTIF)
|
/* Errata 6. The Receive Packet Pending Interrupt Flag (EIR.PKTIF)
|
||||||
* does not reliably/accurately report the status of pending packet.
|
* does not reliably/accurately report the status of pending packet.
|
||||||
|
@ -523,14 +523,14 @@ static int eth_enc28j60_rx(struct device *dev)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
struct net_buf *pkt_buf = NULL;
|
struct net_buf *pkt_buf = NULL;
|
||||||
uint16_t frm_len = 0;
|
u16_t frm_len = 0;
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
uint16_t next_packet;
|
u16_t next_packet;
|
||||||
uint8_t np[2];
|
u8_t np[2];
|
||||||
|
|
||||||
/* Read address for next packet */
|
/* Read address for next packet */
|
||||||
eth_enc28j60_read_mem(dev, np, 2);
|
eth_enc28j60_read_mem(dev, np, 2);
|
||||||
next_packet = np[0] | (uint16_t)np[1] << 8;
|
next_packet = np[0] | (u16_t)np[1] << 8;
|
||||||
|
|
||||||
/* Errata 14. Even values in ERXRDPT
|
/* Errata 14. Even values in ERXRDPT
|
||||||
* may corrupt receive buffer.
|
* may corrupt receive buffer.
|
||||||
|
@ -559,7 +559,7 @@ static int eth_enc28j60_rx(struct device *dev)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
size_t frag_len;
|
size_t frag_len;
|
||||||
uint8_t *data_ptr;
|
u8_t *data_ptr;
|
||||||
size_t spi_frame_len;
|
size_t spi_frame_len;
|
||||||
|
|
||||||
/* Reserve a data frag to receive the frame */
|
/* Reserve a data frag to receive the frame */
|
||||||
|
@ -629,7 +629,7 @@ static void enc28j60_thread_main(void *arg1, void *unused1, void *unused2)
|
||||||
{
|
{
|
||||||
struct device *dev = (struct device *) arg1;
|
struct device *dev = (struct device *) arg1;
|
||||||
struct eth_enc28j60_runtime *context;
|
struct eth_enc28j60_runtime *context;
|
||||||
uint8_t int_stat;
|
u8_t int_stat;
|
||||||
|
|
||||||
ARG_UNUSED(unused1);
|
ARG_UNUSED(unused1);
|
||||||
ARG_UNUSED(unused2);
|
ARG_UNUSED(unused2);
|
||||||
|
@ -652,7 +652,7 @@ static void enc28j60_thread_main(void *arg1, void *unused1, void *unused2)
|
||||||
|
|
||||||
static int eth_net_tx(struct net_if *iface, struct net_pkt *pkt)
|
static int eth_net_tx(struct net_if *iface, struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
uint16_t len = net_pkt_ll_reserve(pkt) + net_pkt_get_len(pkt);
|
u16_t len = net_pkt_ll_reserve(pkt) + net_pkt_get_len(pkt);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
SYS_LOG_DBG("pkt %p (len %u)", pkt, len);
|
SYS_LOG_DBG("pkt %p (len %u)", pkt, len);
|
||||||
|
@ -667,7 +667,7 @@ static int eth_net_tx(struct net_if *iface, struct net_pkt *pkt)
|
||||||
|
|
||||||
#ifdef CONFIG_ETH_ENC28J60_0
|
#ifdef CONFIG_ETH_ENC28J60_0
|
||||||
|
|
||||||
static uint8_t mac_address_0[6] = { MICROCHIP_OUI_B0,
|
static u8_t mac_address_0[6] = { MICROCHIP_OUI_B0,
|
||||||
MICROCHIP_OUI_B1,
|
MICROCHIP_OUI_B1,
|
||||||
MICROCHIP_OUI_B2,
|
MICROCHIP_OUI_B2,
|
||||||
CONFIG_ETH_ENC28J60_0_MAC3,
|
CONFIG_ETH_ENC28J60_0_MAC3,
|
||||||
|
|
|
@ -215,12 +215,12 @@
|
||||||
|
|
||||||
struct eth_enc28j60_config {
|
struct eth_enc28j60_config {
|
||||||
const char *gpio_port;
|
const char *gpio_port;
|
||||||
uint8_t gpio_pin;
|
u8_t gpio_pin;
|
||||||
const char *spi_port;
|
const char *spi_port;
|
||||||
uint32_t spi_freq;
|
u32_t spi_freq;
|
||||||
uint8_t spi_slave;
|
u8_t spi_slave;
|
||||||
uint8_t full_duplex;
|
u8_t full_duplex;
|
||||||
int32_t timeout;
|
s32_t timeout;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct eth_enc28j60_runtime {
|
struct eth_enc28j60_runtime {
|
||||||
|
@ -229,9 +229,9 @@ struct eth_enc28j60_runtime {
|
||||||
struct device *gpio;
|
struct device *gpio;
|
||||||
struct device *spi;
|
struct device *spi;
|
||||||
struct gpio_callback gpio_cb;
|
struct gpio_callback gpio_cb;
|
||||||
uint8_t mem_buf[MAX_BUFFER_LENGTH + 1];
|
u8_t mem_buf[MAX_BUFFER_LENGTH + 1];
|
||||||
uint8_t tx_tsv[TSV_SIZE];
|
u8_t tx_tsv[TSV_SIZE];
|
||||||
uint8_t rx_rsv[RSV_SIZE];
|
u8_t rx_rsv[RSV_SIZE];
|
||||||
struct k_sem tx_rx_sem;
|
struct k_sem tx_rx_sem;
|
||||||
struct k_sem int_sem;
|
struct k_sem int_sem;
|
||||||
struct k_sem spi_sem;
|
struct k_sem spi_sem;
|
||||||
|
|
|
@ -67,7 +67,7 @@ struct eth_context {
|
||||||
bool link_up;
|
bool link_up;
|
||||||
phy_duplex_t phy_duplex;
|
phy_duplex_t phy_duplex;
|
||||||
phy_speed_t phy_speed;
|
phy_speed_t phy_speed;
|
||||||
uint8_t mac_addr[6];
|
u8_t mac_addr[6];
|
||||||
struct k_work phy_work;
|
struct k_work phy_work;
|
||||||
struct k_delayed_work delayed_phy_work;
|
struct k_delayed_work delayed_phy_work;
|
||||||
/* TODO: FIXME. This Ethernet frame sized buffer is used for
|
/* TODO: FIXME. This Ethernet frame sized buffer is used for
|
||||||
|
@ -82,7 +82,7 @@ struct eth_context {
|
||||||
* bypassing it and writing a more complex driver working
|
* bypassing it and writing a more complex driver working
|
||||||
* directly with hardware).
|
* directly with hardware).
|
||||||
*/
|
*/
|
||||||
uint8_t frame_buf[1500];
|
u8_t frame_buf[1500];
|
||||||
};
|
};
|
||||||
|
|
||||||
static void eth_0_config_func(void);
|
static void eth_0_config_func(void);
|
||||||
|
@ -99,13 +99,13 @@ tx_buffer_desc[CONFIG_ETH_MCUX_TX_BUFFERS];
|
||||||
#define ETH_MCUX_BUFFER_SIZE \
|
#define ETH_MCUX_BUFFER_SIZE \
|
||||||
ROUND_UP(ENET_FRAME_MAX_FRAMELEN, ENET_BUFF_ALIGNMENT)
|
ROUND_UP(ENET_FRAME_MAX_FRAMELEN, ENET_BUFF_ALIGNMENT)
|
||||||
|
|
||||||
static uint8_t __aligned(ENET_BUFF_ALIGNMENT)
|
static u8_t __aligned(ENET_BUFF_ALIGNMENT)
|
||||||
rx_buffer[CONFIG_ETH_MCUX_RX_BUFFERS][ETH_MCUX_BUFFER_SIZE];
|
rx_buffer[CONFIG_ETH_MCUX_RX_BUFFERS][ETH_MCUX_BUFFER_SIZE];
|
||||||
|
|
||||||
static uint8_t __aligned(ENET_BUFF_ALIGNMENT)
|
static u8_t __aligned(ENET_BUFF_ALIGNMENT)
|
||||||
tx_buffer[CONFIG_ETH_MCUX_TX_BUFFERS][ETH_MCUX_BUFFER_SIZE];
|
tx_buffer[CONFIG_ETH_MCUX_TX_BUFFERS][ETH_MCUX_BUFFER_SIZE];
|
||||||
|
|
||||||
static void eth_mcux_decode_duplex_and_speed(uint32_t status,
|
static void eth_mcux_decode_duplex_and_speed(u32_t status,
|
||||||
phy_duplex_t *p_phy_duplex,
|
phy_duplex_t *p_phy_duplex,
|
||||||
phy_speed_t *p_phy_speed)
|
phy_speed_t *p_phy_speed)
|
||||||
{
|
{
|
||||||
|
@ -131,7 +131,7 @@ static void eth_mcux_decode_duplex_and_speed(uint32_t status,
|
||||||
|
|
||||||
static void eth_mcux_phy_enter_reset(struct eth_context *context)
|
static void eth_mcux_phy_enter_reset(struct eth_context *context)
|
||||||
{
|
{
|
||||||
const uint32_t phy_addr = 0;
|
const u32_t phy_addr = 0;
|
||||||
|
|
||||||
/* Reset the PHY. */
|
/* Reset the PHY. */
|
||||||
ENET_StartSMIWrite(ENET, phy_addr, PHY_BASICCONTROL_REG,
|
ENET_StartSMIWrite(ENET, phy_addr, PHY_BASICCONTROL_REG,
|
||||||
|
@ -197,11 +197,11 @@ void eth_mcux_phy_stop(struct eth_context *context)
|
||||||
|
|
||||||
static void eth_mcux_phy_event(struct eth_context *context)
|
static void eth_mcux_phy_event(struct eth_context *context)
|
||||||
{
|
{
|
||||||
uint32_t status;
|
u32_t status;
|
||||||
bool link_up;
|
bool link_up;
|
||||||
phy_duplex_t phy_duplex = kPHY_FullDuplex;
|
phy_duplex_t phy_duplex = kPHY_FullDuplex;
|
||||||
phy_speed_t phy_speed = kPHY_Speed100M;
|
phy_speed_t phy_speed = kPHY_Speed100M;
|
||||||
const uint32_t phy_addr = 0;
|
const u32_t phy_addr = 0;
|
||||||
|
|
||||||
#ifdef CONFIG_ETH_MCUX_PHY_DETAILED_DEBUG
|
#ifdef CONFIG_ETH_MCUX_PHY_DETAILED_DEBUG
|
||||||
SYS_LOG_DBG("phy_state=%s", phy_state_name(context->phy_state));
|
SYS_LOG_DBG("phy_state=%s", phy_state_name(context->phy_state));
|
||||||
|
@ -310,11 +310,11 @@ static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
struct eth_context *context = iface->dev->driver_data;
|
struct eth_context *context = iface->dev->driver_data;
|
||||||
const struct net_buf *frag;
|
const struct net_buf *frag;
|
||||||
uint8_t *dst;
|
u8_t *dst;
|
||||||
status_t status;
|
status_t status;
|
||||||
unsigned int imask;
|
unsigned int imask;
|
||||||
|
|
||||||
uint16_t total_len = net_pkt_ll_reserve(pkt) + net_pkt_get_len(pkt);
|
u16_t total_len = net_pkt_ll_reserve(pkt) + net_pkt_get_len(pkt);
|
||||||
|
|
||||||
k_sem_take(&context->tx_buf_sem, K_FOREVER);
|
k_sem_take(&context->tx_buf_sem, K_FOREVER);
|
||||||
|
|
||||||
|
@ -359,8 +359,8 @@ static void eth_rx(struct device *iface)
|
||||||
{
|
{
|
||||||
struct eth_context *context = iface->driver_data;
|
struct eth_context *context = iface->driver_data;
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
const uint8_t *src;
|
const u8_t *src;
|
||||||
uint32_t frame_length = 0;
|
u32_t frame_length = 0;
|
||||||
status_t status;
|
status_t status;
|
||||||
unsigned int imask;
|
unsigned int imask;
|
||||||
|
|
||||||
|
@ -481,9 +481,9 @@ static void eth_callback(ENET_Type *base, enet_handle_t *handle,
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_ETH_MCUX_0_RANDOM_MAC)
|
#if defined(CONFIG_ETH_MCUX_0_RANDOM_MAC)
|
||||||
static void generate_mac(uint8_t *mac_addr)
|
static void generate_mac(u8_t *mac_addr)
|
||||||
{
|
{
|
||||||
uint32_t entropy;
|
u32_t entropy;
|
||||||
|
|
||||||
entropy = sys_rand32_get();
|
entropy = sys_rand32_get();
|
||||||
|
|
||||||
|
@ -498,7 +498,7 @@ static int eth_0_init(struct device *dev)
|
||||||
{
|
{
|
||||||
struct eth_context *context = dev->driver_data;
|
struct eth_context *context = dev->driver_data;
|
||||||
enet_config_t enet_config;
|
enet_config_t enet_config;
|
||||||
uint32_t sys_clock;
|
u32_t sys_clock;
|
||||||
enet_buffer_config_t buffer_config = {
|
enet_buffer_config_t buffer_config = {
|
||||||
.rxBdNumber = CONFIG_ETH_MCUX_RX_BUFFERS,
|
.rxBdNumber = CONFIG_ETH_MCUX_RX_BUFFERS,
|
||||||
.txBdNumber = CONFIG_ETH_MCUX_TX_BUFFERS,
|
.txBdNumber = CONFIG_ETH_MCUX_TX_BUFFERS,
|
||||||
|
@ -596,7 +596,7 @@ static void eth_mcux_error_isr(void *p)
|
||||||
{
|
{
|
||||||
struct device *dev = p;
|
struct device *dev = p;
|
||||||
struct eth_context *context = dev->driver_data;
|
struct eth_context *context = dev->driver_data;
|
||||||
uint32_t pending = ENET_GetInterruptStatus(ENET);
|
u32_t pending = ENET_GetInterruptStatus(ENET);
|
||||||
|
|
||||||
if (pending & ENET_EIR_MII_MASK) {
|
if (pending & ENET_EIR_MII_MASK) {
|
||||||
k_work_submit(&context->phy_work);
|
k_work_submit(&context->phy_work);
|
||||||
|
|
|
@ -93,9 +93,9 @@ static void ring_buf_reset(struct ring_buf *rb)
|
||||||
/*
|
/*
|
||||||
* Get one 32 bit item from the ring buffer
|
* Get one 32 bit item from the ring buffer
|
||||||
*/
|
*/
|
||||||
static uint32_t ring_buf_get(struct ring_buf *rb)
|
static u32_t ring_buf_get(struct ring_buf *rb)
|
||||||
{
|
{
|
||||||
uint32_t val;
|
u32_t val;
|
||||||
|
|
||||||
__ASSERT(rb->tail != rb->head,
|
__ASSERT(rb->tail != rb->head,
|
||||||
"retrieving data from empty ring buffer");
|
"retrieving data from empty ring buffer");
|
||||||
|
@ -109,7 +109,7 @@ static uint32_t ring_buf_get(struct ring_buf *rb)
|
||||||
/*
|
/*
|
||||||
* Put one 32 bit item into the ring buffer
|
* Put one 32 bit item into the ring buffer
|
||||||
*/
|
*/
|
||||||
static void ring_buf_put(struct ring_buf *rb, uint32_t val)
|
static void ring_buf_put(struct ring_buf *rb, u32_t val)
|
||||||
{
|
{
|
||||||
rb->buf[rb->head] = val;
|
rb->buf[rb->head] = val;
|
||||||
MODULO_INC(rb->head, rb->len);
|
MODULO_INC(rb->head, rb->len);
|
||||||
|
@ -136,8 +136,8 @@ static void free_rx_bufs(struct ring_buf *rx_pkt_list)
|
||||||
/*
|
/*
|
||||||
* Set MAC Address for frame filtering logic
|
* Set MAC Address for frame filtering logic
|
||||||
*/
|
*/
|
||||||
static void mac_addr_set(Gmac *gmac, uint8_t index,
|
static void mac_addr_set(Gmac *gmac, u8_t index,
|
||||||
uint8_t mac_addr[6])
|
u8_t mac_addr[6])
|
||||||
{
|
{
|
||||||
__ASSERT(index < 4, "index has to be in the range 0..3");
|
__ASSERT(index < 4, "index has to be in the range 0..3");
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ static int rx_descriptors_init(Gmac *gmac, struct gmac_queue *queue)
|
||||||
struct gmac_desc_list *rx_desc_list = &queue->rx_desc_list;
|
struct gmac_desc_list *rx_desc_list = &queue->rx_desc_list;
|
||||||
struct ring_buf *rx_pkt_list = &queue->rx_pkt_list;
|
struct ring_buf *rx_pkt_list = &queue->rx_pkt_list;
|
||||||
struct net_buf *rx_buf;
|
struct net_buf *rx_buf;
|
||||||
uint8_t *rx_buf_addr;
|
u8_t *rx_buf_addr;
|
||||||
|
|
||||||
__ASSERT_NO_MSG(rx_pkt_list->buf);
|
__ASSERT_NO_MSG(rx_pkt_list->buf);
|
||||||
|
|
||||||
|
@ -172,15 +172,15 @@ static int rx_descriptors_init(Gmac *gmac, struct gmac_queue *queue)
|
||||||
return -ENOBUFS;
|
return -ENOBUFS;
|
||||||
}
|
}
|
||||||
|
|
||||||
rx_pkt_list->buf[i] = (uint32_t)rx_buf;
|
rx_pkt_list->buf[i] = (u32_t)rx_buf;
|
||||||
|
|
||||||
rx_buf_addr = rx_buf->data;
|
rx_buf_addr = rx_buf->data;
|
||||||
__ASSERT(!((uint32_t)rx_buf_addr & ~GMAC_RXW0_ADDR),
|
__ASSERT(!((u32_t)rx_buf_addr & ~GMAC_RXW0_ADDR),
|
||||||
"Misaligned RX buffer address");
|
"Misaligned RX buffer address");
|
||||||
__ASSERT(rx_buf->size == CONFIG_NET_BUF_DATA_SIZE,
|
__ASSERT(rx_buf->size == CONFIG_NET_BUF_DATA_SIZE,
|
||||||
"Incorrect length of RX data buffer");
|
"Incorrect length of RX data buffer");
|
||||||
/* Give ownership to GMAC and remove the wrap bit */
|
/* Give ownership to GMAC and remove the wrap bit */
|
||||||
rx_desc_list->buf[i].w0 = (uint32_t)rx_buf_addr & GMAC_RXW0_ADDR;
|
rx_desc_list->buf[i].w0 = (u32_t)rx_buf_addr & GMAC_RXW0_ADDR;
|
||||||
rx_desc_list->buf[i].w1 = 0;
|
rx_desc_list->buf[i].w1 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +293,7 @@ static void rx_error_handler(Gmac *gmac, struct gmac_queue *queue)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set Receive Buffer Queue Pointer Register */
|
/* Set Receive Buffer Queue Pointer Register */
|
||||||
gmac->GMAC_RBQB = (uint32_t)queue->rx_desc_list.buf;
|
gmac->GMAC_RBQB = (u32_t)queue->rx_desc_list.buf;
|
||||||
|
|
||||||
/* Restart reception */
|
/* Restart reception */
|
||||||
gmac->GMAC_NCR |= GMAC_NCR_RXEN;
|
gmac->GMAC_NCR |= GMAC_NCR_RXEN;
|
||||||
|
@ -304,9 +304,9 @@ static void rx_error_handler(Gmac *gmac, struct gmac_queue *queue)
|
||||||
*
|
*
|
||||||
* According to 802.3 MDC should be less then 2.5 MHz.
|
* According to 802.3 MDC should be less then 2.5 MHz.
|
||||||
*/
|
*/
|
||||||
static int get_mck_clock_divisor(uint32_t mck)
|
static int get_mck_clock_divisor(u32_t mck)
|
||||||
{
|
{
|
||||||
uint32_t mck_divisor;
|
u32_t mck_divisor;
|
||||||
|
|
||||||
if (mck <= 20000000) {
|
if (mck <= 20000000) {
|
||||||
mck_divisor = GMAC_NCFGR_CLK_MCK_8;
|
mck_divisor = GMAC_NCFGR_CLK_MCK_8;
|
||||||
|
@ -328,7 +328,7 @@ static int get_mck_clock_divisor(uint32_t mck)
|
||||||
return mck_divisor;
|
return mck_divisor;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gmac_init(Gmac *gmac, uint32_t gmac_ncfgr_val)
|
static int gmac_init(Gmac *gmac, u32_t gmac_ncfgr_val)
|
||||||
{
|
{
|
||||||
int mck_divisor;
|
int mck_divisor;
|
||||||
|
|
||||||
|
@ -364,9 +364,9 @@ static int gmac_init(Gmac *gmac, uint32_t gmac_ncfgr_val)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void link_configure(Gmac *gmac, uint32_t flags)
|
static void link_configure(Gmac *gmac, u32_t flags)
|
||||||
{
|
{
|
||||||
uint32_t val;
|
u32_t val;
|
||||||
|
|
||||||
gmac->GMAC_NCR &= ~(GMAC_NCR_RXEN | GMAC_NCR_TXEN);
|
gmac->GMAC_NCR &= ~(GMAC_NCR_RXEN | GMAC_NCR_TXEN);
|
||||||
|
|
||||||
|
@ -387,9 +387,9 @@ static int queue_init(Gmac *gmac, struct gmac_queue *queue)
|
||||||
|
|
||||||
__ASSERT_NO_MSG(queue->rx_desc_list.len > 0);
|
__ASSERT_NO_MSG(queue->rx_desc_list.len > 0);
|
||||||
__ASSERT_NO_MSG(queue->tx_desc_list.len > 0);
|
__ASSERT_NO_MSG(queue->tx_desc_list.len > 0);
|
||||||
__ASSERT(!((uint32_t)queue->rx_desc_list.buf & ~GMAC_RBQB_ADDR_Msk),
|
__ASSERT(!((u32_t)queue->rx_desc_list.buf & ~GMAC_RBQB_ADDR_Msk),
|
||||||
"RX descriptors have to be word aligned");
|
"RX descriptors have to be word aligned");
|
||||||
__ASSERT(!((uint32_t)queue->tx_desc_list.buf & ~GMAC_TBQB_ADDR_Msk),
|
__ASSERT(!((u32_t)queue->tx_desc_list.buf & ~GMAC_TBQB_ADDR_Msk),
|
||||||
"TX descriptors have to be word aligned");
|
"TX descriptors have to be word aligned");
|
||||||
|
|
||||||
/* Setup descriptor lists */
|
/* Setup descriptor lists */
|
||||||
|
@ -408,9 +408,9 @@ static int queue_init(Gmac *gmac, struct gmac_queue *queue)
|
||||||
queue->tx_desc_list.len - 1);
|
queue->tx_desc_list.len - 1);
|
||||||
|
|
||||||
/* Set Receive Buffer Queue Pointer Register */
|
/* Set Receive Buffer Queue Pointer Register */
|
||||||
gmac->GMAC_RBQB = (uint32_t)queue->rx_desc_list.buf;
|
gmac->GMAC_RBQB = (u32_t)queue->rx_desc_list.buf;
|
||||||
/* Set Transmit Buffer Queue Pointer Register */
|
/* Set Transmit Buffer Queue Pointer Register */
|
||||||
gmac->GMAC_TBQB = (uint32_t)queue->tx_desc_list.buf;
|
gmac->GMAC_TBQB = (u32_t)queue->tx_desc_list.buf;
|
||||||
|
|
||||||
/* Configure GMAC DMA transfer */
|
/* Configure GMAC DMA transfer */
|
||||||
gmac->GMAC_DCFGR =
|
gmac->GMAC_DCFGR =
|
||||||
|
@ -442,9 +442,9 @@ static int priority_queue_init_as_idle(Gmac *gmac, struct gmac_queue *queue)
|
||||||
struct gmac_desc_list *rx_desc_list = &queue->rx_desc_list;
|
struct gmac_desc_list *rx_desc_list = &queue->rx_desc_list;
|
||||||
struct gmac_desc_list *tx_desc_list = &queue->tx_desc_list;
|
struct gmac_desc_list *tx_desc_list = &queue->tx_desc_list;
|
||||||
|
|
||||||
__ASSERT(!((uint32_t)rx_desc_list->buf & ~GMAC_RBQB_ADDR_Msk),
|
__ASSERT(!((u32_t)rx_desc_list->buf & ~GMAC_RBQB_ADDR_Msk),
|
||||||
"RX descriptors have to be word aligned");
|
"RX descriptors have to be word aligned");
|
||||||
__ASSERT(!((uint32_t)tx_desc_list->buf & ~GMAC_TBQB_ADDR_Msk),
|
__ASSERT(!((u32_t)tx_desc_list->buf & ~GMAC_TBQB_ADDR_Msk),
|
||||||
"TX descriptors have to be word aligned");
|
"TX descriptors have to be word aligned");
|
||||||
__ASSERT((rx_desc_list->len == 1) && (tx_desc_list->len == 1),
|
__ASSERT((rx_desc_list->len == 1) && (tx_desc_list->len == 1),
|
||||||
"Priority queues are currently not supported, descriptor "
|
"Priority queues are currently not supported, descriptor "
|
||||||
|
@ -460,9 +460,9 @@ static int priority_queue_init_as_idle(Gmac *gmac, struct gmac_queue *queue)
|
||||||
tx_desc_list->buf[0].w1 = GMAC_TXW1_USED | GMAC_TXW1_WRAP;
|
tx_desc_list->buf[0].w1 = GMAC_TXW1_USED | GMAC_TXW1_WRAP;
|
||||||
|
|
||||||
/* Set Receive Buffer Queue Pointer Register */
|
/* Set Receive Buffer Queue Pointer Register */
|
||||||
gmac->GMAC_RBQBAPQ[queue->que_idx - 1] = (uint32_t)rx_desc_list->buf;
|
gmac->GMAC_RBQBAPQ[queue->que_idx - 1] = (u32_t)rx_desc_list->buf;
|
||||||
/* Set Transmit Buffer Queue Pointer Register */
|
/* Set Transmit Buffer Queue Pointer Register */
|
||||||
gmac->GMAC_TBQBAPQ[queue->que_idx - 1] = (uint32_t)tx_desc_list->buf;
|
gmac->GMAC_TBQBAPQ[queue->que_idx - 1] = (u32_t)tx_desc_list->buf;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -476,10 +476,10 @@ static struct net_buf *frame_get(struct gmac_queue *queue)
|
||||||
bool frame_is_complete;
|
bool frame_is_complete;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct net_buf *new_frag;
|
struct net_buf *new_frag;
|
||||||
uint8_t *frag_data;
|
u8_t *frag_data;
|
||||||
uint32_t frag_len;
|
u32_t frag_len;
|
||||||
uint32_t frame_len = 0;
|
u32_t frame_len = 0;
|
||||||
uint16_t tail;
|
u16_t tail;
|
||||||
|
|
||||||
/* Check if there exists a complete frame in RX descriptor list */
|
/* Check if there exists a complete frame in RX descriptor list */
|
||||||
tail = rx_desc_list->tail;
|
tail = rx_desc_list->tail;
|
||||||
|
@ -517,7 +517,7 @@ static struct net_buf *frame_get(struct gmac_queue *queue)
|
||||||
*/
|
*/
|
||||||
while ((rx_desc->w0 & GMAC_RXW0_OWNERSHIP) && !frame_is_complete) {
|
while ((rx_desc->w0 & GMAC_RXW0_OWNERSHIP) && !frame_is_complete) {
|
||||||
frag = (struct net_buf *)rx_pkt_list->buf[tail];
|
frag = (struct net_buf *)rx_pkt_list->buf[tail];
|
||||||
frag_data = (uint8_t *)(rx_desc->w0 & GMAC_RXW0_ADDR);
|
frag_data = (u8_t *)(rx_desc->w0 & GMAC_RXW0_ADDR);
|
||||||
__ASSERT(frag->data == frag_data,
|
__ASSERT(frag->data == frag_data,
|
||||||
"RX descriptor and buffer list desynchronized");
|
"RX descriptor and buffer list desynchronized");
|
||||||
frame_is_complete = (bool)(rx_desc->w1 & GMAC_RXW1_EOF);
|
frame_is_complete = (bool)(rx_desc->w1 & GMAC_RXW1_EOF);
|
||||||
|
@ -544,7 +544,7 @@ static struct net_buf *frame_get(struct gmac_queue *queue)
|
||||||
net_buf_add(frag, frag_len);
|
net_buf_add(frag, frag_len);
|
||||||
net_pkt_frag_insert(rx_frame, frag);
|
net_pkt_frag_insert(rx_frame, frag);
|
||||||
frag = new_frag;
|
frag = new_frag;
|
||||||
rx_pkt_list->buf[tail] = (uint32_t)frag;
|
rx_pkt_list->buf[tail] = (u32_t)frag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -556,7 +556,7 @@ static struct net_buf *frame_get(struct gmac_queue *queue)
|
||||||
__DMB(); /* data memory barrier */
|
__DMB(); /* data memory barrier */
|
||||||
/* Update buffer descriptor address word */
|
/* Update buffer descriptor address word */
|
||||||
rx_desc->w0 =
|
rx_desc->w0 =
|
||||||
((uint32_t)frag->data & GMAC_RXW0_ADDR)
|
((u32_t)frag->data & GMAC_RXW0_ADDR)
|
||||||
| (tail == rx_desc_list->len-1 ? GMAC_RXW0_WRAP : 0);
|
| (tail == rx_desc_list->len-1 ? GMAC_RXW0_WRAP : 0);
|
||||||
|
|
||||||
MODULO_INC(tail, rx_desc_list->len);
|
MODULO_INC(tail, rx_desc_list->len);
|
||||||
|
@ -601,9 +601,9 @@ static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
|
||||||
struct gmac_desc_list *tx_desc_list = &queue->tx_desc_list;
|
struct gmac_desc_list *tx_desc_list = &queue->tx_desc_list;
|
||||||
struct gmac_desc *tx_desc;
|
struct gmac_desc *tx_desc;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
uint8_t *frag_data;
|
u8_t *frag_data;
|
||||||
uint16_t frag_len;
|
u16_t frag_len;
|
||||||
uint32_t err_tx_flushed_count_at_entry = queue->err_tx_flushed_count;
|
u32_t err_tx_flushed_count_at_entry = queue->err_tx_flushed_count;
|
||||||
unsigned int key;
|
unsigned int key;
|
||||||
|
|
||||||
__ASSERT(pkt, "buf pointer is NULL");
|
__ASSERT(pkt, "buf pointer is NULL");
|
||||||
|
@ -642,7 +642,7 @@ static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
|
||||||
tx_desc = &tx_desc_list->buf[tx_desc_list->head];
|
tx_desc = &tx_desc_list->buf[tx_desc_list->head];
|
||||||
|
|
||||||
/* Update buffer descriptor address word */
|
/* Update buffer descriptor address word */
|
||||||
tx_desc->w0 = (uint32_t)frag_data;
|
tx_desc->w0 = (u32_t)frag_data;
|
||||||
/* Guarantee that address word is written before the status
|
/* Guarantee that address word is written before the status
|
||||||
* word to avoid race condition.
|
* word to avoid race condition.
|
||||||
*/
|
*/
|
||||||
|
@ -696,7 +696,7 @@ static void queue0_isr(void *arg)
|
||||||
struct eth_sam_dev_data *const dev_data = DEV_DATA(dev);
|
struct eth_sam_dev_data *const dev_data = DEV_DATA(dev);
|
||||||
Gmac *gmac = cfg->regs;
|
Gmac *gmac = cfg->regs;
|
||||||
struct gmac_queue *queue = &dev_data->queue_list[0];
|
struct gmac_queue *queue = &dev_data->queue_list[0];
|
||||||
uint32_t isr;
|
u32_t isr;
|
||||||
|
|
||||||
/* Interrupt Status Register is cleared on read */
|
/* Interrupt Status Register is cleared on read */
|
||||||
isr = gmac->GMAC_ISR;
|
isr = gmac->GMAC_ISR;
|
||||||
|
@ -747,8 +747,8 @@ static void eth0_iface_init(struct net_if *iface)
|
||||||
struct device *const dev = net_if_get_device(iface);
|
struct device *const dev = net_if_get_device(iface);
|
||||||
struct eth_sam_dev_data *const dev_data = DEV_DATA(dev);
|
struct eth_sam_dev_data *const dev_data = DEV_DATA(dev);
|
||||||
const struct eth_sam_dev_cfg *const cfg = DEV_CFG(dev);
|
const struct eth_sam_dev_cfg *const cfg = DEV_CFG(dev);
|
||||||
uint32_t gmac_ncfgr_val;
|
u32_t gmac_ncfgr_val;
|
||||||
uint32_t link_status;
|
u32_t link_status;
|
||||||
int result;
|
int result;
|
||||||
|
|
||||||
dev_data->iface = iface;
|
dev_data->iface = iface;
|
||||||
|
@ -845,11 +845,11 @@ static struct eth_sam_dev_data eth0_data = {
|
||||||
.len = ARRAY_SIZE(tx_desc_que0),
|
.len = ARRAY_SIZE(tx_desc_que0),
|
||||||
},
|
},
|
||||||
.rx_pkt_list = {
|
.rx_pkt_list = {
|
||||||
.buf = (uint32_t *)rx_buf_list_que0,
|
.buf = (u32_t *)rx_buf_list_que0,
|
||||||
.len = ARRAY_SIZE(rx_buf_list_que0),
|
.len = ARRAY_SIZE(rx_buf_list_que0),
|
||||||
},
|
},
|
||||||
.tx_frames = {
|
.tx_frames = {
|
||||||
.buf = (uint32_t *)tx_frame_list_que0,
|
.buf = (u32_t *)tx_frame_list_que0,
|
||||||
.len = ARRAY_SIZE(tx_frame_list_que0),
|
.len = ARRAY_SIZE(tx_frame_list_que0),
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
|
|
|
@ -32,9 +32,9 @@
|
||||||
*/
|
*/
|
||||||
#if 0
|
#if 0
|
||||||
#define DCACHE_INVALIDATE(addr, size) \
|
#define DCACHE_INVALIDATE(addr, size) \
|
||||||
SCB_InvalidateDCache_by_Addr((uint32_t *)addr, size)
|
SCB_InvalidateDCache_by_Addr((u32_t *)addr, size)
|
||||||
#define DCACHE_CLEAN(addr, size) \
|
#define DCACHE_CLEAN(addr, size) \
|
||||||
SCB_CleanDCache_by_Addr((uint32_t *)addr, size)
|
SCB_CleanDCache_by_Addr((u32_t *)addr, size)
|
||||||
#else
|
#else
|
||||||
#define DCACHE_INVALIDATE(addr, size) { ; }
|
#define DCACHE_INVALIDATE(addr, size) { ; }
|
||||||
#define DCACHE_CLEAN(addr, size) { ; }
|
#define DCACHE_CLEAN(addr, size) { ; }
|
||||||
|
@ -126,24 +126,24 @@ enum queue_idx {
|
||||||
|
|
||||||
/** Minimal ring buffer implementation */
|
/** Minimal ring buffer implementation */
|
||||||
struct ring_buf {
|
struct ring_buf {
|
||||||
uint32_t *buf;
|
u32_t *buf;
|
||||||
uint16_t len;
|
u16_t len;
|
||||||
uint16_t head;
|
u16_t head;
|
||||||
uint16_t tail;
|
u16_t tail;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Receive/transmit buffer descriptor */
|
/** Receive/transmit buffer descriptor */
|
||||||
struct gmac_desc {
|
struct gmac_desc {
|
||||||
uint32_t w0;
|
u32_t w0;
|
||||||
uint32_t w1;
|
u32_t w1;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Ring list of receive/transmit buffer descriptors */
|
/** Ring list of receive/transmit buffer descriptors */
|
||||||
struct gmac_desc_list {
|
struct gmac_desc_list {
|
||||||
struct gmac_desc *buf;
|
struct gmac_desc *buf;
|
||||||
uint16_t len;
|
u16_t len;
|
||||||
uint16_t head;
|
u16_t head;
|
||||||
uint16_t tail;
|
u16_t tail;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** GMAC Queue data */
|
/** GMAC Queue data */
|
||||||
|
@ -156,11 +156,11 @@ struct gmac_queue {
|
||||||
struct ring_buf tx_frames;
|
struct ring_buf tx_frames;
|
||||||
|
|
||||||
/** Number of RX frames dropped by the driver */
|
/** Number of RX frames dropped by the driver */
|
||||||
volatile uint32_t err_rx_frames_dropped;
|
volatile u32_t err_rx_frames_dropped;
|
||||||
/** Number of times receive queue was flushed */
|
/** Number of times receive queue was flushed */
|
||||||
volatile uint32_t err_rx_flushed_count;
|
volatile u32_t err_rx_flushed_count;
|
||||||
/** Number of times transmit queue was flushed */
|
/** Number of times transmit queue was flushed */
|
||||||
volatile uint32_t err_tx_flushed_count;
|
volatile u32_t err_tx_flushed_count;
|
||||||
|
|
||||||
enum queue_idx que_idx;
|
enum queue_idx que_idx;
|
||||||
};
|
};
|
||||||
|
@ -168,9 +168,9 @@ struct gmac_queue {
|
||||||
/* Device constant configuration parameters */
|
/* Device constant configuration parameters */
|
||||||
struct eth_sam_dev_cfg {
|
struct eth_sam_dev_cfg {
|
||||||
Gmac *regs;
|
Gmac *regs;
|
||||||
uint32_t periph_id;
|
u32_t periph_id;
|
||||||
const struct soc_gpio_pin *pin_list;
|
const struct soc_gpio_pin *pin_list;
|
||||||
uint32_t pin_list_size;
|
u32_t pin_list_size;
|
||||||
void (*config_func)(void);
|
void (*config_func)(void);
|
||||||
struct phy_sam_gmac_dev phy;
|
struct phy_sam_gmac_dev phy;
|
||||||
};
|
};
|
||||||
|
@ -178,7 +178,7 @@ struct eth_sam_dev_cfg {
|
||||||
/* Device run time data */
|
/* Device run time data */
|
||||||
struct eth_sam_dev_data {
|
struct eth_sam_dev_data {
|
||||||
struct net_if *iface;
|
struct net_if *iface;
|
||||||
uint8_t mac_addr[6];
|
u8_t mac_addr[6];
|
||||||
struct gmac_queue queue_list[GMAC_QUEUE_NO];
|
struct gmac_queue queue_list[GMAC_QUEUE_NO];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ static void mdio_bus_disable(Gmac *gmac)
|
||||||
/* Wait PHY operation complete. */
|
/* Wait PHY operation complete. */
|
||||||
static int mdio_bus_wait(Gmac *gmac)
|
static int mdio_bus_wait(Gmac *gmac)
|
||||||
{
|
{
|
||||||
uint32_t retries = 100; /* will wait up to 1 s */
|
u32_t retries = 100; /* will wait up to 1 s */
|
||||||
|
|
||||||
while (!(gmac->GMAC_NSR & GMAC_NSR_IDLE)) {
|
while (!(gmac->GMAC_NSR & GMAC_NSR_IDLE)) {
|
||||||
if (retries-- == 0) {
|
if (retries-- == 0) {
|
||||||
|
@ -52,8 +52,8 @@ static int mdio_bus_wait(Gmac *gmac)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Send command to PHY over MDIO serial bus */
|
/* Send command to PHY over MDIO serial bus */
|
||||||
static int mdio_bus_send(Gmac *gmac, uint8_t phy_addr, uint8_t reg_addr,
|
static int mdio_bus_send(Gmac *gmac, u8_t phy_addr, u8_t reg_addr,
|
||||||
uint8_t rw, uint16_t data)
|
u8_t rw, u16_t data)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
|
@ -75,11 +75,11 @@ static int mdio_bus_send(Gmac *gmac, uint8_t phy_addr, uint8_t reg_addr,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read PHY register. */
|
/* Read PHY register. */
|
||||||
static int phy_read(const struct phy_sam_gmac_dev *phy, uint8_t reg_addr,
|
static int phy_read(const struct phy_sam_gmac_dev *phy, u8_t reg_addr,
|
||||||
uint32_t *value)
|
u32_t *value)
|
||||||
{
|
{
|
||||||
Gmac *const gmac = phy->regs;
|
Gmac *const gmac = phy->regs;
|
||||||
uint8_t phy_addr = phy->address;
|
u8_t phy_addr = phy->address;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
retval = mdio_bus_send(gmac, phy_addr, reg_addr, 1, 0);
|
retval = mdio_bus_send(gmac, phy_addr, reg_addr, 1, 0);
|
||||||
|
@ -94,11 +94,11 @@ static int phy_read(const struct phy_sam_gmac_dev *phy, uint8_t reg_addr,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write PHY register. */
|
/* Write PHY register. */
|
||||||
static int phy_write(const struct phy_sam_gmac_dev *phy, uint8_t reg_addr,
|
static int phy_write(const struct phy_sam_gmac_dev *phy, u8_t reg_addr,
|
||||||
uint32_t value)
|
u32_t value)
|
||||||
{
|
{
|
||||||
Gmac *const gmac = phy->regs;
|
Gmac *const gmac = phy->regs;
|
||||||
uint8_t phy_addr = phy->address;
|
u8_t phy_addr = phy->address;
|
||||||
|
|
||||||
return mdio_bus_send(gmac, phy_addr, reg_addr, 0, value);
|
return mdio_bus_send(gmac, phy_addr, reg_addr, 0, value);
|
||||||
}
|
}
|
||||||
|
@ -106,8 +106,8 @@ static int phy_write(const struct phy_sam_gmac_dev *phy, uint8_t reg_addr,
|
||||||
/* Issue a PHY soft reset. */
|
/* Issue a PHY soft reset. */
|
||||||
static int phy_soft_reset(const struct phy_sam_gmac_dev *phy)
|
static int phy_soft_reset(const struct phy_sam_gmac_dev *phy)
|
||||||
{
|
{
|
||||||
uint32_t phy_reg;
|
u32_t phy_reg;
|
||||||
uint32_t retries = 12;
|
u32_t retries = 12;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
/* Issue a soft reset */
|
/* Issue a soft reset */
|
||||||
|
@ -160,11 +160,11 @@ int phy_sam_gmac_init(const struct phy_sam_gmac_dev *phy)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t phy_sam_gmac_id_get(const struct phy_sam_gmac_dev *phy)
|
u32_t phy_sam_gmac_id_get(const struct phy_sam_gmac_dev *phy)
|
||||||
{
|
{
|
||||||
Gmac *const gmac = phy->regs;
|
Gmac *const gmac = phy->regs;
|
||||||
uint32_t phy_reg;
|
u32_t phy_reg;
|
||||||
uint32_t phy_id;
|
u32_t phy_id;
|
||||||
|
|
||||||
mdio_bus_enable(gmac);
|
mdio_bus_enable(gmac);
|
||||||
|
|
||||||
|
@ -186,13 +186,13 @@ uint32_t phy_sam_gmac_id_get(const struct phy_sam_gmac_dev *phy)
|
||||||
}
|
}
|
||||||
|
|
||||||
int phy_sam_gmac_auto_negotiate(const struct phy_sam_gmac_dev *phy,
|
int phy_sam_gmac_auto_negotiate(const struct phy_sam_gmac_dev *phy,
|
||||||
uint32_t *status)
|
u32_t *status)
|
||||||
{
|
{
|
||||||
Gmac *const gmac = phy->regs;
|
Gmac *const gmac = phy->regs;
|
||||||
uint32_t val;
|
u32_t val;
|
||||||
uint32_t ability_adv;
|
u32_t ability_adv;
|
||||||
uint32_t ability_rcvd;
|
u32_t ability_rcvd;
|
||||||
uint32_t retries = PHY_AUTONEG_TIMEOUT_MS / 100;
|
u32_t retries = PHY_AUTONEG_TIMEOUT_MS / 100;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
mdio_bus_enable(gmac);
|
mdio_bus_enable(gmac);
|
||||||
|
|
|
@ -24,7 +24,7 @@ extern "C" {
|
||||||
|
|
||||||
struct phy_sam_gmac_dev {
|
struct phy_sam_gmac_dev {
|
||||||
Gmac *regs;
|
Gmac *regs;
|
||||||
uint8_t address;
|
u8_t address;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,7 +43,7 @@ int phy_sam_gmac_init(const struct phy_sam_gmac_dev *phy);
|
||||||
* @return 0 on success or a negative error value on failure
|
* @return 0 on success or a negative error value on failure
|
||||||
*/
|
*/
|
||||||
int phy_sam_gmac_auto_negotiate(const struct phy_sam_gmac_dev *phy,
|
int phy_sam_gmac_auto_negotiate(const struct phy_sam_gmac_dev *phy,
|
||||||
uint32_t *status);
|
u32_t *status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get PHY ID value.
|
* @brief Get PHY ID value.
|
||||||
|
@ -51,7 +51,7 @@ int phy_sam_gmac_auto_negotiate(const struct phy_sam_gmac_dev *phy,
|
||||||
* @param phy PHY instance
|
* @param phy PHY instance
|
||||||
* @return PHY ID value or 0xFFFFFFFF on failure
|
* @return PHY ID value or 0xFFFFFFFF on failure
|
||||||
*/
|
*/
|
||||||
uint32_t phy_sam_gmac_id_get(const struct phy_sam_gmac_dev *phy);
|
u32_t phy_sam_gmac_id_get(const struct phy_sam_gmac_dev *phy);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ static inline void _cc2520_print_gpio_config(struct device *dev)
|
||||||
|
|
||||||
static inline void _cc2520_print_exceptions(struct cc2520_context *cc2520)
|
static inline void _cc2520_print_exceptions(struct cc2520_context *cc2520)
|
||||||
{
|
{
|
||||||
uint8_t flag = read_reg_excflag0(&cc2520->spi);
|
u8_t flag = read_reg_excflag0(&cc2520->spi);
|
||||||
|
|
||||||
SYS_LOG_DBG("EXCFLAG0:");
|
SYS_LOG_DBG("EXCFLAG0:");
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ static inline void _cc2520_print_exceptions(struct cc2520_context *cc2520)
|
||||||
|
|
||||||
static inline void _cc2520_print_errors(struct cc2520_context *cc2520)
|
static inline void _cc2520_print_errors(struct cc2520_context *cc2520)
|
||||||
{
|
{
|
||||||
uint8_t flag = read_reg_excflag2(&cc2520->spi);
|
u8_t flag = read_reg_excflag2(&cc2520->spi);
|
||||||
|
|
||||||
SYS_LOG_DBG("EXCFLAG2:");
|
SYS_LOG_DBG("EXCFLAG2:");
|
||||||
|
|
||||||
|
@ -203,10 +203,10 @@ static inline void _cc2520_print_errors(struct cc2520_context *cc2520)
|
||||||
********************/
|
********************/
|
||||||
#define _usleep(usec) k_busy_wait(usec)
|
#define _usleep(usec) k_busy_wait(usec)
|
||||||
|
|
||||||
uint8_t _cc2520_read_reg(struct cc2520_spi *spi,
|
u8_t _cc2520_read_reg(struct cc2520_spi *spi,
|
||||||
bool freg, uint8_t addr)
|
bool freg, u8_t addr)
|
||||||
{
|
{
|
||||||
uint8_t len = freg ? 2 : 3;
|
u8_t len = freg ? 2 : 3;
|
||||||
|
|
||||||
spi->cmd_buf[0] = freg ? CC2520_INS_REGRD | addr : CC2520_INS_MEMRD;
|
spi->cmd_buf[0] = freg ? CC2520_INS_REGRD | addr : CC2520_INS_MEMRD;
|
||||||
spi->cmd_buf[1] = freg ? 0 : addr;
|
spi->cmd_buf[1] = freg ? 0 : addr;
|
||||||
|
@ -223,9 +223,9 @@ uint8_t _cc2520_read_reg(struct cc2520_spi *spi,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _cc2520_write_reg(struct cc2520_spi *spi, bool freg,
|
bool _cc2520_write_reg(struct cc2520_spi *spi, bool freg,
|
||||||
uint8_t addr, uint8_t value)
|
u8_t addr, u8_t value)
|
||||||
{
|
{
|
||||||
uint8_t len = freg ? 2 : 3;
|
u8_t len = freg ? 2 : 3;
|
||||||
|
|
||||||
spi->cmd_buf[0] = freg ? CC2520_INS_REGWR | addr : CC2520_INS_MEMWR;
|
spi->cmd_buf[0] = freg ? CC2520_INS_REGWR | addr : CC2520_INS_MEMWR;
|
||||||
spi->cmd_buf[1] = freg ? value : addr;
|
spi->cmd_buf[1] = freg ? value : addr;
|
||||||
|
@ -236,13 +236,13 @@ bool _cc2520_write_reg(struct cc2520_spi *spi, bool freg,
|
||||||
return (spi_write(spi->dev, spi->cmd_buf, len) == 0);
|
return (spi_write(spi->dev, spi->cmd_buf, len) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _cc2520_write_ram(struct cc2520_spi *spi, uint16_t addr,
|
bool _cc2520_write_ram(struct cc2520_spi *spi, u16_t addr,
|
||||||
uint8_t *data_buf, uint8_t len)
|
u8_t *data_buf, u8_t len)
|
||||||
{
|
{
|
||||||
#ifndef CONFIG_IEEE802154_CC2520_CRYPTO
|
#ifndef CONFIG_IEEE802154_CC2520_CRYPTO
|
||||||
uint8_t *cmd_data = spi->cmd_buf;
|
u8_t *cmd_data = spi->cmd_buf;
|
||||||
#else
|
#else
|
||||||
uint8_t cmd_data[128];
|
u8_t cmd_data[128];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cmd_data[0] = CC2520_INS_MEMWR | (addr >> 8);
|
cmd_data[0] = CC2520_INS_MEMWR | (addr >> 8);
|
||||||
|
@ -255,7 +255,7 @@ bool _cc2520_write_ram(struct cc2520_spi *spi, uint16_t addr,
|
||||||
return (spi_write(spi->dev, cmd_data, len + 2) == 0);
|
return (spi_write(spi->dev, cmd_data, len + 2) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t _cc2520_status(struct cc2520_spi *spi)
|
static u8_t _cc2520_status(struct cc2520_spi *spi)
|
||||||
{
|
{
|
||||||
spi->cmd_buf[0] = CC2520_INS_SNOP;
|
spi->cmd_buf[0] = CC2520_INS_SNOP;
|
||||||
|
|
||||||
|
@ -271,8 +271,8 @@ static uint8_t _cc2520_status(struct cc2520_spi *spi)
|
||||||
|
|
||||||
static bool verify_osc_stabilization(struct cc2520_context *cc2520)
|
static bool verify_osc_stabilization(struct cc2520_context *cc2520)
|
||||||
{
|
{
|
||||||
uint8_t timeout = 100;
|
u8_t timeout = 100;
|
||||||
uint8_t status;
|
u8_t status;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
status = _cc2520_status(&cc2520->spi);
|
status = _cc2520_status(&cc2520->spi);
|
||||||
|
@ -284,12 +284,12 @@ static bool verify_osc_stabilization(struct cc2520_context *cc2520)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline uint8_t *get_mac(struct device *dev)
|
static inline u8_t *get_mac(struct device *dev)
|
||||||
{
|
{
|
||||||
struct cc2520_context *cc2520 = dev->driver_data;
|
struct cc2520_context *cc2520 = dev->driver_data;
|
||||||
|
|
||||||
#if defined(CONFIG_IEEE802154_CC2520_RANDOM_MAC)
|
#if defined(CONFIG_IEEE802154_CC2520_RANDOM_MAC)
|
||||||
uint32_t *ptr = (uint32_t *)(cc2520->mac_addr + 4);
|
u32_t *ptr = (u32_t *)(cc2520->mac_addr + 4);
|
||||||
|
|
||||||
UNALIGNED_PUT(sys_rand32_get(), ptr);
|
UNALIGNED_PUT(sys_rand32_get(), ptr);
|
||||||
|
|
||||||
|
@ -312,7 +312,7 @@ static inline uint8_t *get_mac(struct device *dev)
|
||||||
/******************
|
/******************
|
||||||
* GPIO functions *
|
* GPIO functions *
|
||||||
*****************/
|
*****************/
|
||||||
static inline void set_reset(struct device *dev, uint32_t value)
|
static inline void set_reset(struct device *dev, u32_t value)
|
||||||
{
|
{
|
||||||
struct cc2520_context *cc2520 = dev->driver_data;
|
struct cc2520_context *cc2520 = dev->driver_data;
|
||||||
|
|
||||||
|
@ -320,7 +320,7 @@ static inline void set_reset(struct device *dev, uint32_t value)
|
||||||
cc2520->gpios[CC2520_GPIO_IDX_RESET].pin, value);
|
cc2520->gpios[CC2520_GPIO_IDX_RESET].pin, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void set_vreg_en(struct device *dev, uint32_t value)
|
static inline void set_vreg_en(struct device *dev, u32_t value)
|
||||||
{
|
{
|
||||||
struct cc2520_context *cc2520 = dev->driver_data;
|
struct cc2520_context *cc2520 = dev->driver_data;
|
||||||
|
|
||||||
|
@ -328,9 +328,9 @@ static inline void set_vreg_en(struct device *dev, uint32_t value)
|
||||||
cc2520->gpios[CC2520_GPIO_IDX_VREG_EN].pin, value);
|
cc2520->gpios[CC2520_GPIO_IDX_VREG_EN].pin, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t get_fifo(struct cc2520_context *cc2520)
|
static inline u32_t get_fifo(struct cc2520_context *cc2520)
|
||||||
{
|
{
|
||||||
uint32_t pin_value;
|
u32_t pin_value;
|
||||||
|
|
||||||
gpio_pin_read(cc2520->gpios[CC2520_GPIO_IDX_FIFO].dev,
|
gpio_pin_read(cc2520->gpios[CC2520_GPIO_IDX_FIFO].dev,
|
||||||
cc2520->gpios[CC2520_GPIO_IDX_FIFO].pin, &pin_value);
|
cc2520->gpios[CC2520_GPIO_IDX_FIFO].pin, &pin_value);
|
||||||
|
@ -338,9 +338,9 @@ static inline uint32_t get_fifo(struct cc2520_context *cc2520)
|
||||||
return pin_value;
|
return pin_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t get_fifop(struct cc2520_context *cc2520)
|
static inline u32_t get_fifop(struct cc2520_context *cc2520)
|
||||||
{
|
{
|
||||||
uint32_t pin_value;
|
u32_t pin_value;
|
||||||
|
|
||||||
gpio_pin_read(cc2520->gpios[CC2520_GPIO_IDX_FIFOP].dev,
|
gpio_pin_read(cc2520->gpios[CC2520_GPIO_IDX_FIFOP].dev,
|
||||||
cc2520->gpios[CC2520_GPIO_IDX_FIFOP].pin, &pin_value);
|
cc2520->gpios[CC2520_GPIO_IDX_FIFOP].pin, &pin_value);
|
||||||
|
@ -348,9 +348,9 @@ static inline uint32_t get_fifop(struct cc2520_context *cc2520)
|
||||||
return pin_value;
|
return pin_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t get_cca(struct cc2520_context *cc2520)
|
static inline u32_t get_cca(struct cc2520_context *cc2520)
|
||||||
{
|
{
|
||||||
uint32_t pin_value;
|
u32_t pin_value;
|
||||||
|
|
||||||
gpio_pin_read(cc2520->gpios[CC2520_GPIO_IDX_CCA].dev,
|
gpio_pin_read(cc2520->gpios[CC2520_GPIO_IDX_CCA].dev,
|
||||||
cc2520->gpios[CC2520_GPIO_IDX_CCA].pin, &pin_value);
|
cc2520->gpios[CC2520_GPIO_IDX_CCA].pin, &pin_value);
|
||||||
|
@ -359,7 +359,7 @@ static inline uint32_t get_cca(struct cc2520_context *cc2520)
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void sfd_int_handler(struct device *port,
|
static inline void sfd_int_handler(struct device *port,
|
||||||
struct gpio_callback *cb, uint32_t pins)
|
struct gpio_callback *cb, u32_t pins)
|
||||||
{
|
{
|
||||||
struct cc2520_context *cc2520 =
|
struct cc2520_context *cc2520 =
|
||||||
CONTAINER_OF(cb, struct cc2520_context, sfd_cb);
|
CONTAINER_OF(cb, struct cc2520_context, sfd_cb);
|
||||||
|
@ -371,7 +371,7 @@ static inline void sfd_int_handler(struct device *port,
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void fifop_int_handler(struct device *port,
|
static inline void fifop_int_handler(struct device *port,
|
||||||
struct gpio_callback *cb, uint32_t pins)
|
struct gpio_callback *cb, u32_t pins)
|
||||||
{
|
{
|
||||||
struct cc2520_context *cc2520 =
|
struct cc2520_context *cc2520 =
|
||||||
CONTAINER_OF(cb, struct cc2520_context, fifop_cb);
|
CONTAINER_OF(cb, struct cc2520_context, fifop_cb);
|
||||||
|
@ -436,7 +436,7 @@ static inline void setup_gpio_callbacks(struct device *dev)
|
||||||
* TX functions *
|
* TX functions *
|
||||||
***************/
|
***************/
|
||||||
static inline bool write_txfifo_length(struct cc2520_spi *spi,
|
static inline bool write_txfifo_length(struct cc2520_spi *spi,
|
||||||
uint8_t len)
|
u8_t len)
|
||||||
{
|
{
|
||||||
spi->cmd_buf[0] = CC2520_INS_TXBUF;
|
spi->cmd_buf[0] = CC2520_INS_TXBUF;
|
||||||
spi->cmd_buf[1] = len + CC2520_FCS_LENGTH;
|
spi->cmd_buf[1] = len + CC2520_FCS_LENGTH;
|
||||||
|
@ -447,9 +447,9 @@ static inline bool write_txfifo_length(struct cc2520_spi *spi,
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool write_txfifo_content(struct cc2520_spi *spi,
|
static inline bool write_txfifo_content(struct cc2520_spi *spi,
|
||||||
uint8_t *frame, uint8_t len)
|
u8_t *frame, u8_t len)
|
||||||
{
|
{
|
||||||
uint8_t cmd[128];
|
u8_t cmd[128];
|
||||||
|
|
||||||
cmd[0] = CC2520_INS_TXBUF;
|
cmd[0] = CC2520_INS_TXBUF;
|
||||||
memcpy(&cmd[1], frame, len);
|
memcpy(&cmd[1], frame, len);
|
||||||
|
@ -460,7 +460,7 @@ static inline bool write_txfifo_content(struct cc2520_spi *spi,
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool verify_txfifo_status(struct cc2520_context *cc2520,
|
static inline bool verify_txfifo_status(struct cc2520_context *cc2520,
|
||||||
uint8_t len)
|
u8_t len)
|
||||||
{
|
{
|
||||||
if (read_reg_txfifocnt(&cc2520->spi) < len ||
|
if (read_reg_txfifocnt(&cc2520->spi) < len ||
|
||||||
(read_reg_excflag0(&cc2520->spi) & EXCFLAG0_TX_UNDERFLOW)) {
|
(read_reg_excflag0(&cc2520->spi) & EXCFLAG0_TX_UNDERFLOW)) {
|
||||||
|
@ -472,8 +472,8 @@ static inline bool verify_txfifo_status(struct cc2520_context *cc2520,
|
||||||
|
|
||||||
static inline bool verify_tx_done(struct cc2520_context *cc2520)
|
static inline bool verify_tx_done(struct cc2520_context *cc2520)
|
||||||
{
|
{
|
||||||
uint8_t timeout = 10;
|
u8_t timeout = 10;
|
||||||
uint8_t status;
|
u8_t status;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
_usleep(1);
|
_usleep(1);
|
||||||
|
@ -501,7 +501,7 @@ static inline void flush_rxfifo(struct cc2520_context *cc2520)
|
||||||
write_reg_excflag0(&cc2520->spi, EXCFLAG0_RESET_RX_FLAGS);
|
write_reg_excflag0(&cc2520->spi, EXCFLAG0_RESET_RX_FLAGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t read_rxfifo_length(struct cc2520_spi *spi)
|
static inline u8_t read_rxfifo_length(struct cc2520_spi *spi)
|
||||||
{
|
{
|
||||||
spi->cmd_buf[0] = CC2520_INS_RXBUF;
|
spi->cmd_buf[0] = CC2520_INS_RXBUF;
|
||||||
spi->cmd_buf[1] = 0;
|
spi->cmd_buf[1] = 0;
|
||||||
|
@ -517,9 +517,9 @@ static inline uint8_t read_rxfifo_length(struct cc2520_spi *spi)
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool read_rxfifo_content(struct cc2520_spi *spi,
|
static inline bool read_rxfifo_content(struct cc2520_spi *spi,
|
||||||
struct net_buf *frag, uint8_t len)
|
struct net_buf *frag, u8_t len)
|
||||||
{
|
{
|
||||||
uint8_t data[128+1];
|
u8_t data[128+1];
|
||||||
|
|
||||||
data[0] = CC2520_INS_RXBUF;
|
data[0] = CC2520_INS_RXBUF;
|
||||||
memset(&data[1], 0, len);
|
memset(&data[1], 0, len);
|
||||||
|
@ -584,7 +584,7 @@ static inline bool verify_crc(struct cc2520_context *cc2520,
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool verify_rxfifo_validity(struct cc2520_spi *spi,
|
static inline bool verify_rxfifo_validity(struct cc2520_spi *spi,
|
||||||
uint8_t pkt_len)
|
u8_t pkt_len)
|
||||||
{
|
{
|
||||||
if (pkt_len < 2 || read_reg_rxfifocnt(spi) != pkt_len) {
|
if (pkt_len < 2 || read_reg_rxfifocnt(spi) != pkt_len) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -599,7 +599,7 @@ static void cc2520_rx(int arg)
|
||||||
struct cc2520_context *cc2520 = dev->driver_data;
|
struct cc2520_context *cc2520 = dev->driver_data;
|
||||||
struct net_buf *pkt_frag = NULL;
|
struct net_buf *pkt_frag = NULL;
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
uint8_t pkt_len;
|
u8_t pkt_len;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
pkt = NULL;
|
pkt = NULL;
|
||||||
|
@ -717,7 +717,7 @@ static int cc2520_cca(struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cc2520_set_channel(struct device *dev, uint16_t channel)
|
static int cc2520_set_channel(struct device *dev, u16_t channel)
|
||||||
{
|
{
|
||||||
struct cc2520_context *cc2520 = dev->driver_data;
|
struct cc2520_context *cc2520 = dev->driver_data;
|
||||||
|
|
||||||
|
@ -738,7 +738,7 @@ static int cc2520_set_channel(struct device *dev, uint16_t channel)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cc2520_set_pan_id(struct device *dev, uint16_t pan_id)
|
static int cc2520_set_pan_id(struct device *dev, u16_t pan_id)
|
||||||
{
|
{
|
||||||
struct cc2520_context *cc2520 = dev->driver_data;
|
struct cc2520_context *cc2520 = dev->driver_data;
|
||||||
|
|
||||||
|
@ -746,7 +746,7 @@ static int cc2520_set_pan_id(struct device *dev, uint16_t pan_id)
|
||||||
|
|
||||||
pan_id = sys_le16_to_cpu(pan_id);
|
pan_id = sys_le16_to_cpu(pan_id);
|
||||||
|
|
||||||
if (!write_mem_pan_id(&cc2520->spi, (uint8_t *) &pan_id)) {
|
if (!write_mem_pan_id(&cc2520->spi, (u8_t *) &pan_id)) {
|
||||||
SYS_LOG_ERR("Failed");
|
SYS_LOG_ERR("Failed");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@ -754,7 +754,7 @@ static int cc2520_set_pan_id(struct device *dev, uint16_t pan_id)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cc2520_set_short_addr(struct device *dev, uint16_t short_addr)
|
static int cc2520_set_short_addr(struct device *dev, u16_t short_addr)
|
||||||
{
|
{
|
||||||
struct cc2520_context *cc2520 = dev->driver_data;
|
struct cc2520_context *cc2520 = dev->driver_data;
|
||||||
|
|
||||||
|
@ -762,7 +762,7 @@ static int cc2520_set_short_addr(struct device *dev, uint16_t short_addr)
|
||||||
|
|
||||||
short_addr = sys_le16_to_cpu(short_addr);
|
short_addr = sys_le16_to_cpu(short_addr);
|
||||||
|
|
||||||
if (!write_mem_short_addr(&cc2520->spi, (uint8_t *) &short_addr)) {
|
if (!write_mem_short_addr(&cc2520->spi, (u8_t *) &short_addr)) {
|
||||||
SYS_LOG_ERR("Failed");
|
SYS_LOG_ERR("Failed");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@ -770,7 +770,7 @@ static int cc2520_set_short_addr(struct device *dev, uint16_t short_addr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cc2520_set_ieee_addr(struct device *dev, const uint8_t *ieee_addr)
|
static int cc2520_set_ieee_addr(struct device *dev, const u8_t *ieee_addr)
|
||||||
{
|
{
|
||||||
struct cc2520_context *cc2520 = dev->driver_data;
|
struct cc2520_context *cc2520 = dev->driver_data;
|
||||||
|
|
||||||
|
@ -786,10 +786,10 @@ static int cc2520_set_ieee_addr(struct device *dev, const uint8_t *ieee_addr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cc2520_set_txpower(struct device *dev, int16_t dbm)
|
static int cc2520_set_txpower(struct device *dev, s16_t dbm)
|
||||||
{
|
{
|
||||||
struct cc2520_context *cc2520 = dev->driver_data;
|
struct cc2520_context *cc2520 = dev->driver_data;
|
||||||
uint8_t pwr;
|
u8_t pwr;
|
||||||
|
|
||||||
SYS_LOG_DBG("%d", dbm);
|
SYS_LOG_DBG("%d", dbm);
|
||||||
|
|
||||||
|
@ -840,10 +840,10 @@ static int cc2520_tx(struct device *dev,
|
||||||
struct net_pkt *pkt,
|
struct net_pkt *pkt,
|
||||||
struct net_buf *frag)
|
struct net_buf *frag)
|
||||||
{
|
{
|
||||||
uint8_t *frame = frag->data - net_pkt_ll_reserve(pkt);
|
u8_t *frame = frag->data - net_pkt_ll_reserve(pkt);
|
||||||
uint8_t len = net_pkt_ll_reserve(pkt) + frag->len;
|
u8_t len = net_pkt_ll_reserve(pkt) + frag->len;
|
||||||
struct cc2520_context *cc2520 = dev->driver_data;
|
struct cc2520_context *cc2520 = dev->driver_data;
|
||||||
uint8_t retry = 2;
|
u8_t retry = 2;
|
||||||
bool status;
|
bool status;
|
||||||
|
|
||||||
SYS_LOG_DBG("%p (%u)", frag, len);
|
SYS_LOG_DBG("%p (%u)", frag, len);
|
||||||
|
@ -943,7 +943,7 @@ static int cc2520_stop(struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t cc2520_get_lqi(struct device *dev)
|
static u8_t cc2520_get_lqi(struct device *dev)
|
||||||
{
|
{
|
||||||
struct cc2520_context *cc2520 = dev->driver_data;
|
struct cc2520_context *cc2520 = dev->driver_data;
|
||||||
|
|
||||||
|
@ -1090,7 +1090,7 @@ static void cc2520_iface_init(struct net_if *iface)
|
||||||
{
|
{
|
||||||
struct device *dev = net_if_get_device(iface);
|
struct device *dev = net_if_get_device(iface);
|
||||||
struct cc2520_context *cc2520 = dev->driver_data;
|
struct cc2520_context *cc2520 = dev->driver_data;
|
||||||
uint8_t *mac = get_mac(dev);
|
u8_t *mac = get_mac(dev);
|
||||||
|
|
||||||
SYS_LOG_DBG("");
|
SYS_LOG_DBG("");
|
||||||
|
|
||||||
|
@ -1142,10 +1142,10 @@ NET_STACK_INFO_ADDR(RX, cc2520,
|
||||||
|
|
||||||
#ifdef CONFIG_IEEE802154_CC2520_CRYPTO
|
#ifdef CONFIG_IEEE802154_CC2520_CRYPTO
|
||||||
|
|
||||||
static bool _cc2520_read_ram(struct cc2520_spi *spi, uint16_t addr,
|
static bool _cc2520_read_ram(struct cc2520_spi *spi, u16_t addr,
|
||||||
uint8_t *data_buf, uint8_t len)
|
u8_t *data_buf, u8_t len)
|
||||||
{
|
{
|
||||||
uint8_t cmd_buf[128];
|
u8_t cmd_buf[128];
|
||||||
|
|
||||||
cmd_buf[0] = CC2520_INS_MEMRD | (addr >> 8);
|
cmd_buf[0] = CC2520_INS_MEMRD | (addr >> 8);
|
||||||
cmd_buf[1] = addr;
|
cmd_buf[1] = addr;
|
||||||
|
@ -1163,15 +1163,15 @@ static bool _cc2520_read_ram(struct cc2520_spi *spi, uint16_t addr,
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool instruct_ccm(struct cc2520_context *cc2520,
|
static inline bool instruct_ccm(struct cc2520_context *cc2520,
|
||||||
uint8_t key_addr,
|
u8_t key_addr,
|
||||||
uint8_t auth_crypt,
|
u8_t auth_crypt,
|
||||||
uint8_t nonce_addr,
|
u8_t nonce_addr,
|
||||||
uint16_t input_addr,
|
u16_t input_addr,
|
||||||
uint16_t output_addr,
|
u16_t output_addr,
|
||||||
uint8_t in_len,
|
u8_t in_len,
|
||||||
uint8_t m)
|
u8_t m)
|
||||||
{
|
{
|
||||||
uint8_t cmd[9];
|
u8_t cmd[9];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
SYS_LOG_DBG("CCM(P={01} K={%02x} C={%02x} N={%02x}"
|
SYS_LOG_DBG("CCM(P={01} K={%02x} C={%02x} N={%02x}"
|
||||||
|
@ -1183,10 +1183,10 @@ static inline bool instruct_ccm(struct cc2520_context *cc2520,
|
||||||
cmd[1] = key_addr;
|
cmd[1] = key_addr;
|
||||||
cmd[2] = (auth_crypt & 0x7f);
|
cmd[2] = (auth_crypt & 0x7f);
|
||||||
cmd[3] = nonce_addr;
|
cmd[3] = nonce_addr;
|
||||||
cmd[4] = (uint8_t)(((input_addr & 0x0f00) >> 4) |
|
cmd[4] = (u8_t)(((input_addr & 0x0f00) >> 4) |
|
||||||
((output_addr & 0x0f00) >> 8));
|
((output_addr & 0x0f00) >> 8));
|
||||||
cmd[5] = (uint8_t)(input_addr & 0x00ff);
|
cmd[5] = (u8_t)(input_addr & 0x00ff);
|
||||||
cmd[6] = (uint8_t)(output_addr & 0x00ff);
|
cmd[6] = (u8_t)(output_addr & 0x00ff);
|
||||||
cmd[7] = (in_len & 0x7f);
|
cmd[7] = (in_len & 0x7f);
|
||||||
cmd[8] = (m & 0x03);
|
cmd[8] = (m & 0x03);
|
||||||
|
|
||||||
|
@ -1205,15 +1205,15 @@ static inline bool instruct_ccm(struct cc2520_context *cc2520,
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool instruct_uccm(struct cc2520_context *cc2520,
|
static inline bool instruct_uccm(struct cc2520_context *cc2520,
|
||||||
uint8_t key_addr,
|
u8_t key_addr,
|
||||||
uint8_t auth_crypt,
|
u8_t auth_crypt,
|
||||||
uint8_t nonce_addr,
|
u8_t nonce_addr,
|
||||||
uint16_t input_addr,
|
u16_t input_addr,
|
||||||
uint16_t output_addr,
|
u16_t output_addr,
|
||||||
uint8_t in_len,
|
u8_t in_len,
|
||||||
uint8_t m)
|
u8_t m)
|
||||||
{
|
{
|
||||||
uint8_t cmd[9];
|
u8_t cmd[9];
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
SYS_LOG_DBG("UCCM(P={01} K={%02x} C={%02x} N={%02x}"
|
SYS_LOG_DBG("UCCM(P={01} K={%02x} C={%02x} N={%02x}"
|
||||||
|
@ -1225,10 +1225,10 @@ static inline bool instruct_uccm(struct cc2520_context *cc2520,
|
||||||
cmd[1] = key_addr;
|
cmd[1] = key_addr;
|
||||||
cmd[2] = (auth_crypt & 0x7f);
|
cmd[2] = (auth_crypt & 0x7f);
|
||||||
cmd[3] = nonce_addr;
|
cmd[3] = nonce_addr;
|
||||||
cmd[4] = (uint8_t)(((input_addr & 0x0f00) >> 4) |
|
cmd[4] = (u8_t)(((input_addr & 0x0f00) >> 4) |
|
||||||
((output_addr & 0x0f00) >> 8));
|
((output_addr & 0x0f00) >> 8));
|
||||||
cmd[5] = (uint8_t)(input_addr & 0x00ff);
|
cmd[5] = (u8_t)(input_addr & 0x00ff);
|
||||||
cmd[6] = (uint8_t)(output_addr & 0x00ff);
|
cmd[6] = (u8_t)(output_addr & 0x00ff);
|
||||||
cmd[7] = (in_len & 0x7f);
|
cmd[7] = (in_len & 0x7f);
|
||||||
cmd[8] = (m & 0x03);
|
cmd[8] = (m & 0x03);
|
||||||
|
|
||||||
|
@ -1246,15 +1246,15 @@ static inline bool instruct_uccm(struct cc2520_context *cc2520,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void generate_nonce(uint8_t *ccm_nonce, uint8_t *nonce,
|
static inline void generate_nonce(u8_t *ccm_nonce, u8_t *nonce,
|
||||||
struct cipher_aead_pkt *apkt, uint8_t m)
|
struct cipher_aead_pkt *apkt, u8_t m)
|
||||||
{
|
{
|
||||||
nonce[0] = 0 | (apkt->ad_len ? 0x40 : 0) | (m << 3) | 1;
|
nonce[0] = 0 | (apkt->ad_len ? 0x40 : 0) | (m << 3) | 1;
|
||||||
|
|
||||||
memcpy(&nonce[1], ccm_nonce, 13);
|
memcpy(&nonce[1], ccm_nonce, 13);
|
||||||
|
|
||||||
nonce[14] = (uint8_t)(apkt->pkt->in_len >> 8);
|
nonce[14] = (u8_t)(apkt->pkt->in_len >> 8);
|
||||||
nonce[15] = (uint8_t)(apkt->pkt->in_len);
|
nonce[15] = (u8_t)(apkt->pkt->in_len);
|
||||||
|
|
||||||
/* See section 26.8.1 */
|
/* See section 26.8.1 */
|
||||||
sys_mem_swap(nonce, 16);
|
sys_mem_swap(nonce, 16);
|
||||||
|
@ -1262,13 +1262,13 @@ static inline void generate_nonce(uint8_t *ccm_nonce, uint8_t *nonce,
|
||||||
|
|
||||||
static int insert_crypto_parameters(struct cipher_ctx *ctx,
|
static int insert_crypto_parameters(struct cipher_ctx *ctx,
|
||||||
struct cipher_aead_pkt *apkt,
|
struct cipher_aead_pkt *apkt,
|
||||||
uint8_t *ccm_nonce, uint8_t *auth_crypt)
|
u8_t *ccm_nonce, u8_t *auth_crypt)
|
||||||
{
|
{
|
||||||
struct cc2520_context *cc2520 = ctx->device->driver_data;
|
struct cc2520_context *cc2520 = ctx->device->driver_data;
|
||||||
uint8_t data[128];
|
u8_t data[128];
|
||||||
uint8_t *in_buf;
|
u8_t *in_buf;
|
||||||
uint8_t in_len;
|
u8_t in_len;
|
||||||
uint8_t m = 0;
|
u8_t m = 0;
|
||||||
|
|
||||||
if (!apkt->pkt->out_buf || !apkt->pkt->out_buf_max) {
|
if (!apkt->pkt->out_buf || !apkt->pkt->out_buf_max) {
|
||||||
SYS_LOG_ERR("Out buffer needs to be set");
|
SYS_LOG_ERR("Out buffer needs to be set");
|
||||||
|
@ -1353,10 +1353,10 @@ static int insert_crypto_parameters(struct cipher_ctx *ctx,
|
||||||
|
|
||||||
static int _cc2520_crypto_ccm(struct cipher_ctx *ctx,
|
static int _cc2520_crypto_ccm(struct cipher_ctx *ctx,
|
||||||
struct cipher_aead_pkt *apkt,
|
struct cipher_aead_pkt *apkt,
|
||||||
uint8_t *ccm_nonce)
|
u8_t *ccm_nonce)
|
||||||
{
|
{
|
||||||
struct cc2520_context *cc2520 = ctx->device->driver_data;
|
struct cc2520_context *cc2520 = ctx->device->driver_data;
|
||||||
uint8_t auth_crypt;
|
u8_t auth_crypt;
|
||||||
int m;
|
int m;
|
||||||
|
|
||||||
if (!apkt || !apkt->pkt) {
|
if (!apkt || !apkt->pkt) {
|
||||||
|
@ -1400,10 +1400,10 @@ static int _cc2520_crypto_ccm(struct cipher_ctx *ctx,
|
||||||
|
|
||||||
static int _cc2520_crypto_uccm(struct cipher_ctx *ctx,
|
static int _cc2520_crypto_uccm(struct cipher_ctx *ctx,
|
||||||
struct cipher_aead_pkt *apkt,
|
struct cipher_aead_pkt *apkt,
|
||||||
uint8_t *ccm_nonce)
|
u8_t *ccm_nonce)
|
||||||
{
|
{
|
||||||
struct cc2520_context *cc2520 = ctx->device->driver_data;
|
struct cc2520_context *cc2520 = ctx->device->driver_data;
|
||||||
uint8_t auth_crypt;
|
u8_t auth_crypt;
|
||||||
int m;
|
int m;
|
||||||
|
|
||||||
if (!apkt || !apkt->pkt) {
|
if (!apkt || !apkt->pkt) {
|
||||||
|
|
|
@ -20,12 +20,12 @@
|
||||||
*/
|
*/
|
||||||
struct cc2520_spi {
|
struct cc2520_spi {
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
uint32_t slave;
|
u32_t slave;
|
||||||
/**
|
/**
|
||||||
* cmd_buf will use at most 9 bytes:
|
* cmd_buf will use at most 9 bytes:
|
||||||
* dummy bytes + 8 ieee address bytes
|
* dummy bytes + 8 ieee address bytes
|
||||||
*/
|
*/
|
||||||
uint8_t cmd_buf[12];
|
u8_t cmd_buf[12];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cc2520_context {
|
struct cc2520_context {
|
||||||
|
@ -35,7 +35,7 @@ struct cc2520_context {
|
||||||
struct gpio_callback sfd_cb;
|
struct gpio_callback sfd_cb;
|
||||||
struct gpio_callback fifop_cb;
|
struct gpio_callback fifop_cb;
|
||||||
struct cc2520_spi spi;
|
struct cc2520_spi spi;
|
||||||
uint8_t mac_addr[8];
|
u8_t mac_addr[8];
|
||||||
/************TX************/
|
/************TX************/
|
||||||
struct k_sem tx_sync;
|
struct k_sem tx_sync;
|
||||||
atomic_t tx;
|
atomic_t tx;
|
||||||
|
@ -46,7 +46,7 @@ struct cc2520_context {
|
||||||
struct k_sem access_lock;
|
struct k_sem access_lock;
|
||||||
#endif
|
#endif
|
||||||
bool overflow;
|
bool overflow;
|
||||||
uint8_t lqi;
|
u8_t lqi;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "ieee802154_cc2520_regs.h"
|
#include "ieee802154_cc2520_regs.h"
|
||||||
|
@ -56,20 +56,20 @@ struct cc2520_context {
|
||||||
***************************
|
***************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
uint8_t _cc2520_read_reg(struct cc2520_spi *spi,
|
u8_t _cc2520_read_reg(struct cc2520_spi *spi,
|
||||||
bool freg, uint8_t addr);
|
bool freg, u8_t addr);
|
||||||
bool _cc2520_write_reg(struct cc2520_spi *spi, bool freg,
|
bool _cc2520_write_reg(struct cc2520_spi *spi, bool freg,
|
||||||
uint8_t addr, uint8_t value);
|
u8_t addr, u8_t value);
|
||||||
|
|
||||||
#define DEFINE_REG_READ(__reg_name, __reg_addr, __freg) \
|
#define DEFINE_REG_READ(__reg_name, __reg_addr, __freg) \
|
||||||
static inline uint8_t read_reg_##__reg_name(struct cc2520_spi *spi) \
|
static inline u8_t read_reg_##__reg_name(struct cc2520_spi *spi) \
|
||||||
{ \
|
{ \
|
||||||
return _cc2520_read_reg(spi, __freg, __reg_addr); \
|
return _cc2520_read_reg(spi, __freg, __reg_addr); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_REG_WRITE(__reg_name, __reg_addr, __freg) \
|
#define DEFINE_REG_WRITE(__reg_name, __reg_addr, __freg) \
|
||||||
static inline bool write_reg_##__reg_name(struct cc2520_spi *spi, \
|
static inline bool write_reg_##__reg_name(struct cc2520_spi *spi, \
|
||||||
uint8_t val) \
|
u8_t val) \
|
||||||
{ \
|
{ \
|
||||||
return _cc2520_write_reg(spi, __freg, __reg_addr, val); \
|
return _cc2520_write_reg(spi, __freg, __reg_addr, val); \
|
||||||
}
|
}
|
||||||
|
@ -128,12 +128,12 @@ DEFINE_SREG_WRITE(extclock, CC2520_SREG_EXTCLOCK)
|
||||||
************************
|
************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool _cc2520_write_ram(struct cc2520_spi *spi, uint16_t addr,
|
bool _cc2520_write_ram(struct cc2520_spi *spi, u16_t addr,
|
||||||
uint8_t *data_buf, uint8_t len);
|
u8_t *data_buf, u8_t len);
|
||||||
|
|
||||||
#define DEFINE_MEM_WRITE(__mem_name, __addr, __sz) \
|
#define DEFINE_MEM_WRITE(__mem_name, __addr, __sz) \
|
||||||
static inline bool write_mem_##__mem_name(struct cc2520_spi *spi, \
|
static inline bool write_mem_##__mem_name(struct cc2520_spi *spi, \
|
||||||
uint8_t *buf) \
|
u8_t *buf) \
|
||||||
{ \
|
{ \
|
||||||
return _cc2520_write_ram(spi, __addr, buf, __sz); \
|
return _cc2520_write_ram(spi, __addr, buf, __sz); \
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ DEFINE_MEM_WRITE(ext_addr, CC2520_MEM_EXT_ADDR, 8)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static inline bool _cc2520_command_strobe(struct cc2520_spi *spi,
|
static inline bool _cc2520_command_strobe(struct cc2520_spi *spi,
|
||||||
uint8_t instruction)
|
u8_t instruction)
|
||||||
{
|
{
|
||||||
spi_slave_select(spi->dev, spi->slave);
|
spi_slave_select(spi->dev, spi->slave);
|
||||||
|
|
||||||
|
@ -156,9 +156,9 @@ static inline bool _cc2520_command_strobe(struct cc2520_spi *spi,
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool _cc2520_command_strobe_snop(struct cc2520_spi *spi,
|
static inline bool _cc2520_command_strobe_snop(struct cc2520_spi *spi,
|
||||||
uint8_t instruction)
|
u8_t instruction)
|
||||||
{
|
{
|
||||||
uint8_t ins[2] = {
|
u8_t ins[2] = {
|
||||||
instruction,
|
instruction,
|
||||||
CC2520_INS_SNOP
|
CC2520_INS_SNOP
|
||||||
};
|
};
|
||||||
|
|
|
@ -111,12 +111,12 @@
|
||||||
#define EXCFLAG0_RX_UNDERFLOW BIT(5)
|
#define EXCFLAG0_RX_UNDERFLOW BIT(5)
|
||||||
#define EXCFLAG0_RX_OVERFLOW BIT(6)
|
#define EXCFLAG0_RX_OVERFLOW BIT(6)
|
||||||
#define EXCFLAG0_RXENABLE_ZERO BIT(7)
|
#define EXCFLAG0_RXENABLE_ZERO BIT(7)
|
||||||
#define EXCFLAG0_RESET_TX_FLAGS ((uint8_t) \
|
#define EXCFLAG0_RESET_TX_FLAGS ((u8_t) \
|
||||||
~(EXCFLAG0_TX_FRM_DONE | \
|
~(EXCFLAG0_TX_FRM_DONE | \
|
||||||
EXCFLAG0_TX_ACK_DONE | \
|
EXCFLAG0_TX_ACK_DONE | \
|
||||||
EXCFLAG0_TX_UNDERFLOW | \
|
EXCFLAG0_TX_UNDERFLOW | \
|
||||||
EXCFLAG0_TX_OVERFLOW))
|
EXCFLAG0_TX_OVERFLOW))
|
||||||
#define EXCFLAG0_RESET_RX_FLAGS ((uint8_t) \
|
#define EXCFLAG0_RESET_RX_FLAGS ((u8_t) \
|
||||||
~(EXCFLAG0_RX_UNDERFLOW | \
|
~(EXCFLAG0_RX_UNDERFLOW | \
|
||||||
EXCFLAG0_RX_OVERFLOW | \
|
EXCFLAG0_RX_OVERFLOW | \
|
||||||
EXCFLAG0_RXENABLE_ZERO))
|
EXCFLAG0_RXENABLE_ZERO))
|
||||||
|
@ -130,7 +130,7 @@
|
||||||
#define EXCFLAG1_SFD BIT(5)
|
#define EXCFLAG1_SFD BIT(5)
|
||||||
#define EXCFLAG1_DPU_DONE_L BIT(6)
|
#define EXCFLAG1_DPU_DONE_L BIT(6)
|
||||||
#define EXCFLAG1_DPU_DONE_H BIT(7)
|
#define EXCFLAG1_DPU_DONE_H BIT(7)
|
||||||
#define EXCFLAG1_RESET_RX_FLAGS ((uint8_t) \
|
#define EXCFLAG1_RESET_RX_FLAGS ((u8_t) \
|
||||||
~(EXCFLAG1_RX_FRM_DONE | \
|
~(EXCFLAG1_RX_FRM_DONE | \
|
||||||
EXCFLAG1_RX_FRM_ACCEPTED | \
|
EXCFLAG1_RX_FRM_ACCEPTED | \
|
||||||
EXCFLAG1_FIFOP))
|
EXCFLAG1_FIFOP))
|
||||||
|
|
|
@ -105,7 +105,7 @@
|
||||||
#define MCR20A_OUTPUT_POWER_MIN (-35)
|
#define MCR20A_OUTPUT_POWER_MIN (-35)
|
||||||
|
|
||||||
/* Lookup table for the Power Control register */
|
/* Lookup table for the Power Control register */
|
||||||
static const uint8_t pow_lt[44] = {
|
static const u8_t pow_lt[44] = {
|
||||||
3, 4, 5, 6,
|
3, 4, 5, 6,
|
||||||
6, 7, 7, 8,
|
6, 7, 7, 8,
|
||||||
8, 9, 9, 10,
|
8, 9, 9, 10,
|
||||||
|
@ -127,14 +127,14 @@ static const uint8_t pow_lt[44] = {
|
||||||
* F = ((PLL_INT0 + 64) + (PLL_FRAC0/65536))32MHz
|
* F = ((PLL_INT0 + 64) + (PLL_FRAC0/65536))32MHz
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static const uint8_t pll_int_lt[16] = {
|
static const u8_t pll_int_lt[16] = {
|
||||||
11, 11, 11, 11,
|
11, 11, 11, 11,
|
||||||
11, 11, 12, 12,
|
11, 11, 12, 12,
|
||||||
12, 12, 12, 12,
|
12, 12, 12, 12,
|
||||||
13, 13, 13, 13
|
13, 13, 13, 13
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint16_t pll_frac_lt[16] = {
|
static const u16_t pll_frac_lt[16] = {
|
||||||
10240, 20480, 30720, 40960,
|
10240, 20480, 30720, 40960,
|
||||||
51200, 61440, 6144, 16384,
|
51200, 61440, 6144, 16384,
|
||||||
26624, 36864, 47104, 57344,
|
26624, 36864, 47104, 57344,
|
||||||
|
@ -144,9 +144,9 @@ static const uint16_t pll_frac_lt[16] = {
|
||||||
#define _usleep(usec) k_busy_wait(usec)
|
#define _usleep(usec) k_busy_wait(usec)
|
||||||
|
|
||||||
/* Read direct (dreg is true) or indirect register (dreg is false) */
|
/* Read direct (dreg is true) or indirect register (dreg is false) */
|
||||||
uint8_t _mcr20a_read_reg(struct mcr20a_spi *spi, bool dreg, uint8_t addr)
|
u8_t _mcr20a_read_reg(struct mcr20a_spi *spi, bool dreg, u8_t addr)
|
||||||
{
|
{
|
||||||
uint8_t len = dreg ? 2 : 3;
|
u8_t len = dreg ? 2 : 3;
|
||||||
|
|
||||||
k_sem_take(&spi->spi_sem, K_FOREVER);
|
k_sem_take(&spi->spi_sem, K_FOREVER);
|
||||||
|
|
||||||
|
@ -169,10 +169,10 @@ uint8_t _mcr20a_read_reg(struct mcr20a_spi *spi, bool dreg, uint8_t addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write direct (dreg is true) or indirect register (dreg is false) */
|
/* Write direct (dreg is true) or indirect register (dreg is false) */
|
||||||
bool _mcr20a_write_reg(struct mcr20a_spi *spi, bool dreg, uint8_t addr,
|
bool _mcr20a_write_reg(struct mcr20a_spi *spi, bool dreg, u8_t addr,
|
||||||
uint8_t value)
|
u8_t value)
|
||||||
{
|
{
|
||||||
uint8_t len = dreg ? 2 : 3;
|
u8_t len = dreg ? 2 : 3;
|
||||||
bool retval;
|
bool retval;
|
||||||
|
|
||||||
k_sem_take(&spi->spi_sem, K_FOREVER);
|
k_sem_take(&spi->spi_sem, K_FOREVER);
|
||||||
|
@ -191,8 +191,8 @@ bool _mcr20a_write_reg(struct mcr20a_spi *spi, bool dreg, uint8_t addr,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write multiple bytes to direct or indirect register */
|
/* Write multiple bytes to direct or indirect register */
|
||||||
bool _mcr20a_write_burst(struct mcr20a_spi *spi, bool dreg, uint16_t addr,
|
bool _mcr20a_write_burst(struct mcr20a_spi *spi, bool dreg, u16_t addr,
|
||||||
uint8_t *data_buf, uint8_t len)
|
u8_t *data_buf, u8_t len)
|
||||||
{
|
{
|
||||||
bool retval;
|
bool retval;
|
||||||
|
|
||||||
|
@ -222,8 +222,8 @@ bool _mcr20a_write_burst(struct mcr20a_spi *spi, bool dreg, uint16_t addr,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read multiple bytes from direct or indirect register */
|
/* Read multiple bytes from direct or indirect register */
|
||||||
bool _mcr20a_read_burst(struct mcr20a_spi *spi, bool dreg, uint16_t addr,
|
bool _mcr20a_read_burst(struct mcr20a_spi *spi, bool dreg, u16_t addr,
|
||||||
uint8_t *data_buf, uint8_t len)
|
u8_t *data_buf, u8_t len)
|
||||||
{
|
{
|
||||||
k_sem_take(&spi->spi_sem, K_FOREVER);
|
k_sem_take(&spi->spi_sem, K_FOREVER);
|
||||||
|
|
||||||
|
@ -262,7 +262,7 @@ bool _mcr20a_read_burst(struct mcr20a_spi *spi, bool dreg, uint16_t addr,
|
||||||
/* Mask (msk is true) or unmask all interrupts from asserting IRQ_B */
|
/* Mask (msk is true) or unmask all interrupts from asserting IRQ_B */
|
||||||
static bool mcr20a_mask_irqb(struct mcr20a_context *dev, bool msk)
|
static bool mcr20a_mask_irqb(struct mcr20a_context *dev, bool msk)
|
||||||
{
|
{
|
||||||
uint8_t ctrl4 = read_reg_phy_ctrl4(&dev->spi);
|
u8_t ctrl4 = read_reg_phy_ctrl4(&dev->spi);
|
||||||
|
|
||||||
if (msk) {
|
if (msk) {
|
||||||
ctrl4 |= MCR20A_PHY_CTRL4_TRCV_MSK;
|
ctrl4 |= MCR20A_PHY_CTRL4_TRCV_MSK;
|
||||||
|
@ -275,14 +275,14 @@ static bool mcr20a_mask_irqb(struct mcr20a_context *dev, bool msk)
|
||||||
|
|
||||||
/** Set an timeout value for the given compare register */
|
/** Set an timeout value for the given compare register */
|
||||||
static int mcr20a_timer_set(struct mcr20a_context *mcr20a,
|
static int mcr20a_timer_set(struct mcr20a_context *mcr20a,
|
||||||
uint8_t cmp_reg,
|
u8_t cmp_reg,
|
||||||
uint32_t timeout)
|
u32_t timeout)
|
||||||
{
|
{
|
||||||
uint32_t now = 0;
|
u32_t now = 0;
|
||||||
uint32_t next;
|
u32_t next;
|
||||||
bool retval;
|
bool retval;
|
||||||
|
|
||||||
if (!read_burst_event_timer(&mcr20a->spi, (uint8_t *)&now)) {
|
if (!read_burst_event_timer(&mcr20a->spi, (u8_t *)&now)) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,16 +293,16 @@ static int mcr20a_timer_set(struct mcr20a_context *mcr20a,
|
||||||
|
|
||||||
switch (cmp_reg) {
|
switch (cmp_reg) {
|
||||||
case 1:
|
case 1:
|
||||||
retval = write_burst_t1cmp(&mcr20a->spi, (uint8_t *)&next);
|
retval = write_burst_t1cmp(&mcr20a->spi, (u8_t *)&next);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
retval = write_burst_t2cmp(&mcr20a->spi, (uint8_t *)&next);
|
retval = write_burst_t2cmp(&mcr20a->spi, (u8_t *)&next);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
retval = write_burst_t3cmp(&mcr20a->spi, (uint8_t *)&next);
|
retval = write_burst_t3cmp(&mcr20a->spi, (u8_t *)&next);
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
retval = write_burst_t4cmp(&mcr20a->spi, (uint8_t *)&next);
|
retval = write_burst_t4cmp(&mcr20a->spi, (u8_t *)&next);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -319,11 +319,11 @@ error:
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mcr20a_timer_init(struct device *dev, uint8_t tb)
|
static int mcr20a_timer_init(struct device *dev, u8_t tb)
|
||||||
{
|
{
|
||||||
struct mcr20a_context *mcr20a = dev->driver_data;
|
struct mcr20a_context *mcr20a = dev->driver_data;
|
||||||
uint8_t buf[3] = {0, 0, 0};
|
u8_t buf[3] = {0, 0, 0};
|
||||||
uint8_t ctrl4;
|
u8_t ctrl4;
|
||||||
|
|
||||||
if (!write_reg_tmr_prescale(&mcr20a->spi,
|
if (!write_reg_tmr_prescale(&mcr20a->spi,
|
||||||
set_bits_tmr_prescale(tb))) {
|
set_bits_tmr_prescale(tb))) {
|
||||||
|
@ -350,10 +350,10 @@ error:
|
||||||
|
|
||||||
/* Set Timer Comparator 4 */
|
/* Set Timer Comparator 4 */
|
||||||
static int mcr20a_t4cmp_set(struct mcr20a_context *mcr20a,
|
static int mcr20a_t4cmp_set(struct mcr20a_context *mcr20a,
|
||||||
uint32_t timeout)
|
u32_t timeout)
|
||||||
{
|
{
|
||||||
uint8_t irqsts3;
|
u8_t irqsts3;
|
||||||
uint8_t ctrl3;
|
u8_t ctrl3;
|
||||||
|
|
||||||
if (mcr20a_timer_set(mcr20a, 4, timeout)) {
|
if (mcr20a_timer_set(mcr20a, 4, timeout)) {
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -383,8 +383,8 @@ error:
|
||||||
/* Clear Timer Comparator 4 */
|
/* Clear Timer Comparator 4 */
|
||||||
static int mcr20a_t4cmp_clear(struct mcr20a_context *mcr20a)
|
static int mcr20a_t4cmp_clear(struct mcr20a_context *mcr20a)
|
||||||
{
|
{
|
||||||
uint8_t irqsts3;
|
u8_t irqsts3;
|
||||||
uint8_t ctrl3;
|
u8_t ctrl3;
|
||||||
|
|
||||||
ctrl3 = read_reg_phy_ctrl3(&mcr20a->spi);
|
ctrl3 = read_reg_phy_ctrl3(&mcr20a->spi);
|
||||||
ctrl3 &= ~MCR20A_PHY_CTRL3_TMR4CMP_EN;
|
ctrl3 &= ~MCR20A_PHY_CTRL3_TMR4CMP_EN;
|
||||||
|
@ -407,8 +407,8 @@ error:
|
||||||
|
|
||||||
static inline void _xcvseq_wait_until_idle(struct mcr20a_context *mcr20a)
|
static inline void _xcvseq_wait_until_idle(struct mcr20a_context *mcr20a)
|
||||||
{
|
{
|
||||||
uint8_t state;
|
u8_t state;
|
||||||
uint8_t retries = MCR20A_GET_SEQ_STATE_RETRIES;
|
u8_t retries = MCR20A_GET_SEQ_STATE_RETRIES;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
state = read_reg_seq_state(&mcr20a->spi);
|
state = read_reg_seq_state(&mcr20a->spi);
|
||||||
|
@ -423,7 +423,7 @@ static inline void _xcvseq_wait_until_idle(struct mcr20a_context *mcr20a)
|
||||||
static inline int mcr20a_abort_sequence(struct mcr20a_context *mcr20a,
|
static inline int mcr20a_abort_sequence(struct mcr20a_context *mcr20a,
|
||||||
bool force)
|
bool force)
|
||||||
{
|
{
|
||||||
uint8_t ctrl1;
|
u8_t ctrl1;
|
||||||
|
|
||||||
ctrl1 = read_reg_phy_ctrl1(&mcr20a->spi);
|
ctrl1 = read_reg_phy_ctrl1(&mcr20a->spi);
|
||||||
SYS_LOG_DBG("CTRL1 0x%02x", ctrl1);
|
SYS_LOG_DBG("CTRL1 0x%02x", ctrl1);
|
||||||
|
@ -453,9 +453,9 @@ static inline int mcr20a_abort_sequence(struct mcr20a_context *mcr20a,
|
||||||
|
|
||||||
/* Initiate a (new) Transceiver Sequence */
|
/* Initiate a (new) Transceiver Sequence */
|
||||||
static inline int mcr20a_set_sequence(struct mcr20a_context *mcr20a,
|
static inline int mcr20a_set_sequence(struct mcr20a_context *mcr20a,
|
||||||
uint8_t seq)
|
u8_t seq)
|
||||||
{
|
{
|
||||||
uint8_t ctrl1 = 0;
|
u8_t ctrl1 = 0;
|
||||||
|
|
||||||
seq = set_bits_phy_ctrl1_xcvseq(seq);
|
seq = set_bits_phy_ctrl1_xcvseq(seq);
|
||||||
ctrl1 = read_reg_phy_ctrl1(&mcr20a->spi);
|
ctrl1 = read_reg_phy_ctrl1(&mcr20a->spi);
|
||||||
|
@ -476,7 +476,7 @@ static inline int mcr20a_set_sequence(struct mcr20a_context *mcr20a,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t mcr20a_get_rssi(uint32_t lqi)
|
static inline u32_t mcr20a_get_rssi(u32_t lqi)
|
||||||
{
|
{
|
||||||
/* Get rssi (Received Signal Strength Indicator, unit is dBm)
|
/* Get rssi (Received Signal Strength Indicator, unit is dBm)
|
||||||
* from lqi (Link Quality Indicator) value.
|
* from lqi (Link Quality Indicator) value.
|
||||||
|
@ -489,19 +489,19 @@ static inline uint32_t mcr20a_get_rssi(uint32_t lqi)
|
||||||
* -RF * 65536 = (LQI / 2.84 - 295.4 / 2.84) * 65536
|
* -RF * 65536 = (LQI / 2.84 - 295.4 / 2.84) * 65536
|
||||||
* RF * 65536 = (295.4 * 65536 / 2.84) - (LQI * 65536 / 2.84)
|
* RF * 65536 = (295.4 * 65536 / 2.84) - (LQI * 65536 / 2.84)
|
||||||
*/
|
*/
|
||||||
uint32_t a = (uint32_t)(295.4 * 65536 / 2.84);
|
u32_t a = (u32_t)(295.4 * 65536 / 2.84);
|
||||||
uint32_t b = (uint32_t)(65536 / 2.84);
|
u32_t b = (u32_t)(65536 / 2.84);
|
||||||
|
|
||||||
return (a - (b * lqi)) >> 16;
|
return (a - (b * lqi)) >> 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t *get_mac(struct device *dev)
|
static inline u8_t *get_mac(struct device *dev)
|
||||||
{
|
{
|
||||||
struct mcr20a_context *mcr20a = dev->driver_data;
|
struct mcr20a_context *mcr20a = dev->driver_data;
|
||||||
uint32_t *ptr = (uint32_t *)(mcr20a->mac_addr);
|
u32_t *ptr = (u32_t *)(mcr20a->mac_addr);
|
||||||
|
|
||||||
UNALIGNED_PUT(sys_rand32_get(), ptr);
|
UNALIGNED_PUT(sys_rand32_get(), ptr);
|
||||||
ptr = (uint32_t *)(mcr20a->mac_addr + 4);
|
ptr = (u32_t *)(mcr20a->mac_addr + 4);
|
||||||
UNALIGNED_PUT(sys_rand32_get(), ptr);
|
UNALIGNED_PUT(sys_rand32_get(), ptr);
|
||||||
|
|
||||||
mcr20a->mac_addr[0] = (mcr20a->mac_addr[0] & ~0x01) | 0x02;
|
mcr20a->mac_addr[0] = (mcr20a->mac_addr[0] & ~0x01) | 0x02;
|
||||||
|
@ -510,9 +510,9 @@ static inline uint8_t *get_mac(struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool read_rxfifo_content(struct mcr20a_spi *spi,
|
static inline bool read_rxfifo_content(struct mcr20a_spi *spi,
|
||||||
struct net_buf *buf, uint8_t len)
|
struct net_buf *buf, u8_t len)
|
||||||
{
|
{
|
||||||
uint8_t data[1 + MCR20A_PSDU_LENGTH];
|
u8_t data[1 + MCR20A_PSDU_LENGTH];
|
||||||
|
|
||||||
if (len > MCR20A_PSDU_LENGTH) {
|
if (len > MCR20A_PSDU_LENGTH) {
|
||||||
SYS_LOG_ERR("Packet length too large");
|
SYS_LOG_ERR("Packet length too large");
|
||||||
|
@ -537,11 +537,11 @@ static inline bool read_rxfifo_content(struct mcr20a_spi *spi,
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void mcr20a_rx(struct mcr20a_context *mcr20a, uint8_t len)
|
static inline void mcr20a_rx(struct mcr20a_context *mcr20a, u8_t len)
|
||||||
{
|
{
|
||||||
struct net_pkt *pkt = NULL;
|
struct net_pkt *pkt = NULL;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
uint8_t pkt_len;
|
u8_t pkt_len;
|
||||||
|
|
||||||
pkt_len = len - MCR20A_FCS_LENGTH;
|
pkt_len = len - MCR20A_FCS_LENGTH;
|
||||||
|
|
||||||
|
@ -607,10 +607,10 @@ out:
|
||||||
* when a sequence has been completed.
|
* when a sequence has been completed.
|
||||||
*/
|
*/
|
||||||
static inline bool _irqsts1_event(struct mcr20a_context *mcr20a,
|
static inline bool _irqsts1_event(struct mcr20a_context *mcr20a,
|
||||||
uint8_t *dregs)
|
u8_t *dregs)
|
||||||
{
|
{
|
||||||
uint8_t seq = dregs[MCR20A_PHY_CTRL1] & MCR20A_PHY_CTRL1_XCVSEQ_MASK;
|
u8_t seq = dregs[MCR20A_PHY_CTRL1] & MCR20A_PHY_CTRL1_XCVSEQ_MASK;
|
||||||
uint8_t new_seq = MCR20A_XCVSEQ_RECEIVE;
|
u8_t new_seq = MCR20A_XCVSEQ_RECEIVE;
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
|
|
||||||
switch (seq) {
|
switch (seq) {
|
||||||
|
@ -694,7 +694,7 @@ static inline bool _irqsts1_event(struct mcr20a_context *mcr20a,
|
||||||
* usually the TR.
|
* usually the TR.
|
||||||
*/
|
*/
|
||||||
static inline bool _irqsts3_event(struct mcr20a_context *mcr20a,
|
static inline bool _irqsts3_event(struct mcr20a_context *mcr20a,
|
||||||
uint8_t *dregs)
|
u8_t *dregs)
|
||||||
{
|
{
|
||||||
bool retval = false;
|
bool retval = false;
|
||||||
|
|
||||||
|
@ -724,9 +724,9 @@ static void mcr20a_thread_main(void *arg)
|
||||||
{
|
{
|
||||||
struct device *dev = (struct device *)arg;
|
struct device *dev = (struct device *)arg;
|
||||||
struct mcr20a_context *mcr20a = dev->driver_data;
|
struct mcr20a_context *mcr20a = dev->driver_data;
|
||||||
uint8_t dregs[MCR20A_PHY_CTRL4 + 1];
|
u8_t dregs[MCR20A_PHY_CTRL4 + 1];
|
||||||
bool set_new_seq;
|
bool set_new_seq;
|
||||||
uint8_t ctrl1 = 0;
|
u8_t ctrl1 = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
k_sem_take(&mcr20a->isr_sem, K_FOREVER);
|
k_sem_take(&mcr20a->isr_sem, K_FOREVER);
|
||||||
|
@ -796,7 +796,7 @@ unmask_irqb:
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void irqb_int_handler(struct device *port,
|
static inline void irqb_int_handler(struct device *port,
|
||||||
struct gpio_callback *cb, uint32_t pins)
|
struct gpio_callback *cb, u32_t pins)
|
||||||
{
|
{
|
||||||
struct mcr20a_context *mcr20a = CONTAINER_OF(cb,
|
struct mcr20a_context *mcr20a = CONTAINER_OF(cb,
|
||||||
struct mcr20a_context,
|
struct mcr20a_context,
|
||||||
|
@ -804,7 +804,7 @@ static inline void irqb_int_handler(struct device *port,
|
||||||
k_sem_give(&mcr20a->isr_sem);
|
k_sem_give(&mcr20a->isr_sem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void set_reset(struct device *dev, uint32_t value)
|
static inline void set_reset(struct device *dev, u32_t value)
|
||||||
{
|
{
|
||||||
struct mcr20a_context *mcr20a = dev->driver_data;
|
struct mcr20a_context *mcr20a = dev->driver_data;
|
||||||
|
|
||||||
|
@ -832,10 +832,10 @@ static inline void setup_gpio_callbacks(struct mcr20a_context *mcr20a)
|
||||||
gpio_add_callback(mcr20a->irq_gpio, &mcr20a->irqb_cb);
|
gpio_add_callback(mcr20a->irq_gpio, &mcr20a->irqb_cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mcr20a_set_cca_mode(struct device *dev, uint8_t mode)
|
static int mcr20a_set_cca_mode(struct device *dev, u8_t mode)
|
||||||
{
|
{
|
||||||
struct mcr20a_context *mcr20a = dev->driver_data;
|
struct mcr20a_context *mcr20a = dev->driver_data;
|
||||||
uint8_t ctrl4;
|
u8_t ctrl4;
|
||||||
|
|
||||||
ctrl4 = read_reg_phy_ctrl4(&mcr20a->spi);
|
ctrl4 = read_reg_phy_ctrl4(&mcr20a->spi);
|
||||||
ctrl4 &= ~MCR20A_PHY_CTRL4_CCATYPE_MASK;
|
ctrl4 &= ~MCR20A_PHY_CTRL4_CCATYPE_MASK;
|
||||||
|
@ -891,11 +891,11 @@ error:
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mcr20a_set_channel(struct device *dev, uint16_t channel)
|
static int mcr20a_set_channel(struct device *dev, u16_t channel)
|
||||||
{
|
{
|
||||||
struct mcr20a_context *mcr20a = dev->driver_data;
|
struct mcr20a_context *mcr20a = dev->driver_data;
|
||||||
uint8_t buf[3];
|
u8_t buf[3];
|
||||||
uint8_t ctrl1;
|
u8_t ctrl1;
|
||||||
int retval = -EIO;
|
int retval = -EIO;
|
||||||
|
|
||||||
if (channel < 11 || channel > 26) {
|
if (channel < 11 || channel > 26) {
|
||||||
|
@ -920,8 +920,8 @@ static int mcr20a_set_channel(struct device *dev, uint16_t channel)
|
||||||
SYS_LOG_DBG("%u", channel);
|
SYS_LOG_DBG("%u", channel);
|
||||||
channel -= 11;
|
channel -= 11;
|
||||||
buf[0] = set_bits_pll_int0_val(pll_int_lt[channel]);
|
buf[0] = set_bits_pll_int0_val(pll_int_lt[channel]);
|
||||||
buf[1] = (uint8_t)pll_frac_lt[channel];
|
buf[1] = (u8_t)pll_frac_lt[channel];
|
||||||
buf[2] = (uint8_t)(pll_frac_lt[channel] >> 8);
|
buf[2] = (u8_t)(pll_frac_lt[channel] >> 8);
|
||||||
|
|
||||||
if (!write_burst_pll_int0(&mcr20a->spi, buf)) {
|
if (!write_burst_pll_int0(&mcr20a->spi, buf)) {
|
||||||
SYS_LOG_ERR("Failed to set PLL");
|
SYS_LOG_ERR("Failed to set PLL");
|
||||||
|
@ -946,14 +946,14 @@ out:
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mcr20a_set_pan_id(struct device *dev, uint16_t pan_id)
|
static int mcr20a_set_pan_id(struct device *dev, u16_t pan_id)
|
||||||
{
|
{
|
||||||
struct mcr20a_context *mcr20a = dev->driver_data;
|
struct mcr20a_context *mcr20a = dev->driver_data;
|
||||||
|
|
||||||
pan_id = sys_le16_to_cpu(pan_id);
|
pan_id = sys_le16_to_cpu(pan_id);
|
||||||
k_mutex_lock(&mcr20a->phy_mutex, K_FOREVER);
|
k_mutex_lock(&mcr20a->phy_mutex, K_FOREVER);
|
||||||
|
|
||||||
if (!write_burst_pan_id(&mcr20a->spi, (uint8_t *) &pan_id)) {
|
if (!write_burst_pan_id(&mcr20a->spi, (u8_t *) &pan_id)) {
|
||||||
SYS_LOG_ERR("FAILED");
|
SYS_LOG_ERR("FAILED");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@ -964,14 +964,14 @@ static int mcr20a_set_pan_id(struct device *dev, uint16_t pan_id)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mcr20a_set_short_addr(struct device *dev, uint16_t short_addr)
|
static int mcr20a_set_short_addr(struct device *dev, u16_t short_addr)
|
||||||
{
|
{
|
||||||
struct mcr20a_context *mcr20a = dev->driver_data;
|
struct mcr20a_context *mcr20a = dev->driver_data;
|
||||||
|
|
||||||
short_addr = sys_le16_to_cpu(short_addr);
|
short_addr = sys_le16_to_cpu(short_addr);
|
||||||
k_mutex_lock(&mcr20a->phy_mutex, K_FOREVER);
|
k_mutex_lock(&mcr20a->phy_mutex, K_FOREVER);
|
||||||
|
|
||||||
if (!write_burst_short_addr(&mcr20a->spi, (uint8_t *) &short_addr)) {
|
if (!write_burst_short_addr(&mcr20a->spi, (u8_t *) &short_addr)) {
|
||||||
SYS_LOG_ERR("FAILED");
|
SYS_LOG_ERR("FAILED");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@ -982,7 +982,7 @@ static int mcr20a_set_short_addr(struct device *dev, uint16_t short_addr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mcr20a_set_ieee_addr(struct device *dev, const uint8_t *ieee_addr)
|
static int mcr20a_set_ieee_addr(struct device *dev, const u8_t *ieee_addr)
|
||||||
{
|
{
|
||||||
struct mcr20a_context *mcr20a = dev->driver_data;
|
struct mcr20a_context *mcr20a = dev->driver_data;
|
||||||
|
|
||||||
|
@ -1001,10 +1001,10 @@ static int mcr20a_set_ieee_addr(struct device *dev, const uint8_t *ieee_addr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mcr20a_set_txpower(struct device *dev, int16_t dbm)
|
static int mcr20a_set_txpower(struct device *dev, s16_t dbm)
|
||||||
{
|
{
|
||||||
struct mcr20a_context *mcr20a = dev->driver_data;
|
struct mcr20a_context *mcr20a = dev->driver_data;
|
||||||
uint8_t pwr;
|
u8_t pwr;
|
||||||
|
|
||||||
k_mutex_lock(&mcr20a->phy_mutex, K_FOREVER);
|
k_mutex_lock(&mcr20a->phy_mutex, K_FOREVER);
|
||||||
SYS_LOG_DBG("%d", dbm);
|
SYS_LOG_DBG("%d", dbm);
|
||||||
|
@ -1032,9 +1032,9 @@ static inline bool write_txfifo_content(struct mcr20a_spi *spi,
|
||||||
struct net_pkt *pkt,
|
struct net_pkt *pkt,
|
||||||
struct net_buf *frag)
|
struct net_buf *frag)
|
||||||
{
|
{
|
||||||
uint8_t cmd[2 + MCR20A_PSDU_LENGTH];
|
u8_t cmd[2 + MCR20A_PSDU_LENGTH];
|
||||||
uint8_t payload_len = net_pkt_ll_reserve(pkt) + frag->len;
|
u8_t payload_len = net_pkt_ll_reserve(pkt) + frag->len;
|
||||||
uint8_t *payload = frag->data - net_pkt_ll_reserve(pkt);
|
u8_t *payload = frag->data - net_pkt_ll_reserve(pkt);
|
||||||
bool retval;
|
bool retval;
|
||||||
|
|
||||||
k_sem_take(&spi->spi_sem, K_FOREVER);
|
k_sem_take(&spi->spi_sem, K_FOREVER);
|
||||||
|
@ -1069,7 +1069,7 @@ static int mcr20a_tx(struct device *dev,
|
||||||
struct net_buf *frag)
|
struct net_buf *frag)
|
||||||
{
|
{
|
||||||
struct mcr20a_context *mcr20a = dev->driver_data;
|
struct mcr20a_context *mcr20a = dev->driver_data;
|
||||||
uint8_t seq = MCR20A_AUTOACK_ENABLED ? MCR20A_XCVSEQ_TX_RX :
|
u8_t seq = MCR20A_AUTOACK_ENABLED ? MCR20A_XCVSEQ_TX_RX :
|
||||||
MCR20A_XCVSEQ_TX;
|
MCR20A_XCVSEQ_TX;
|
||||||
|
|
||||||
k_mutex_lock(&mcr20a->phy_mutex, K_FOREVER);
|
k_mutex_lock(&mcr20a->phy_mutex, K_FOREVER);
|
||||||
|
@ -1118,8 +1118,8 @@ error:
|
||||||
static int mcr20a_start(struct device *dev)
|
static int mcr20a_start(struct device *dev)
|
||||||
{
|
{
|
||||||
struct mcr20a_context *mcr20a = dev->driver_data;
|
struct mcr20a_context *mcr20a = dev->driver_data;
|
||||||
uint8_t timeout = 6;
|
u8_t timeout = 6;
|
||||||
uint8_t status;
|
u8_t status;
|
||||||
|
|
||||||
k_mutex_lock(&mcr20a->phy_mutex, K_FOREVER);
|
k_mutex_lock(&mcr20a->phy_mutex, K_FOREVER);
|
||||||
enable_irqb_interrupt(mcr20a, false);
|
enable_irqb_interrupt(mcr20a, false);
|
||||||
|
@ -1206,7 +1206,7 @@ error:
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t mcr20a_get_lqi(struct device *dev)
|
static u8_t mcr20a_get_lqi(struct device *dev)
|
||||||
{
|
{
|
||||||
struct mcr20a_context *mcr20a = dev->driver_data;
|
struct mcr20a_context *mcr20a = dev->driver_data;
|
||||||
|
|
||||||
|
@ -1224,7 +1224,7 @@ static int mcr20a_update_overwrites(struct mcr20a_context *dev)
|
||||||
|
|
||||||
k_sem_take(&spi->spi_sem, K_FOREVER);
|
k_sem_take(&spi->spi_sem, K_FOREVER);
|
||||||
|
|
||||||
for (uint8_t i = 0;
|
for (u8_t i = 0;
|
||||||
i < sizeof(overwrites_indirect) / sizeof(overwrites_t);
|
i < sizeof(overwrites_indirect) / sizeof(overwrites_t);
|
||||||
i++) {
|
i++) {
|
||||||
|
|
||||||
|
@ -1252,9 +1252,9 @@ error:
|
||||||
static int power_on_and_setup(struct device *dev)
|
static int power_on_and_setup(struct device *dev)
|
||||||
{
|
{
|
||||||
struct mcr20a_context *mcr20a = dev->driver_data;
|
struct mcr20a_context *mcr20a = dev->driver_data;
|
||||||
uint8_t timeout = 6;
|
u8_t timeout = 6;
|
||||||
uint32_t status;
|
u32_t status;
|
||||||
uint8_t tmp = 0;
|
u8_t tmp = 0;
|
||||||
|
|
||||||
set_reset(dev, 0);
|
set_reset(dev, 0);
|
||||||
_usleep(150);
|
_usleep(150);
|
||||||
|
@ -1418,7 +1418,7 @@ static void mcr20a_iface_init(struct net_if *iface)
|
||||||
{
|
{
|
||||||
struct device *dev = net_if_get_device(iface);
|
struct device *dev = net_if_get_device(iface);
|
||||||
struct mcr20a_context *mcr20a = dev->driver_data;
|
struct mcr20a_context *mcr20a = dev->driver_data;
|
||||||
uint8_t *mac = get_mac(dev);
|
u8_t *mac = get_mac(dev);
|
||||||
|
|
||||||
net_if_set_link_addr(iface, mac, 8, NET_LINK_IEEE802154);
|
net_if_set_link_addr(iface, mac, 8, NET_LINK_IEEE802154);
|
||||||
|
|
||||||
|
|
|
@ -19,13 +19,13 @@
|
||||||
*/
|
*/
|
||||||
struct mcr20a_spi {
|
struct mcr20a_spi {
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
uint32_t slave;
|
u32_t slave;
|
||||||
struct k_sem spi_sem;
|
struct k_sem spi_sem;
|
||||||
/**
|
/**
|
||||||
* cmd_buf will use at most 9 bytes:
|
* cmd_buf will use at most 9 bytes:
|
||||||
* dummy bytes + 8 ieee address bytes
|
* dummy bytes + 8 ieee address bytes
|
||||||
*/
|
*/
|
||||||
uint8_t cmd_buf[12];
|
u8_t cmd_buf[12];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mcr20a_context {
|
struct mcr20a_context {
|
||||||
|
@ -35,7 +35,7 @@ struct mcr20a_context {
|
||||||
struct device *reset_gpio;
|
struct device *reset_gpio;
|
||||||
struct gpio_callback irqb_cb;
|
struct gpio_callback irqb_cb;
|
||||||
struct mcr20a_spi spi;
|
struct mcr20a_spi spi;
|
||||||
uint8_t mac_addr[8];
|
u8_t mac_addr[8];
|
||||||
struct k_mutex phy_mutex;
|
struct k_mutex phy_mutex;
|
||||||
struct k_sem isr_sem;
|
struct k_sem isr_sem;
|
||||||
/*********TX + CCA*********/
|
/*********TX + CCA*********/
|
||||||
|
@ -43,28 +43,28 @@ struct mcr20a_context {
|
||||||
atomic_t seq_retval;
|
atomic_t seq_retval;
|
||||||
/************RX************/
|
/************RX************/
|
||||||
char __stack mcr20a_rx_stack[CONFIG_IEEE802154_MCR20A_RX_STACK_SIZE];
|
char __stack mcr20a_rx_stack[CONFIG_IEEE802154_MCR20A_RX_STACK_SIZE];
|
||||||
uint8_t lqi;
|
u8_t lqi;
|
||||||
};
|
};
|
||||||
|
|
||||||
#include "ieee802154_mcr20a_regs.h"
|
#include "ieee802154_mcr20a_regs.h"
|
||||||
|
|
||||||
uint8_t _mcr20a_read_reg(struct mcr20a_spi *spi, bool dreg, uint8_t addr);
|
u8_t _mcr20a_read_reg(struct mcr20a_spi *spi, bool dreg, u8_t addr);
|
||||||
bool _mcr20a_write_reg(struct mcr20a_spi *spi, bool dreg, uint8_t addr,
|
bool _mcr20a_write_reg(struct mcr20a_spi *spi, bool dreg, u8_t addr,
|
||||||
uint8_t value);
|
u8_t value);
|
||||||
bool _mcr20a_write_burst(struct mcr20a_spi *spi, bool dreg, uint16_t addr,
|
bool _mcr20a_write_burst(struct mcr20a_spi *spi, bool dreg, u16_t addr,
|
||||||
uint8_t *data_buf, uint8_t len);
|
u8_t *data_buf, u8_t len);
|
||||||
bool _mcr20a_read_burst(struct mcr20a_spi *spi, bool dreg, uint16_t addr,
|
bool _mcr20a_read_burst(struct mcr20a_spi *spi, bool dreg, u16_t addr,
|
||||||
uint8_t *data_buf, uint8_t len);
|
u8_t *data_buf, u8_t len);
|
||||||
|
|
||||||
#define DEFINE_REG_READ(__reg_name, __reg_addr, __dreg) \
|
#define DEFINE_REG_READ(__reg_name, __reg_addr, __dreg) \
|
||||||
static inline uint8_t read_reg_##__reg_name(struct mcr20a_spi *spi) \
|
static inline u8_t read_reg_##__reg_name(struct mcr20a_spi *spi) \
|
||||||
{ \
|
{ \
|
||||||
return _mcr20a_read_reg(spi, __dreg, __reg_addr); \
|
return _mcr20a_read_reg(spi, __dreg, __reg_addr); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_REG_WRITE(__reg_name, __reg_addr, __dreg) \
|
#define DEFINE_REG_WRITE(__reg_name, __reg_addr, __dreg) \
|
||||||
static inline bool write_reg_##__reg_name(struct mcr20a_spi *spi, \
|
static inline bool write_reg_##__reg_name(struct mcr20a_spi *spi, \
|
||||||
uint8_t value) \
|
u8_t value) \
|
||||||
{ \
|
{ \
|
||||||
return _mcr20a_write_reg(spi, __dreg, __reg_addr, value); \
|
return _mcr20a_write_reg(spi, __dreg, __reg_addr, value); \
|
||||||
}
|
}
|
||||||
|
@ -141,7 +141,7 @@ DEFINE_IREG_WRITE(rx_byte_count, MCR20A_RX_BYTE_COUNT)
|
||||||
DEFINE_IREG_WRITE(rx_wtr_mark, MCR20A_RX_WTR_MARK)
|
DEFINE_IREG_WRITE(rx_wtr_mark, MCR20A_RX_WTR_MARK)
|
||||||
|
|
||||||
#define DEFINE_BITS_SET(__reg_name, __reg_addr, __nibble) \
|
#define DEFINE_BITS_SET(__reg_name, __reg_addr, __nibble) \
|
||||||
static inline uint8_t set_bits_##__reg_name(uint8_t value) \
|
static inline u8_t set_bits_##__reg_name(u8_t value) \
|
||||||
{ \
|
{ \
|
||||||
value = (value << __reg_addr##__nibble##_SHIFT) & \
|
value = (value << __reg_addr##__nibble##_SHIFT) & \
|
||||||
__reg_addr##__nibble##_MASK; \
|
__reg_addr##__nibble##_MASK; \
|
||||||
|
@ -156,14 +156,14 @@ DEFINE_BITS_SET(tmr_prescale, MCR20A_TMR_PRESCALE, _VAL)
|
||||||
|
|
||||||
#define DEFINE_BURST_WRITE(__reg_addr, __addr, __sz, __dreg) \
|
#define DEFINE_BURST_WRITE(__reg_addr, __addr, __sz, __dreg) \
|
||||||
static inline bool write_burst_##__reg_addr(struct mcr20a_spi *spi, \
|
static inline bool write_burst_##__reg_addr(struct mcr20a_spi *spi, \
|
||||||
uint8_t *buf) \
|
u8_t *buf) \
|
||||||
{ \
|
{ \
|
||||||
return _mcr20a_write_burst(spi, __dreg, __addr, buf, __sz); \
|
return _mcr20a_write_burst(spi, __dreg, __addr, buf, __sz); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_BURST_READ(__reg_addr, __addr, __sz, __dreg) \
|
#define DEFINE_BURST_READ(__reg_addr, __addr, __sz, __dreg) \
|
||||||
static inline bool read_burst_##__reg_addr(struct mcr20a_spi *spi, \
|
static inline bool read_burst_##__reg_addr(struct mcr20a_spi *spi, \
|
||||||
uint8_t *buf) \
|
u8_t *buf) \
|
||||||
{ \
|
{ \
|
||||||
return _mcr20a_read_burst(spi, __dreg, __addr, buf, __sz); \
|
return _mcr20a_read_burst(spi, __dreg, __addr, buf, __sz); \
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,9 +46,9 @@ static struct nrf5_802154_data nrf5_data;
|
||||||
#define NRF5_802154_CFG(dev) \
|
#define NRF5_802154_CFG(dev) \
|
||||||
((struct nrf5_802154_config * const)(dev)->config->config_info)
|
((struct nrf5_802154_config * const)(dev)->config->config_info)
|
||||||
|
|
||||||
static void nrf5_get_eui64(uint8_t *mac)
|
static void nrf5_get_eui64(u8_t *mac)
|
||||||
{
|
{
|
||||||
memcpy(mac, (const uint32_t *)&NRF_FICR->DEVICEID, 8);
|
memcpy(mac, (const u32_t *)&NRF_FICR->DEVICEID, 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void nrf5_rx_thread(void *arg1, void *arg2, void *arg3)
|
static void nrf5_rx_thread(void *arg1, void *arg2, void *arg3)
|
||||||
|
@ -58,7 +58,7 @@ static void nrf5_rx_thread(void *arg1, void *arg2, void *arg3)
|
||||||
struct net_buf *frag = NULL;
|
struct net_buf *frag = NULL;
|
||||||
enum net_verdict ack_result;
|
enum net_verdict ack_result;
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
uint8_t pkt_len;
|
u8_t pkt_len;
|
||||||
|
|
||||||
ARG_UNUSED(arg2);
|
ARG_UNUSED(arg2);
|
||||||
ARG_UNUSED(arg3);
|
ARG_UNUSED(arg3);
|
||||||
|
@ -162,7 +162,7 @@ static int nrf5_cca(struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nrf5_set_channel(struct device *dev, uint16_t channel)
|
static int nrf5_set_channel(struct device *dev, u16_t channel)
|
||||||
{
|
{
|
||||||
struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev);
|
struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev);
|
||||||
|
|
||||||
|
@ -180,9 +180,9 @@ static int nrf5_set_channel(struct device *dev, uint16_t channel)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nrf5_set_pan_id(struct device *dev, uint16_t pan_id)
|
static int nrf5_set_pan_id(struct device *dev, u16_t pan_id)
|
||||||
{
|
{
|
||||||
uint8_t pan_id_le[2];
|
u8_t pan_id_le[2];
|
||||||
|
|
||||||
ARG_UNUSED(dev);
|
ARG_UNUSED(dev);
|
||||||
|
|
||||||
|
@ -193,9 +193,9 @@ static int nrf5_set_pan_id(struct device *dev, uint16_t pan_id)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nrf5_set_short_addr(struct device *dev, uint16_t short_addr)
|
static int nrf5_set_short_addr(struct device *dev, u16_t short_addr)
|
||||||
{
|
{
|
||||||
uint8_t short_addr_le[2];
|
u8_t short_addr_le[2];
|
||||||
|
|
||||||
ARG_UNUSED(dev);
|
ARG_UNUSED(dev);
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ static int nrf5_set_short_addr(struct device *dev, uint16_t short_addr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nrf5_set_ieee_addr(struct device *dev, const uint8_t *ieee_addr)
|
static int nrf5_set_ieee_addr(struct device *dev, const u8_t *ieee_addr)
|
||||||
{
|
{
|
||||||
ARG_UNUSED(dev);
|
ARG_UNUSED(dev);
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ static int nrf5_set_ieee_addr(struct device *dev, const uint8_t *ieee_addr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int nrf5_set_txpower(struct device *dev, int16_t dbm)
|
static int nrf5_set_txpower(struct device *dev, s16_t dbm)
|
||||||
{
|
{
|
||||||
struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev);
|
struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev);
|
||||||
|
|
||||||
|
@ -234,8 +234,8 @@ static int nrf5_tx(struct device *dev,
|
||||||
struct net_buf *frag)
|
struct net_buf *frag)
|
||||||
{
|
{
|
||||||
struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev);
|
struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev);
|
||||||
uint8_t payload_len = net_pkt_ll_reserve(pkt) + frag->len;
|
u8_t payload_len = net_pkt_ll_reserve(pkt) + frag->len;
|
||||||
uint8_t *payload = frag->data - net_pkt_ll_reserve(pkt);
|
u8_t *payload = frag->data - net_pkt_ll_reserve(pkt);
|
||||||
|
|
||||||
SYS_LOG_DBG("%p (%u)", payload, payload_len);
|
SYS_LOG_DBG("%p (%u)", payload, payload_len);
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ static int nrf5_stop(struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t nrf5_get_lqi(struct device *dev)
|
static u8_t nrf5_get_lqi(struct device *dev)
|
||||||
{
|
{
|
||||||
struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev);
|
struct nrf5_802154_data *nrf5_radio = NRF5_802154_DATA(dev);
|
||||||
|
|
||||||
|
@ -365,7 +365,7 @@ static void nrf5_iface_init(struct net_if *iface)
|
||||||
|
|
||||||
/* nRF5 radio driver callbacks */
|
/* nRF5 radio driver callbacks */
|
||||||
|
|
||||||
void nrf_drv_radio802154_received(uint8_t *p_data, int8_t power, int8_t lqi)
|
void nrf_drv_radio802154_received(u8_t *p_data, s8_t power, s8_t lqi)
|
||||||
{
|
{
|
||||||
nrf5_data.rx_psdu = p_data;
|
nrf5_data.rx_psdu = p_data;
|
||||||
nrf5_data.rssi = power;
|
nrf5_data.rssi = power;
|
||||||
|
@ -387,7 +387,7 @@ void nrf_drv_radio802154_busy_channel(void)
|
||||||
k_sem_give(&nrf5_data.tx_wait);
|
k_sem_give(&nrf5_data.tx_wait);
|
||||||
}
|
}
|
||||||
|
|
||||||
void nrf_drv_radio802154_energy_detected(int8_t result)
|
void nrf_drv_radio802154_energy_detected(s8_t result)
|
||||||
{
|
{
|
||||||
nrf5_data.channel_ed = result;
|
nrf5_data.channel_ed = result;
|
||||||
k_sem_give(&nrf5_data.cca_wait);
|
k_sem_give(&nrf5_data.cca_wait);
|
||||||
|
|
|
@ -19,13 +19,13 @@ struct nrf5_802154_data {
|
||||||
/* Pointer to the network interface. */
|
/* Pointer to the network interface. */
|
||||||
struct net_if *iface;
|
struct net_if *iface;
|
||||||
/* Pointer to a received frame. */
|
/* Pointer to a received frame. */
|
||||||
uint8_t *rx_psdu;
|
u8_t *rx_psdu;
|
||||||
/* TX buffer. First byte is PHR (length), remaining bytes are
|
/* TX buffer. First byte is PHR (length), remaining bytes are
|
||||||
* MPDU data.
|
* MPDU data.
|
||||||
*/
|
*/
|
||||||
uint8_t tx_psdu[NRF5_PHR_LENGTH + NRF5_PSDU_LENGTH];
|
u8_t tx_psdu[NRF5_PHR_LENGTH + NRF5_PSDU_LENGTH];
|
||||||
/* 802.15.4 HW address. */
|
/* 802.15.4 HW address. */
|
||||||
uint8_t mac[8];
|
u8_t mac[8];
|
||||||
/* RX thread stack. */
|
/* RX thread stack. */
|
||||||
char __stack rx_stack[CONFIG_IEEE802154_NRF5_RX_STACK_SIZE];
|
char __stack rx_stack[CONFIG_IEEE802154_NRF5_RX_STACK_SIZE];
|
||||||
|
|
||||||
|
@ -43,17 +43,17 @@ struct nrf5_802154_data {
|
||||||
bool tx_success;
|
bool tx_success;
|
||||||
|
|
||||||
/* CCA channel energy. Unit as per 802.15.4-2006 specification. */
|
/* CCA channel energy. Unit as per 802.15.4-2006 specification. */
|
||||||
int8_t channel_ed;
|
s8_t channel_ed;
|
||||||
|
|
||||||
/* TX power, in dBm, to be used when sending a frame. */
|
/* TX power, in dBm, to be used when sending a frame. */
|
||||||
int8_t txpower;
|
s8_t txpower;
|
||||||
/* 802.15.4 channel to be used when sending a frame. */
|
/* 802.15.4 channel to be used when sending a frame. */
|
||||||
uint8_t channel;
|
u8_t channel;
|
||||||
|
|
||||||
/* Last received frame LQI value. */
|
/* Last received frame LQI value. */
|
||||||
uint8_t lqi;
|
u8_t lqi;
|
||||||
/* Last received frame RSSI value. */
|
/* Last received frame RSSI value. */
|
||||||
int8_t rssi;
|
s8_t rssi;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __IEEE802154_NRF5_H__ */
|
#endif /* __IEEE802154_NRF5_H__ */
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
/** Singleton device used in uart pipe callback */
|
/** Singleton device used in uart pipe callback */
|
||||||
static struct device *upipe_dev;
|
static struct device *upipe_dev;
|
||||||
|
|
||||||
static uint8_t *upipe_rx(uint8_t *buf, size_t *off)
|
static u8_t *upipe_rx(u8_t *buf, size_t *off)
|
||||||
{
|
{
|
||||||
struct upipe_context *upipe = upipe_dev->driver_data;
|
struct upipe_context *upipe = upipe_dev->driver_data;
|
||||||
struct net_pkt *pkt = NULL;
|
struct net_pkt *pkt = NULL;
|
||||||
|
@ -107,7 +107,7 @@ static int upipe_cca(struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int upipe_set_channel(struct device *dev, uint16_t channel)
|
static int upipe_set_channel(struct device *dev, u16_t channel)
|
||||||
{
|
{
|
||||||
struct upipe_context *upipe = dev->driver_data;
|
struct upipe_context *upipe = dev->driver_data;
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ static int upipe_set_channel(struct device *dev, uint16_t channel)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int upipe_set_pan_id(struct device *dev, uint16_t pan_id)
|
static int upipe_set_pan_id(struct device *dev, u16_t pan_id)
|
||||||
{
|
{
|
||||||
struct upipe_context *upipe = dev->driver_data;
|
struct upipe_context *upipe = dev->driver_data;
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ static int upipe_set_pan_id(struct device *dev, uint16_t pan_id)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int upipe_set_short_addr(struct device *dev, uint16_t short_addr)
|
static int upipe_set_short_addr(struct device *dev, u16_t short_addr)
|
||||||
{
|
{
|
||||||
struct upipe_context *upipe = dev->driver_data;
|
struct upipe_context *upipe = dev->driver_data;
|
||||||
|
|
||||||
|
@ -140,7 +140,7 @@ static int upipe_set_short_addr(struct device *dev, uint16_t short_addr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int upipe_set_ieee_addr(struct device *dev, const uint8_t *ieee_addr)
|
static int upipe_set_ieee_addr(struct device *dev, const u8_t *ieee_addr)
|
||||||
{
|
{
|
||||||
struct upipe_context *upipe = dev->driver_data;
|
struct upipe_context *upipe = dev->driver_data;
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ static int upipe_set_ieee_addr(struct device *dev, const uint8_t *ieee_addr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int upipe_set_txpower(struct device *dev, int16_t dbm)
|
static int upipe_set_txpower(struct device *dev, s16_t dbm)
|
||||||
{
|
{
|
||||||
struct upipe_context *upipe = dev->driver_data;
|
struct upipe_context *upipe = dev->driver_data;
|
||||||
|
|
||||||
|
@ -166,10 +166,10 @@ static int upipe_tx(struct device *dev,
|
||||||
struct net_pkt *pkt,
|
struct net_pkt *pkt,
|
||||||
struct net_buf *frag)
|
struct net_buf *frag)
|
||||||
{
|
{
|
||||||
uint8_t *pkt_buf = frag->data - net_pkt_ll_reserve(pkt);
|
u8_t *pkt_buf = frag->data - net_pkt_ll_reserve(pkt);
|
||||||
uint8_t len = net_pkt_ll_reserve(pkt) + frag->len;
|
u8_t len = net_pkt_ll_reserve(pkt) + frag->len;
|
||||||
struct upipe_context *upipe = dev->driver_data;
|
struct upipe_context *upipe = dev->driver_data;
|
||||||
uint8_t i, data;
|
u8_t i, data;
|
||||||
|
|
||||||
SYS_LOG_DBG("%p (%u)", frag, len);
|
SYS_LOG_DBG("%p (%u)", frag, len);
|
||||||
|
|
||||||
|
@ -234,7 +234,7 @@ static int upipe_init(struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t *get_mac(struct device *dev)
|
static inline u8_t *get_mac(struct device *dev)
|
||||||
{
|
{
|
||||||
struct upipe_context *upipe = dev->driver_data;
|
struct upipe_context *upipe = dev->driver_data;
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ static inline uint8_t *get_mac(struct device *dev)
|
||||||
upipe->mac_addr[3] = 0x30;
|
upipe->mac_addr[3] = 0x30;
|
||||||
|
|
||||||
UNALIGNED_PUT(sys_cpu_to_be32(sys_rand32_get()),
|
UNALIGNED_PUT(sys_cpu_to_be32(sys_rand32_get()),
|
||||||
(uint32_t *) ((void *)upipe->mac_addr+4));
|
(u32_t *) ((void *)upipe->mac_addr+4));
|
||||||
|
|
||||||
return upipe->mac_addr;
|
return upipe->mac_addr;
|
||||||
}
|
}
|
||||||
|
@ -253,7 +253,7 @@ static void upipe_iface_init(struct net_if *iface)
|
||||||
{
|
{
|
||||||
struct device *dev = net_if_get_device(iface);
|
struct device *dev = net_if_get_device(iface);
|
||||||
struct upipe_context *upipe = dev->driver_data;
|
struct upipe_context *upipe = dev->driver_data;
|
||||||
uint8_t *mac = get_mac(dev);
|
u8_t *mac = get_mac(dev);
|
||||||
|
|
||||||
SYS_LOG_DBG("");
|
SYS_LOG_DBG("");
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,14 @@
|
||||||
|
|
||||||
struct upipe_context {
|
struct upipe_context {
|
||||||
struct net_if *iface;
|
struct net_if *iface;
|
||||||
uint8_t mac_addr[8];
|
u8_t mac_addr[8];
|
||||||
bool stopped;
|
bool stopped;
|
||||||
/** RX specific attributes */
|
/** RX specific attributes */
|
||||||
uint8_t uart_pipe_buf[1];
|
u8_t uart_pipe_buf[1];
|
||||||
bool rx;
|
bool rx;
|
||||||
uint8_t rx_len;
|
u8_t rx_len;
|
||||||
uint8_t rx_off;
|
u8_t rx_off;
|
||||||
uint8_t rx_buf[127];
|
u8_t rx_buf[127];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __IEEE802154_UART_PIPE_H__ */
|
#endif /* __IEEE802154_UART_PIPE_H__ */
|
||||||
|
|
|
@ -19,7 +19,7 @@ enum cc2520_gpio_index {
|
||||||
|
|
||||||
struct cc2520_gpio_configuration {
|
struct cc2520_gpio_configuration {
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
uint32_t pin;
|
u32_t pin;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct cc2520_gpio_configuration *cc2520_configure_gpios(void);
|
struct cc2520_gpio_configuration *cc2520_configure_gpios(void);
|
||||||
|
|
|
@ -20,11 +20,11 @@
|
||||||
#define NET_ARP_HDR(pkt) ((struct net_arp_hdr *)net_pkt_ip_data(pkt))
|
#define NET_ARP_HDR(pkt) ((struct net_arp_hdr *)net_pkt_ip_data(pkt))
|
||||||
|
|
||||||
struct net_arp_hdr {
|
struct net_arp_hdr {
|
||||||
uint16_t hwtype; /* HTYPE */
|
u16_t hwtype; /* HTYPE */
|
||||||
uint16_t protocol; /* PTYPE */
|
u16_t protocol; /* PTYPE */
|
||||||
uint8_t hwlen; /* HLEN */
|
u8_t hwlen; /* HLEN */
|
||||||
uint8_t protolen; /* PLEN */
|
u8_t protolen; /* PLEN */
|
||||||
uint16_t opcode;
|
u16_t opcode;
|
||||||
struct net_eth_addr src_hwaddr; /* SHA */
|
struct net_eth_addr src_hwaddr; /* SHA */
|
||||||
struct in_addr src_ipaddr; /* SPA */
|
struct in_addr src_ipaddr; /* SPA */
|
||||||
struct net_eth_addr dst_hwaddr; /* THA */
|
struct net_eth_addr dst_hwaddr; /* THA */
|
||||||
|
|
|
@ -40,7 +40,7 @@ extern "C" {
|
||||||
#define NET_BUF_SIMPLE(_size) \
|
#define NET_BUF_SIMPLE(_size) \
|
||||||
((struct net_buf_simple *)(&(struct { \
|
((struct net_buf_simple *)(&(struct { \
|
||||||
struct net_buf_simple buf; \
|
struct net_buf_simple buf; \
|
||||||
uint8_t data[_size] __net_buf_align; \
|
u8_t data[_size] __net_buf_align; \
|
||||||
}) { \
|
}) { \
|
||||||
.buf.size = _size, \
|
.buf.size = _size, \
|
||||||
}))
|
}))
|
||||||
|
@ -60,18 +60,18 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
struct net_buf_simple {
|
struct net_buf_simple {
|
||||||
/** Pointer to the start of data in the buffer. */
|
/** Pointer to the start of data in the buffer. */
|
||||||
uint8_t *data;
|
u8_t *data;
|
||||||
|
|
||||||
/** Length of the data behind the data pointer. */
|
/** Length of the data behind the data pointer. */
|
||||||
uint16_t len;
|
u16_t len;
|
||||||
|
|
||||||
/** Amount of data that this buffer can store. */
|
/** Amount of data that this buffer can store. */
|
||||||
uint16_t size;
|
u16_t size;
|
||||||
|
|
||||||
/** Start of the data storage. Not to be accessed directly
|
/** Start of the data storage. Not to be accessed directly
|
||||||
* (the data pointer should be used instead).
|
* (the data pointer should be used instead).
|
||||||
*/
|
*/
|
||||||
uint8_t __buf[0] __net_buf_align;
|
u8_t __buf[0] __net_buf_align;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @brief Initialize a net_buf_simple object.
|
/** @brief Initialize a net_buf_simple object.
|
||||||
|
@ -128,7 +128,7 @@ void *net_buf_simple_add_mem(struct net_buf_simple *buf, const void *mem,
|
||||||
*
|
*
|
||||||
* @return Pointer to the value added
|
* @return Pointer to the value added
|
||||||
*/
|
*/
|
||||||
uint8_t *net_buf_simple_add_u8(struct net_buf_simple *buf, uint8_t val);
|
u8_t *net_buf_simple_add_u8(struct net_buf_simple *buf, u8_t val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add 16-bit value at the end of the buffer
|
* @brief Add 16-bit value at the end of the buffer
|
||||||
|
@ -140,7 +140,7 @@ uint8_t *net_buf_simple_add_u8(struct net_buf_simple *buf, uint8_t val);
|
||||||
* @param buf Buffer to update.
|
* @param buf Buffer to update.
|
||||||
* @param val 16-bit value to be added.
|
* @param val 16-bit value to be added.
|
||||||
*/
|
*/
|
||||||
void net_buf_simple_add_le16(struct net_buf_simple *buf, uint16_t val);
|
void net_buf_simple_add_le16(struct net_buf_simple *buf, u16_t val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add 16-bit value at the end of the buffer
|
* @brief Add 16-bit value at the end of the buffer
|
||||||
|
@ -152,7 +152,7 @@ void net_buf_simple_add_le16(struct net_buf_simple *buf, uint16_t val);
|
||||||
* @param buf Buffer to update.
|
* @param buf Buffer to update.
|
||||||
* @param val 16-bit value to be added.
|
* @param val 16-bit value to be added.
|
||||||
*/
|
*/
|
||||||
void net_buf_simple_add_be16(struct net_buf_simple *buf, uint16_t val);
|
void net_buf_simple_add_be16(struct net_buf_simple *buf, u16_t val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add 32-bit value at the end of the buffer
|
* @brief Add 32-bit value at the end of the buffer
|
||||||
|
@ -164,7 +164,7 @@ void net_buf_simple_add_be16(struct net_buf_simple *buf, uint16_t val);
|
||||||
* @param buf Buffer to update.
|
* @param buf Buffer to update.
|
||||||
* @param val 32-bit value to be added.
|
* @param val 32-bit value to be added.
|
||||||
*/
|
*/
|
||||||
void net_buf_simple_add_le32(struct net_buf_simple *buf, uint32_t val);
|
void net_buf_simple_add_le32(struct net_buf_simple *buf, u32_t val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add 32-bit value at the end of the buffer
|
* @brief Add 32-bit value at the end of the buffer
|
||||||
|
@ -176,7 +176,7 @@ void net_buf_simple_add_le32(struct net_buf_simple *buf, uint32_t val);
|
||||||
* @param buf Buffer to update.
|
* @param buf Buffer to update.
|
||||||
* @param val 32-bit value to be added.
|
* @param val 32-bit value to be added.
|
||||||
*/
|
*/
|
||||||
void net_buf_simple_add_be32(struct net_buf_simple *buf, uint32_t val);
|
void net_buf_simple_add_be32(struct net_buf_simple *buf, u32_t val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Push data to the beginning of the buffer.
|
* @brief Push data to the beginning of the buffer.
|
||||||
|
@ -200,7 +200,7 @@ void *net_buf_simple_push(struct net_buf_simple *buf, size_t len);
|
||||||
* @param buf Buffer to update.
|
* @param buf Buffer to update.
|
||||||
* @param val 16-bit value to be pushed to the buffer.
|
* @param val 16-bit value to be pushed to the buffer.
|
||||||
*/
|
*/
|
||||||
void net_buf_simple_push_le16(struct net_buf_simple *buf, uint16_t val);
|
void net_buf_simple_push_le16(struct net_buf_simple *buf, u16_t val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Push 16-bit value to the beginning of the buffer
|
* @brief Push 16-bit value to the beginning of the buffer
|
||||||
|
@ -211,7 +211,7 @@ void net_buf_simple_push_le16(struct net_buf_simple *buf, uint16_t val);
|
||||||
* @param buf Buffer to update.
|
* @param buf Buffer to update.
|
||||||
* @param val 16-bit value to be pushed to the buffer.
|
* @param val 16-bit value to be pushed to the buffer.
|
||||||
*/
|
*/
|
||||||
void net_buf_simple_push_be16(struct net_buf_simple *buf, uint16_t val);
|
void net_buf_simple_push_be16(struct net_buf_simple *buf, u16_t val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Push 8-bit value to the beginning of the buffer
|
* @brief Push 8-bit value to the beginning of the buffer
|
||||||
|
@ -221,7 +221,7 @@ void net_buf_simple_push_be16(struct net_buf_simple *buf, uint16_t val);
|
||||||
* @param buf Buffer to update.
|
* @param buf Buffer to update.
|
||||||
* @param val 8-bit value to be pushed to the buffer.
|
* @param val 8-bit value to be pushed to the buffer.
|
||||||
*/
|
*/
|
||||||
void net_buf_simple_push_u8(struct net_buf_simple *buf, uint8_t val);
|
void net_buf_simple_push_u8(struct net_buf_simple *buf, u8_t val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remove data from the beginning of the buffer.
|
* @brief Remove data from the beginning of the buffer.
|
||||||
|
@ -246,7 +246,7 @@ void *net_buf_simple_pull(struct net_buf_simple *buf, size_t len);
|
||||||
*
|
*
|
||||||
* @return The 8-bit removed value
|
* @return The 8-bit removed value
|
||||||
*/
|
*/
|
||||||
uint8_t net_buf_simple_pull_u8(struct net_buf_simple *buf);
|
u8_t net_buf_simple_pull_u8(struct net_buf_simple *buf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remove and convert 16 bits from the beginning of the buffer.
|
* @brief Remove and convert 16 bits from the beginning of the buffer.
|
||||||
|
@ -258,7 +258,7 @@ uint8_t net_buf_simple_pull_u8(struct net_buf_simple *buf);
|
||||||
*
|
*
|
||||||
* @return 16-bit value converted from little endian to host endian.
|
* @return 16-bit value converted from little endian to host endian.
|
||||||
*/
|
*/
|
||||||
uint16_t net_buf_simple_pull_le16(struct net_buf_simple *buf);
|
u16_t net_buf_simple_pull_le16(struct net_buf_simple *buf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remove and convert 16 bits from the beginning of the buffer.
|
* @brief Remove and convert 16 bits from the beginning of the buffer.
|
||||||
|
@ -270,7 +270,7 @@ uint16_t net_buf_simple_pull_le16(struct net_buf_simple *buf);
|
||||||
*
|
*
|
||||||
* @return 16-bit value converted from big endian to host endian.
|
* @return 16-bit value converted from big endian to host endian.
|
||||||
*/
|
*/
|
||||||
uint16_t net_buf_simple_pull_be16(struct net_buf_simple *buf);
|
u16_t net_buf_simple_pull_be16(struct net_buf_simple *buf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remove and convert 32 bits from the beginning of the buffer.
|
* @brief Remove and convert 32 bits from the beginning of the buffer.
|
||||||
|
@ -282,7 +282,7 @@ uint16_t net_buf_simple_pull_be16(struct net_buf_simple *buf);
|
||||||
*
|
*
|
||||||
* @return 32-bit value converted from little endian to host endian.
|
* @return 32-bit value converted from little endian to host endian.
|
||||||
*/
|
*/
|
||||||
uint32_t net_buf_simple_pull_le32(struct net_buf_simple *buf);
|
u32_t net_buf_simple_pull_le32(struct net_buf_simple *buf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remove and convert 32 bits from the beginning of the buffer.
|
* @brief Remove and convert 32 bits from the beginning of the buffer.
|
||||||
|
@ -294,7 +294,7 @@ uint32_t net_buf_simple_pull_le32(struct net_buf_simple *buf);
|
||||||
*
|
*
|
||||||
* @return 32-bit value converted from big endian to host endian.
|
* @return 32-bit value converted from big endian to host endian.
|
||||||
*/
|
*/
|
||||||
uint32_t net_buf_simple_pull_be32(struct net_buf_simple *buf);
|
u32_t net_buf_simple_pull_be32(struct net_buf_simple *buf);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get the tail pointer for a buffer.
|
* @brief Get the tail pointer for a buffer.
|
||||||
|
@ -305,7 +305,7 @@ uint32_t net_buf_simple_pull_be32(struct net_buf_simple *buf);
|
||||||
*
|
*
|
||||||
* @return Tail pointer for the buffer.
|
* @return Tail pointer for the buffer.
|
||||||
*/
|
*/
|
||||||
static inline uint8_t *net_buf_simple_tail(struct net_buf_simple *buf)
|
static inline u8_t *net_buf_simple_tail(struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
return buf->data + buf->len;
|
return buf->data + buf->len;
|
||||||
}
|
}
|
||||||
|
@ -341,9 +341,9 @@ size_t net_buf_simple_tailroom(struct net_buf_simple *buf);
|
||||||
*/
|
*/
|
||||||
struct net_buf_simple_state {
|
struct net_buf_simple_state {
|
||||||
/** Offset of the data pointer from the beginning of the storage */
|
/** Offset of the data pointer from the beginning of the storage */
|
||||||
uint16_t offset;
|
u16_t offset;
|
||||||
/** Length of data */
|
/** Length of data */
|
||||||
uint16_t len;
|
u16_t len;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -402,10 +402,10 @@ struct net_buf {
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Reference count. */
|
/** Reference count. */
|
||||||
uint8_t ref;
|
u8_t ref;
|
||||||
|
|
||||||
/** Bit-field of buffer flags. */
|
/** Bit-field of buffer flags. */
|
||||||
uint8_t flags;
|
u8_t flags;
|
||||||
|
|
||||||
/** Where the buffer should go when freed up. */
|
/** Where the buffer should go when freed up. */
|
||||||
struct net_buf_pool *pool;
|
struct net_buf_pool *pool;
|
||||||
|
@ -417,13 +417,13 @@ struct net_buf {
|
||||||
/* The ABI of this struct must match net_buf_simple */
|
/* The ABI of this struct must match net_buf_simple */
|
||||||
struct {
|
struct {
|
||||||
/** Pointer to the start of data in the buffer. */
|
/** Pointer to the start of data in the buffer. */
|
||||||
uint8_t *data;
|
u8_t *data;
|
||||||
|
|
||||||
/** Length of the data behind the data pointer. */
|
/** Length of the data behind the data pointer. */
|
||||||
uint16_t len;
|
u16_t len;
|
||||||
|
|
||||||
/** Amount of data that this buffer can store. */
|
/** Amount of data that this buffer can store. */
|
||||||
uint16_t size;
|
u16_t size;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct net_buf_simple b;
|
struct net_buf_simple b;
|
||||||
|
@ -432,7 +432,7 @@ struct net_buf {
|
||||||
/** Start of the data storage. Not to be accessed directly
|
/** Start of the data storage. Not to be accessed directly
|
||||||
* (the data pointer should be used instead).
|
* (the data pointer should be used instead).
|
||||||
*/
|
*/
|
||||||
uint8_t __buf[0] __net_buf_align;
|
u8_t __buf[0] __net_buf_align;
|
||||||
|
|
||||||
/** After __buf (as given by the "size" field, which can be 0),
|
/** After __buf (as given by the "size" field, which can be 0),
|
||||||
* there may be so-called "user data", which is actually a system
|
* there may be so-called "user data", which is actually a system
|
||||||
|
@ -447,23 +447,23 @@ struct net_buf_pool {
|
||||||
struct k_lifo free;
|
struct k_lifo free;
|
||||||
|
|
||||||
/** Number of buffers in pool */
|
/** Number of buffers in pool */
|
||||||
const uint16_t buf_count;
|
const u16_t buf_count;
|
||||||
|
|
||||||
/** Number of uninitialized buffers */
|
/** Number of uninitialized buffers */
|
||||||
uint16_t uninit_count;
|
u16_t uninit_count;
|
||||||
|
|
||||||
/** Data size of each buffer in the pool */
|
/** Data size of each buffer in the pool */
|
||||||
const uint16_t buf_size;
|
const u16_t buf_size;
|
||||||
|
|
||||||
/** Size of the user data associated with each buffer. */
|
/** Size of the user data associated with each buffer. */
|
||||||
const uint16_t user_data_size;
|
const u16_t user_data_size;
|
||||||
|
|
||||||
#if defined(CONFIG_NET_BUF_POOL_USAGE)
|
#if defined(CONFIG_NET_BUF_POOL_USAGE)
|
||||||
/** Amount of available buffers in the pool. */
|
/** Amount of available buffers in the pool. */
|
||||||
int16_t avail_count;
|
s16_t avail_count;
|
||||||
|
|
||||||
/** Total size of the pool. */
|
/** Total size of the pool. */
|
||||||
const uint16_t pool_size;
|
const u16_t pool_size;
|
||||||
|
|
||||||
/** Name of the pool. Used when printing pool information. */
|
/** Name of the pool. Used when printing pool information. */
|
||||||
const char *name;
|
const char *name;
|
||||||
|
@ -528,8 +528,8 @@ struct net_buf_pool {
|
||||||
#define NET_BUF_POOL_DEFINE(_name, _count, _size, _ud_size, _destroy) \
|
#define NET_BUF_POOL_DEFINE(_name, _count, _size, _ud_size, _destroy) \
|
||||||
static struct { \
|
static struct { \
|
||||||
struct net_buf buf; \
|
struct net_buf buf; \
|
||||||
uint8_t data[_size] __net_buf_align; \
|
u8_t data[_size] __net_buf_align; \
|
||||||
uint8_t ud[ROUND_UP(_ud_size, 4)] __net_buf_align; \
|
u8_t ud[ROUND_UP(_ud_size, 4)] __net_buf_align; \
|
||||||
} _net_buf_pool_##_name[_count] __noinit; \
|
} _net_buf_pool_##_name[_count] __noinit; \
|
||||||
static struct net_buf_pool _name = \
|
static struct net_buf_pool _name = \
|
||||||
NET_BUF_POOL_INITIALIZER(_name, _net_buf_pool_##_name, \
|
NET_BUF_POOL_INITIALIZER(_name, _net_buf_pool_##_name, \
|
||||||
|
@ -549,12 +549,12 @@ struct net_buf_pool {
|
||||||
* @return New buffer or NULL if out of buffers.
|
* @return New buffer or NULL if out of buffers.
|
||||||
*/
|
*/
|
||||||
#if defined(CONFIG_NET_BUF_LOG)
|
#if defined(CONFIG_NET_BUF_LOG)
|
||||||
struct net_buf *net_buf_alloc_debug(struct net_buf_pool *pool, int32_t timeout,
|
struct net_buf *net_buf_alloc_debug(struct net_buf_pool *pool, s32_t timeout,
|
||||||
const char *func, int line);
|
const char *func, int line);
|
||||||
#define net_buf_alloc(_pool, _timeout) \
|
#define net_buf_alloc(_pool, _timeout) \
|
||||||
net_buf_alloc_debug(_pool, _timeout, __func__, __LINE__)
|
net_buf_alloc_debug(_pool, _timeout, __func__, __LINE__)
|
||||||
#else
|
#else
|
||||||
struct net_buf *net_buf_alloc(struct net_buf_pool *pool, int32_t timeout);
|
struct net_buf *net_buf_alloc(struct net_buf_pool *pool, s32_t timeout);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -571,12 +571,12 @@ struct net_buf *net_buf_alloc(struct net_buf_pool *pool, int32_t timeout);
|
||||||
* @return New buffer or NULL if the FIFO is empty.
|
* @return New buffer or NULL if the FIFO is empty.
|
||||||
*/
|
*/
|
||||||
#if defined(CONFIG_NET_BUF_LOG)
|
#if defined(CONFIG_NET_BUF_LOG)
|
||||||
struct net_buf *net_buf_get_debug(struct k_fifo *fifo, int32_t timeout,
|
struct net_buf *net_buf_get_debug(struct k_fifo *fifo, s32_t timeout,
|
||||||
const char *func, int line);
|
const char *func, int line);
|
||||||
#define net_buf_get(_fifo, _timeout) \
|
#define net_buf_get(_fifo, _timeout) \
|
||||||
net_buf_get_debug(_fifo, _timeout, __func__, __LINE__)
|
net_buf_get_debug(_fifo, _timeout, __func__, __LINE__)
|
||||||
#else
|
#else
|
||||||
struct net_buf *net_buf_get(struct k_fifo *fifo, int32_t timeout);
|
struct net_buf *net_buf_get(struct k_fifo *fifo, s32_t timeout);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -663,7 +663,7 @@ struct net_buf *net_buf_ref(struct net_buf *buf);
|
||||||
*
|
*
|
||||||
* @return Duplicated buffer or NULL if out of buffers.
|
* @return Duplicated buffer or NULL if out of buffers.
|
||||||
*/
|
*/
|
||||||
struct net_buf *net_buf_clone(struct net_buf *buf, int32_t timeout);
|
struct net_buf *net_buf_clone(struct net_buf *buf, s32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get a pointer to the user data of a buffer.
|
* @brief Get a pointer to the user data of a buffer.
|
||||||
|
|
|
@ -51,10 +51,10 @@ struct dns_addrinfo {
|
||||||
struct sockaddr ai_addr;
|
struct sockaddr ai_addr;
|
||||||
char ai_canonname[DNS_MAX_NAME_SIZE + 1];
|
char ai_canonname[DNS_MAX_NAME_SIZE + 1];
|
||||||
socklen_t ai_addrlen;
|
socklen_t ai_addrlen;
|
||||||
uint16_t ai_flags;
|
u16_t ai_flags;
|
||||||
uint8_t ai_family;
|
u8_t ai_family;
|
||||||
uint8_t ai_socktype;
|
u8_t ai_socktype;
|
||||||
uint8_t ai_protocol;
|
u8_t ai_protocol;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -118,7 +118,7 @@ struct dns_resolve_context {
|
||||||
/** This timeout is also used when a buffer is required from the
|
/** This timeout is also used when a buffer is required from the
|
||||||
* buffer pools.
|
* buffer pools.
|
||||||
*/
|
*/
|
||||||
int32_t buf_timeout;
|
s32_t buf_timeout;
|
||||||
|
|
||||||
/** Result callbacks. We have multiple callbacks here so that it is
|
/** Result callbacks. We have multiple callbacks here so that it is
|
||||||
* possible to do multiple queries at the same time.
|
* possible to do multiple queries at the same time.
|
||||||
|
@ -137,7 +137,7 @@ struct dns_resolve_context {
|
||||||
void *user_data;
|
void *user_data;
|
||||||
|
|
||||||
/** TX timeout */
|
/** TX timeout */
|
||||||
int32_t timeout;
|
s32_t timeout;
|
||||||
|
|
||||||
/** String containing the thing to resolve like www.example.com
|
/** String containing the thing to resolve like www.example.com
|
||||||
*/
|
*/
|
||||||
|
@ -147,7 +147,7 @@ struct dns_resolve_context {
|
||||||
enum dns_query_type query_type;
|
enum dns_query_type query_type;
|
||||||
|
|
||||||
/** DNS id of this query */
|
/** DNS id of this query */
|
||||||
uint16_t id;
|
u16_t id;
|
||||||
} queries[CONFIG_DNS_NUM_CONCUR_QUERIES];
|
} queries[CONFIG_DNS_NUM_CONCUR_QUERIES];
|
||||||
|
|
||||||
/** Is this context in use */
|
/** Is this context in use */
|
||||||
|
@ -203,7 +203,7 @@ int dns_resolve_close(struct dns_resolve_context *ctx);
|
||||||
* @return 0 if ok, <0 if error.
|
* @return 0 if ok, <0 if error.
|
||||||
*/
|
*/
|
||||||
int dns_resolve_cancel(struct dns_resolve_context *ctx,
|
int dns_resolve_cancel(struct dns_resolve_context *ctx,
|
||||||
uint16_t dns_id);
|
u16_t dns_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Resolve DNS name.
|
* @brief Resolve DNS name.
|
||||||
|
@ -235,10 +235,10 @@ int dns_resolve_cancel(struct dns_resolve_context *ctx,
|
||||||
int dns_resolve_name(struct dns_resolve_context *ctx,
|
int dns_resolve_name(struct dns_resolve_context *ctx,
|
||||||
const char *query,
|
const char *query,
|
||||||
enum dns_query_type type,
|
enum dns_query_type type,
|
||||||
uint16_t *dns_id,
|
u16_t *dns_id,
|
||||||
dns_resolve_cb_t cb,
|
dns_resolve_cb_t cb,
|
||||||
void *user_data,
|
void *user_data,
|
||||||
int32_t timeout);
|
s32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get default DNS context.
|
* @brief Get default DNS context.
|
||||||
|
@ -281,10 +281,10 @@ struct dns_resolve_context *dns_resolve_get_default(void);
|
||||||
*/
|
*/
|
||||||
static inline int dns_get_addr_info(const char *query,
|
static inline int dns_get_addr_info(const char *query,
|
||||||
enum dns_query_type type,
|
enum dns_query_type type,
|
||||||
uint16_t *dns_id,
|
u16_t *dns_id,
|
||||||
dns_resolve_cb_t cb,
|
dns_resolve_cb_t cb,
|
||||||
void *user_data,
|
void *user_data,
|
||||||
int32_t timeout)
|
s32_t timeout)
|
||||||
{
|
{
|
||||||
return dns_resolve_name(dns_resolve_get_default(),
|
return dns_resolve_name(dns_resolve_get_default(),
|
||||||
query,
|
query,
|
||||||
|
@ -304,7 +304,7 @@ static inline int dns_get_addr_info(const char *query,
|
||||||
*
|
*
|
||||||
* @return 0 if ok, <0 if error.
|
* @return 0 if ok, <0 if error.
|
||||||
*/
|
*/
|
||||||
static inline int dns_cancel_addr_info(uint16_t dns_id)
|
static inline int dns_cancel_addr_info(u16_t dns_id)
|
||||||
{
|
{
|
||||||
return dns_resolve_cancel(dns_resolve_get_default(), dns_id);
|
return dns_resolve_cancel(dns_resolve_get_default(), dns_id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,13 +29,13 @@
|
||||||
#define NET_ETH_MINIMAL_FRAME_SIZE 60
|
#define NET_ETH_MINIMAL_FRAME_SIZE 60
|
||||||
|
|
||||||
struct net_eth_addr {
|
struct net_eth_addr {
|
||||||
uint8_t addr[6];
|
u8_t addr[6];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct net_eth_hdr {
|
struct net_eth_hdr {
|
||||||
struct net_eth_addr dst;
|
struct net_eth_addr dst;
|
||||||
struct net_eth_addr src;
|
struct net_eth_addr src;
|
||||||
uint16_t type;
|
u16_t type;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
static inline bool net_eth_is_addr_broadcast(struct net_eth_addr *addr)
|
static inline bool net_eth_is_addr_broadcast(struct net_eth_addr *addr)
|
||||||
|
|
|
@ -30,22 +30,22 @@ struct http_client_request {
|
||||||
/** Payload, may be NULL */
|
/** Payload, may be NULL */
|
||||||
char *payload;
|
char *payload;
|
||||||
/** Payload size, may be 0 */
|
/** Payload size, may be 0 */
|
||||||
uint16_t payload_size;
|
u16_t payload_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
int http_request(struct net_context *net_ctx, int32_t timeout,
|
int http_request(struct net_context *net_ctx, s32_t timeout,
|
||||||
struct http_client_request *req);
|
struct http_client_request *req);
|
||||||
|
|
||||||
int http_request_get(struct net_context *net_ctx, int32_t timeout, char *url,
|
int http_request_get(struct net_context *net_ctx, s32_t timeout, char *url,
|
||||||
char *header_fields);
|
char *header_fields);
|
||||||
|
|
||||||
int http_request_head(struct net_context *net_ctx, int32_t timeout, char *url,
|
int http_request_head(struct net_context *net_ctx, s32_t timeout, char *url,
|
||||||
char *header_fields);
|
char *header_fields);
|
||||||
|
|
||||||
int http_request_options(struct net_context *net_ctx, int32_t timeout,
|
int http_request_options(struct net_context *net_ctx, s32_t timeout,
|
||||||
char *url, char *header_fields);
|
char *url, char *header_fields);
|
||||||
|
|
||||||
int http_request_post(struct net_context *net_ctx, int32_t timeout, char *url,
|
int http_request_post(struct net_context *net_ctx, s32_t timeout, char *url,
|
||||||
char *header_fields, char *content_type_value,
|
char *header_fields, char *content_type_value,
|
||||||
char *payload);
|
char *payload);
|
||||||
#endif
|
#endif
|
||||||
|
@ -71,35 +71,35 @@ struct http_field_value {
|
||||||
*/
|
*/
|
||||||
const char *key;
|
const char *key;
|
||||||
/** Length of the field name */
|
/** Length of the field name */
|
||||||
uint16_t key_len;
|
u16_t key_len;
|
||||||
|
|
||||||
/** Value, this variable will point to the beginning of the string
|
/** Value, this variable will point to the beginning of the string
|
||||||
* containing the field value
|
* containing the field value
|
||||||
*/
|
*/
|
||||||
const char *value;
|
const char *value;
|
||||||
/** Length of the field value */
|
/** Length of the field value */
|
||||||
uint16_t value_len;
|
u16_t value_len;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* The HTTP server context struct */
|
/* The HTTP server context struct */
|
||||||
struct http_server_ctx {
|
struct http_server_ctx {
|
||||||
uint8_t state;
|
u8_t state;
|
||||||
|
|
||||||
/** Collection of header fields */
|
/** Collection of header fields */
|
||||||
struct http_field_value field_values[CONFIG_HTTP_HEADER_FIELD_ITEMS];
|
struct http_field_value field_values[CONFIG_HTTP_HEADER_FIELD_ITEMS];
|
||||||
/** Number of header field elements */
|
/** Number of header field elements */
|
||||||
uint16_t field_values_ctr;
|
u16_t field_values_ctr;
|
||||||
|
|
||||||
/** HTTP Request URL */
|
/** HTTP Request URL */
|
||||||
const char *url;
|
const char *url;
|
||||||
/** URL's length */
|
/** URL's length */
|
||||||
uint16_t url_len;
|
u16_t url_len;
|
||||||
|
|
||||||
/**IP stack network context */
|
/**IP stack network context */
|
||||||
struct net_context *net_ctx;
|
struct net_context *net_ctx;
|
||||||
|
|
||||||
/** Network timeout */
|
/** Network timeout */
|
||||||
int32_t timeout;
|
s32_t timeout;
|
||||||
|
|
||||||
#if defined(CONFIG_HTTP_PARSER)
|
#if defined(CONFIG_HTTP_PARSER)
|
||||||
/** HTTP parser */
|
/** HTTP parser */
|
||||||
|
|
|
@ -34,14 +34,14 @@ extern "C" {
|
||||||
(!defined(_MSC_VER) || _MSC_VER < 1600) && !defined(__WINE__)
|
(!defined(_MSC_VER) || _MSC_VER < 1600) && !defined(__WINE__)
|
||||||
#include <BaseTsd.h>
|
#include <BaseTsd.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
typedef __int8 int8_t;
|
typedef __int8 s8_t;
|
||||||
typedef unsigned __int8 uint8_t;
|
typedef unsigned __int8 u8_t;
|
||||||
typedef __int16 int16_t;
|
typedef __int16 s16_t;
|
||||||
typedef unsigned __int16 uint16_t;
|
typedef unsigned __int16 u16_t;
|
||||||
typedef __int32 int32_t;
|
typedef __int32 s32_t;
|
||||||
typedef unsigned __int32 uint32_t;
|
typedef unsigned __int32 u32_t;
|
||||||
typedef __int64 int64_t;
|
typedef __int64 s64_t;
|
||||||
typedef unsigned __int64 uint64_t;
|
typedef unsigned __int64 u64_t;
|
||||||
#else
|
#else
|
||||||
#include <zephyr/types.h>
|
#include <zephyr/types.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
@ -186,8 +186,8 @@ struct http_parser {
|
||||||
unsigned int index : 7; /* index into current matcher */
|
unsigned int index : 7; /* index into current matcher */
|
||||||
unsigned int lenient_http_headers : 1;
|
unsigned int lenient_http_headers : 1;
|
||||||
|
|
||||||
uint32_t nread; /* # bytes read in various scenarios */
|
u32_t nread; /* # bytes read in various scenarios */
|
||||||
uint64_t content_length; /* # bytes in body (0 if no Content-Length
|
u64_t content_length; /* # bytes in body (0 if no Content-Length
|
||||||
* header)
|
* header)
|
||||||
*/
|
*/
|
||||||
/** READ-ONLY **/
|
/** READ-ONLY **/
|
||||||
|
@ -246,17 +246,17 @@ enum http_parser_url_fields {
|
||||||
* Callers should index into field_data[] with UF_* values iff field_set
|
* Callers should index into field_data[] with UF_* values iff field_set
|
||||||
* has the relevant (1 << UF_*) bit set. As a courtesy to clients (and
|
* has the relevant (1 << UF_*) bit set. As a courtesy to clients (and
|
||||||
* because we probably have padding left over), we convert any port to
|
* because we probably have padding left over), we convert any port to
|
||||||
* a uint16_t.
|
* a u16_t.
|
||||||
*/
|
*/
|
||||||
struct http_parser_url {
|
struct http_parser_url {
|
||||||
uint16_t field_set; /* Bitmask of (1 << UF_*) values */
|
u16_t field_set; /* Bitmask of (1 << UF_*) values */
|
||||||
uint16_t port; /* Converted UF_PORT string */
|
u16_t port; /* Converted UF_PORT string */
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
uint16_t off; /* Offset into buffer in which field
|
u16_t off; /* Offset into buffer in which field
|
||||||
* starts
|
* starts
|
||||||
*/
|
*/
|
||||||
uint16_t len; /* Length of run in buffer */
|
u16_t len; /* Length of run in buffer */
|
||||||
} field_data[UF_MAX];
|
} field_data[UF_MAX];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -18,23 +18,23 @@
|
||||||
#define IEEE802154_MAX_ADDR_LENGTH 8
|
#define IEEE802154_MAX_ADDR_LENGTH 8
|
||||||
|
|
||||||
struct ieee802154_security_ctx {
|
struct ieee802154_security_ctx {
|
||||||
uint32_t frame_counter;
|
u32_t frame_counter;
|
||||||
struct cipher_ctx enc;
|
struct cipher_ctx enc;
|
||||||
struct cipher_ctx dec;
|
struct cipher_ctx dec;
|
||||||
uint8_t key[16];
|
u8_t key[16];
|
||||||
uint8_t key_len;
|
u8_t key_len;
|
||||||
uint8_t level : 3;
|
u8_t level : 3;
|
||||||
uint8_t key_mode : 2;
|
u8_t key_mode : 2;
|
||||||
uint8_t _unused : 3;
|
u8_t _unused : 3;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* This not meant to be used by any code but 802.15.4 L2 stack */
|
/* This not meant to be used by any code but 802.15.4 L2 stack */
|
||||||
struct ieee802154_context {
|
struct ieee802154_context {
|
||||||
uint16_t pan_id;
|
u16_t pan_id;
|
||||||
uint16_t channel;
|
u16_t channel;
|
||||||
struct k_sem ack_lock;
|
struct k_sem ack_lock;
|
||||||
uint16_t short_addr;
|
u16_t short_addr;
|
||||||
uint8_t ext_addr[IEEE802154_MAX_ADDR_LENGTH];
|
u8_t ext_addr[IEEE802154_MAX_ADDR_LENGTH];
|
||||||
#ifdef CONFIG_NET_L2_IEEE802154_MGMT
|
#ifdef CONFIG_NET_L2_IEEE802154_MGMT
|
||||||
struct ieee802154_req_params *scan_ctx;
|
struct ieee802154_req_params *scan_ctx;
|
||||||
union {
|
union {
|
||||||
|
@ -42,20 +42,20 @@ struct ieee802154_context {
|
||||||
struct k_sem req_lock;
|
struct k_sem req_lock;
|
||||||
};
|
};
|
||||||
union {
|
union {
|
||||||
uint8_t ext_addr[IEEE802154_MAX_ADDR_LENGTH];
|
u8_t ext_addr[IEEE802154_MAX_ADDR_LENGTH];
|
||||||
uint16_t short_addr;
|
u16_t short_addr;
|
||||||
} coord;
|
} coord;
|
||||||
uint8_t coord_addr_len;
|
u8_t coord_addr_len;
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_NET_L2_IEEE802154_SECURITY
|
#ifdef CONFIG_NET_L2_IEEE802154_SECURITY
|
||||||
struct ieee802154_security_ctx sec_ctx;
|
struct ieee802154_security_ctx sec_ctx;
|
||||||
#endif
|
#endif
|
||||||
int16_t tx_power;
|
s16_t tx_power;
|
||||||
uint8_t sequence;
|
u8_t sequence;
|
||||||
uint8_t ack_received : 1;
|
u8_t ack_received : 1;
|
||||||
uint8_t ack_requested : 1;
|
u8_t ack_requested : 1;
|
||||||
uint8_t associated : 1;
|
u8_t associated : 1;
|
||||||
uint8_t _unused : 5;
|
u8_t _unused : 5;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -219,26 +219,26 @@ enum net_event_ieee802154_cmd {
|
||||||
*/
|
*/
|
||||||
struct ieee802154_req_params {
|
struct ieee802154_req_params {
|
||||||
/** The set of channels to scan, use above macros to manage it */
|
/** The set of channels to scan, use above macros to manage it */
|
||||||
uint32_t channel_set;
|
u32_t channel_set;
|
||||||
|
|
||||||
/** Duration of scan, per-channel, in milliseconds */
|
/** Duration of scan, per-channel, in milliseconds */
|
||||||
uint32_t duration;
|
u32_t duration;
|
||||||
|
|
||||||
/** Current channel in use as a result */
|
/** Current channel in use as a result */
|
||||||
uint16_t channel;
|
u16_t channel;
|
||||||
/** Current pan_id in use as a result */
|
/** Current pan_id in use as a result */
|
||||||
uint16_t pan_id;
|
u16_t pan_id;
|
||||||
|
|
||||||
/** Result address */
|
/** Result address */
|
||||||
union {
|
union {
|
||||||
uint8_t addr[IEEE802154_MAX_ADDR_LENGTH];
|
u8_t addr[IEEE802154_MAX_ADDR_LENGTH];
|
||||||
uint16_t short_addr;
|
u16_t short_addr;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** length of address */
|
/** length of address */
|
||||||
uint8_t len;
|
u8_t len;
|
||||||
/** Link quality information, between 0 and 255 */
|
/** Link quality information, between 0 and 255 */
|
||||||
uint8_t lqi;
|
u8_t lqi;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -247,11 +247,11 @@ struct ieee802154_req_params {
|
||||||
* Used to setup the link-layer security settings
|
* Used to setup the link-layer security settings
|
||||||
*/
|
*/
|
||||||
struct ieee802154_security_params {
|
struct ieee802154_security_params {
|
||||||
uint8_t key[16];
|
u8_t key[16];
|
||||||
uint8_t key_len;
|
u8_t key_len;
|
||||||
uint8_t key_mode : 2;
|
u8_t key_mode : 2;
|
||||||
uint8_t level : 3;
|
u8_t level : 3;
|
||||||
uint8_t _unused : 3;
|
u8_t _unused : 3;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* __IEEE802154_H__ */
|
#endif /* __IEEE802154_H__ */
|
||||||
|
|
|
@ -28,19 +28,19 @@ struct ieee802154_radio_api {
|
||||||
int (*cca)(struct device *dev);
|
int (*cca)(struct device *dev);
|
||||||
|
|
||||||
/** Set current channel */
|
/** Set current channel */
|
||||||
int (*set_channel)(struct device *dev, uint16_t channel);
|
int (*set_channel)(struct device *dev, u16_t channel);
|
||||||
|
|
||||||
/** Set current PAN id */
|
/** Set current PAN id */
|
||||||
int (*set_pan_id)(struct device *dev, uint16_t pan_id);
|
int (*set_pan_id)(struct device *dev, u16_t pan_id);
|
||||||
|
|
||||||
/** Set current device's short address */
|
/** Set current device's short address */
|
||||||
int (*set_short_addr)(struct device *dev, uint16_t short_addr);
|
int (*set_short_addr)(struct device *dev, u16_t short_addr);
|
||||||
|
|
||||||
/** Set current devices's full length address */
|
/** Set current devices's full length address */
|
||||||
int (*set_ieee_addr)(struct device *dev, const uint8_t *ieee_addr);
|
int (*set_ieee_addr)(struct device *dev, const u8_t *ieee_addr);
|
||||||
|
|
||||||
/** Set TX power level in dbm */
|
/** Set TX power level in dbm */
|
||||||
int (*set_txpower)(struct device *dev, int16_t dbm);
|
int (*set_txpower)(struct device *dev, s16_t dbm);
|
||||||
|
|
||||||
/** Transmit a packet fragment */
|
/** Transmit a packet fragment */
|
||||||
int (*tx)(struct device *dev,
|
int (*tx)(struct device *dev,
|
||||||
|
@ -54,7 +54,7 @@ struct ieee802154_radio_api {
|
||||||
int (*stop)(struct device *dev);
|
int (*stop)(struct device *dev);
|
||||||
|
|
||||||
/** Get latest Link Quality Information */
|
/** Get latest Link Quality Information */
|
||||||
uint8_t (*get_lqi)(struct device *dev);
|
u8_t (*get_lqi)(struct device *dev);
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -60,7 +60,7 @@ struct mqtt_ctx {
|
||||||
/** IP stack context structure */
|
/** IP stack context structure */
|
||||||
struct net_context *net_ctx;
|
struct net_context *net_ctx;
|
||||||
/** Network timeout for tx and rx routines */
|
/** Network timeout for tx and rx routines */
|
||||||
int32_t net_timeout;
|
s32_t net_timeout;
|
||||||
|
|
||||||
/** Callback executed when a MQTT CONNACK msg is received and validated.
|
/** Callback executed when a MQTT CONNACK msg is received and validated.
|
||||||
* If this function pointer is not used, must be set to NULL.
|
* If this function pointer is not used, must be set to NULL.
|
||||||
|
@ -88,7 +88,7 @@ struct mqtt_ctx {
|
||||||
* @param [in] pkt_id Packet Identifier for the input MQTT msg
|
* @param [in] pkt_id Packet Identifier for the input MQTT msg
|
||||||
* @param [in] type Packet type
|
* @param [in] type Packet type
|
||||||
*/
|
*/
|
||||||
int (*publish_tx)(struct mqtt_ctx *ctx, uint16_t pkt_id,
|
int (*publish_tx)(struct mqtt_ctx *ctx, u16_t pkt_id,
|
||||||
enum mqtt_packet type);
|
enum mqtt_packet type);
|
||||||
|
|
||||||
/** Callback executed when a MQTT_APP_SUBSCRIBER,
|
/** Callback executed when a MQTT_APP_SUBSCRIBER,
|
||||||
|
@ -108,7 +108,7 @@ struct mqtt_ctx {
|
||||||
* @param [in] type Packet type
|
* @param [in] type Packet type
|
||||||
*/
|
*/
|
||||||
int (*publish_rx)(struct mqtt_ctx *ctx, struct mqtt_publish_msg *msg,
|
int (*publish_rx)(struct mqtt_ctx *ctx, struct mqtt_publish_msg *msg,
|
||||||
uint16_t pkt_id, enum mqtt_packet type);
|
u16_t pkt_id, enum mqtt_packet type);
|
||||||
|
|
||||||
/** Callback executed when a MQTT_APP_SUBSCRIBER or
|
/** Callback executed when a MQTT_APP_SUBSCRIBER or
|
||||||
* MQTT_APP_PUBLISHER_SUBSCRIBER receives the MQTT SUBACK message
|
* MQTT_APP_PUBLISHER_SUBSCRIBER receives the MQTT SUBACK message
|
||||||
|
@ -122,8 +122,8 @@ struct mqtt_ctx {
|
||||||
* @param [in] items Number of elements in the qos array
|
* @param [in] items Number of elements in the qos array
|
||||||
* @param [in] qos Array of QoS values
|
* @param [in] qos Array of QoS values
|
||||||
*/
|
*/
|
||||||
int (*subscribe)(struct mqtt_ctx *ctx, uint16_t pkt_id,
|
int (*subscribe)(struct mqtt_ctx *ctx, u16_t pkt_id,
|
||||||
uint8_t items, enum mqtt_qos qos[]);
|
u8_t items, enum mqtt_qos qos[]);
|
||||||
|
|
||||||
/** Callback executed when a MQTT_APP_SUBSCRIBER or
|
/** Callback executed when a MQTT_APP_SUBSCRIBER or
|
||||||
* MQTT_APP_PUBLISHER_SUBSCRIBER receives the MQTT UNSUBACK message
|
* MQTT_APP_PUBLISHER_SUBSCRIBER receives the MQTT UNSUBACK message
|
||||||
|
@ -135,7 +135,7 @@ struct mqtt_ctx {
|
||||||
* @param [in] ctx MQTT context
|
* @param [in] ctx MQTT context
|
||||||
* @param [in] pkt_id Packet Identifier for the MQTT SUBACK msg
|
* @param [in] pkt_id Packet Identifier for the MQTT SUBACK msg
|
||||||
*/
|
*/
|
||||||
int (*unsubscribe)(struct mqtt_ctx *ctx, uint16_t pkt_id);
|
int (*unsubscribe)(struct mqtt_ctx *ctx, u16_t pkt_id);
|
||||||
|
|
||||||
/** Callback executed when an incoming message doesn't pass the
|
/** Callback executed when an incoming message doesn't pass the
|
||||||
* validation stage. This callback may be NULL.
|
* validation stage. This callback may be NULL.
|
||||||
|
@ -145,22 +145,22 @@ struct mqtt_ctx {
|
||||||
* @param [in] ctx MQTT context
|
* @param [in] ctx MQTT context
|
||||||
* @param [in] pkt_type MQTT Packet type
|
* @param [in] pkt_type MQTT Packet type
|
||||||
*/
|
*/
|
||||||
void (*malformed)(struct mqtt_ctx *ctx, uint16_t pkt_type);
|
void (*malformed)(struct mqtt_ctx *ctx, u16_t pkt_type);
|
||||||
|
|
||||||
/* Internal use only */
|
/* Internal use only */
|
||||||
int (*rcv)(struct mqtt_ctx *ctx, struct net_pkt *);
|
int (*rcv)(struct mqtt_ctx *ctx, struct net_pkt *);
|
||||||
|
|
||||||
/** Application type, see: enum mqtt_app */
|
/** Application type, see: enum mqtt_app */
|
||||||
uint8_t app_type;
|
u8_t app_type;
|
||||||
|
|
||||||
/* Clean session is also part of the MQTT CONNECT msg, however app
|
/* Clean session is also part of the MQTT CONNECT msg, however app
|
||||||
* behavior is influenced by this parameter, so we keep a copy here
|
* behavior is influenced by this parameter, so we keep a copy here
|
||||||
*/
|
*/
|
||||||
/** MQTT Clean Session parameter */
|
/** MQTT Clean Session parameter */
|
||||||
uint8_t clean_session:1;
|
u8_t clean_session:1;
|
||||||
|
|
||||||
/** 1 if the MQTT application is connected and 0 otherwise */
|
/** 1 if the MQTT application is connected and 0 otherwise */
|
||||||
uint8_t connected:1;
|
u8_t connected:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -208,7 +208,7 @@ int mqtt_tx_disconnect(struct mqtt_ctx *ctx);
|
||||||
* @retval -ENOMEM
|
* @retval -ENOMEM
|
||||||
* @retval -EIO
|
* @retval -EIO
|
||||||
*/
|
*/
|
||||||
int mqtt_tx_puback(struct mqtt_ctx *ctx, uint16_t id);
|
int mqtt_tx_puback(struct mqtt_ctx *ctx, u16_t id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the MQTT PUBCOMP message with the given packet id
|
* Sends the MQTT PUBCOMP message with the given packet id
|
||||||
|
@ -221,7 +221,7 @@ int mqtt_tx_puback(struct mqtt_ctx *ctx, uint16_t id);
|
||||||
* @retval -ENOMEM
|
* @retval -ENOMEM
|
||||||
* @retval -EIO
|
* @retval -EIO
|
||||||
*/
|
*/
|
||||||
int mqtt_tx_pubcomp(struct mqtt_ctx *ctx, uint16_t id);
|
int mqtt_tx_pubcomp(struct mqtt_ctx *ctx, u16_t id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the MQTT PUBREC message with the given packet id
|
* Sends the MQTT PUBREC message with the given packet id
|
||||||
|
@ -233,7 +233,7 @@ int mqtt_tx_pubcomp(struct mqtt_ctx *ctx, uint16_t id);
|
||||||
* @retval -ENOMEM
|
* @retval -ENOMEM
|
||||||
* @retval -EIO
|
* @retval -EIO
|
||||||
*/
|
*/
|
||||||
int mqtt_tx_pubrec(struct mqtt_ctx *ctx, uint16_t id);
|
int mqtt_tx_pubrec(struct mqtt_ctx *ctx, u16_t id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the MQTT PUBREL message with the given packet id
|
* Sends the MQTT PUBREL message with the given packet id
|
||||||
|
@ -246,7 +246,7 @@ int mqtt_tx_pubrec(struct mqtt_ctx *ctx, uint16_t id);
|
||||||
* @retval -ENOMEM
|
* @retval -ENOMEM
|
||||||
* @retval -EIO
|
* @retval -EIO
|
||||||
*/
|
*/
|
||||||
int mqtt_tx_pubrel(struct mqtt_ctx *ctx, uint16_t id);
|
int mqtt_tx_pubrel(struct mqtt_ctx *ctx, u16_t id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the MQTT PUBLISH message
|
* Sends the MQTT PUBLISH message
|
||||||
|
@ -292,7 +292,7 @@ int mqtt_tx_pingreq(struct mqtt_ctx *ctx);
|
||||||
* @retval -ENOMEM
|
* @retval -ENOMEM
|
||||||
* @retval -EIO
|
* @retval -EIO
|
||||||
*/
|
*/
|
||||||
int mqtt_tx_subscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items,
|
int mqtt_tx_subscribe(struct mqtt_ctx *ctx, u16_t pkt_id, u8_t items,
|
||||||
const char *topics[], const enum mqtt_qos qos[]);
|
const char *topics[], const enum mqtt_qos qos[]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -308,7 +308,7 @@ int mqtt_tx_subscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items,
|
||||||
* @retval -ENOMEM
|
* @retval -ENOMEM
|
||||||
* @retval -EIO
|
* @retval -EIO
|
||||||
*/
|
*/
|
||||||
int mqtt_tx_unsubscribe(struct mqtt_ctx *ctx, uint16_t pkt_id, uint8_t items,
|
int mqtt_tx_unsubscribe(struct mqtt_ctx *ctx, u16_t pkt_id, u8_t items,
|
||||||
const char *topics[]);
|
const char *topics[]);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -54,32 +54,32 @@ enum mqtt_qos {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mqtt_connect_msg {
|
struct mqtt_connect_msg {
|
||||||
uint8_t clean_session:1;
|
u8_t clean_session:1;
|
||||||
char *client_id;
|
char *client_id;
|
||||||
uint16_t client_id_len;
|
u16_t client_id_len;
|
||||||
uint8_t will_flag:1;
|
u8_t will_flag:1;
|
||||||
enum mqtt_qos will_qos;
|
enum mqtt_qos will_qos;
|
||||||
uint8_t will_retain:1;
|
u8_t will_retain:1;
|
||||||
char *will_topic;
|
char *will_topic;
|
||||||
uint16_t will_topic_len;
|
u16_t will_topic_len;
|
||||||
uint8_t *will_msg;
|
u8_t *will_msg;
|
||||||
uint16_t will_msg_len;
|
u16_t will_msg_len;
|
||||||
uint16_t keep_alive;
|
u16_t keep_alive;
|
||||||
const char *user_name;
|
const char *user_name;
|
||||||
uint16_t user_name_len;
|
u16_t user_name_len;
|
||||||
uint8_t *password;
|
u8_t *password;
|
||||||
uint16_t password_len;
|
u16_t password_len;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mqtt_publish_msg {
|
struct mqtt_publish_msg {
|
||||||
uint8_t dup;
|
u8_t dup;
|
||||||
enum mqtt_qos qos;
|
enum mqtt_qos qos;
|
||||||
uint8_t retain;
|
u8_t retain;
|
||||||
uint16_t pkt_id;
|
u16_t pkt_id;
|
||||||
char *topic;
|
char *topic;
|
||||||
uint16_t topic_len;
|
u16_t topic_len;
|
||||||
uint8_t *msg;
|
u8_t *msg;
|
||||||
uint16_t msg_len;
|
u16_t msg_len;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -228,10 +228,10 @@ struct net_context {
|
||||||
#endif /* CONFIG_NET_CONTEXT_SYNC_RECV */
|
#endif /* CONFIG_NET_CONTEXT_SYNC_RECV */
|
||||||
|
|
||||||
/** Network interface assigned to this context */
|
/** Network interface assigned to this context */
|
||||||
uint8_t iface;
|
u8_t iface;
|
||||||
|
|
||||||
/** Flags for the context */
|
/** Flags for the context */
|
||||||
uint8_t flags;
|
u8_t flags;
|
||||||
|
|
||||||
#if defined(CONFIG_NET_TCP)
|
#if defined(CONFIG_NET_TCP)
|
||||||
/** TCP connection information */
|
/** TCP connection information */
|
||||||
|
@ -575,7 +575,7 @@ int net_context_connect(struct net_context *context,
|
||||||
const struct sockaddr *addr,
|
const struct sockaddr *addr,
|
||||||
socklen_t addrlen,
|
socklen_t addrlen,
|
||||||
net_context_connect_cb_t cb,
|
net_context_connect_cb_t cb,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -605,7 +605,7 @@ int net_context_connect(struct net_context *context,
|
||||||
*/
|
*/
|
||||||
int net_context_accept(struct net_context *context,
|
int net_context_accept(struct net_context *context,
|
||||||
net_tcp_accept_cb_t cb,
|
net_tcp_accept_cb_t cb,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -635,7 +635,7 @@ int net_context_accept(struct net_context *context,
|
||||||
*/
|
*/
|
||||||
int net_context_send(struct net_pkt *pkt,
|
int net_context_send(struct net_pkt *pkt,
|
||||||
net_context_send_cb_t cb,
|
net_context_send_cb_t cb,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
void *token,
|
void *token,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
|
@ -670,7 +670,7 @@ int net_context_sendto(struct net_pkt *pkt,
|
||||||
const struct sockaddr *dst_addr,
|
const struct sockaddr *dst_addr,
|
||||||
socklen_t addrlen,
|
socklen_t addrlen,
|
||||||
net_context_send_cb_t cb,
|
net_context_send_cb_t cb,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
void *token,
|
void *token,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
|
@ -712,7 +712,7 @@ int net_context_sendto(struct net_pkt *pkt,
|
||||||
*/
|
*/
|
||||||
int net_context_recv(struct net_context *context,
|
int net_context_recv(struct net_context *context,
|
||||||
net_context_recv_cb_t cb,
|
net_context_recv_cb_t cb,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -58,7 +58,7 @@ struct net_if_addr {
|
||||||
|
|
||||||
#if defined(CONFIG_NET_IPV6_DAD)
|
#if defined(CONFIG_NET_IPV6_DAD)
|
||||||
/** How many times we have done DAD */
|
/** How many times we have done DAD */
|
||||||
uint8_t dad_count;
|
u8_t dad_count;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Is the IP address valid forever */
|
/** Is the IP address valid forever */
|
||||||
|
@ -75,12 +75,12 @@ struct net_if_addr {
|
||||||
*/
|
*/
|
||||||
struct net_if_mcast_addr {
|
struct net_if_mcast_addr {
|
||||||
/** Is this multicast IP address used or not */
|
/** Is this multicast IP address used or not */
|
||||||
uint8_t is_used : 1;
|
u8_t is_used : 1;
|
||||||
|
|
||||||
/** Did we join to this group */
|
/** Did we join to this group */
|
||||||
uint8_t is_joined : 1;
|
u8_t is_joined : 1;
|
||||||
|
|
||||||
uint8_t _unused : 6;
|
u8_t _unused : 6;
|
||||||
|
|
||||||
/** IP address */
|
/** IP address */
|
||||||
struct net_addr address;
|
struct net_addr address;
|
||||||
|
@ -100,7 +100,7 @@ struct net_if_ipv6_prefix {
|
||||||
struct in6_addr prefix;
|
struct in6_addr prefix;
|
||||||
|
|
||||||
/** Prefix length */
|
/** Prefix length */
|
||||||
uint8_t len;
|
u8_t len;
|
||||||
|
|
||||||
/** Is the IP prefix valid forever */
|
/** Is the IP prefix valid forever */
|
||||||
bool is_infinite;
|
bool is_infinite;
|
||||||
|
@ -200,7 +200,7 @@ struct net_if {
|
||||||
struct k_fifo tx_queue;
|
struct k_fifo tx_queue;
|
||||||
|
|
||||||
/** The hardware MTU */
|
/** The hardware MTU */
|
||||||
uint16_t mtu;
|
u16_t mtu;
|
||||||
|
|
||||||
#if defined(CONFIG_NET_OFFLOAD)
|
#if defined(CONFIG_NET_OFFLOAD)
|
||||||
/** TCP/IP Offload functions.
|
/** TCP/IP Offload functions.
|
||||||
|
@ -229,24 +229,24 @@ struct net_if {
|
||||||
struct k_delayed_work rs_timer;
|
struct k_delayed_work rs_timer;
|
||||||
|
|
||||||
/** Default reachable time (RFC 4861, page 52) */
|
/** Default reachable time (RFC 4861, page 52) */
|
||||||
uint32_t base_reachable_time;
|
u32_t base_reachable_time;
|
||||||
|
|
||||||
/** Reachable time (RFC 4861, page 20) */
|
/** Reachable time (RFC 4861, page 20) */
|
||||||
uint32_t reachable_time;
|
u32_t reachable_time;
|
||||||
|
|
||||||
/** Retransmit timer (RFC 4861, page 52) */
|
/** Retransmit timer (RFC 4861, page 52) */
|
||||||
uint32_t retrans_timer;
|
u32_t retrans_timer;
|
||||||
|
|
||||||
/** IPv6 hop limit */
|
/** IPv6 hop limit */
|
||||||
uint8_t hop_limit;
|
u8_t hop_limit;
|
||||||
|
|
||||||
#if defined(CONFIG_NET_IPV6_DAD)
|
#if defined(CONFIG_NET_IPV6_DAD)
|
||||||
/** IPv6 current duplicate address detection count */
|
/** IPv6 current duplicate address detection count */
|
||||||
uint8_t dad_count;
|
u8_t dad_count;
|
||||||
#endif /* CONFIG_NET_IPV6_DAD */
|
#endif /* CONFIG_NET_IPV6_DAD */
|
||||||
|
|
||||||
/** RS count */
|
/** RS count */
|
||||||
uint8_t rs_count;
|
u8_t rs_count;
|
||||||
} ipv6;
|
} ipv6;
|
||||||
#endif /* CONFIG_NET_IPV6 */
|
#endif /* CONFIG_NET_IPV6 */
|
||||||
|
|
||||||
|
@ -267,22 +267,22 @@ struct net_if {
|
||||||
struct in_addr netmask;
|
struct in_addr netmask;
|
||||||
|
|
||||||
/** IPv4 time-to-live */
|
/** IPv4 time-to-live */
|
||||||
uint8_t ttl;
|
u8_t ttl;
|
||||||
} ipv4;
|
} ipv4;
|
||||||
#endif /* CONFIG_NET_IPV4 */
|
#endif /* CONFIG_NET_IPV4 */
|
||||||
|
|
||||||
#if defined(CONFIG_NET_DHCPV4)
|
#if defined(CONFIG_NET_DHCPV4)
|
||||||
struct {
|
struct {
|
||||||
uint32_t xid;
|
u32_t xid;
|
||||||
|
|
||||||
/** IP address Lease time */
|
/** IP address Lease time */
|
||||||
uint32_t lease_time;
|
u32_t lease_time;
|
||||||
|
|
||||||
/** IP address Renewal time */
|
/** IP address Renewal time */
|
||||||
uint32_t renewal_time;
|
u32_t renewal_time;
|
||||||
|
|
||||||
/** IP address Rebinding time */
|
/** IP address Rebinding time */
|
||||||
uint32_t rebinding_time;
|
u32_t rebinding_time;
|
||||||
|
|
||||||
/** Server ID */
|
/** Server ID */
|
||||||
struct in_addr server_id;
|
struct in_addr server_id;
|
||||||
|
@ -308,7 +308,7 @@ struct net_if {
|
||||||
enum net_dhcpv4_state state;
|
enum net_dhcpv4_state state;
|
||||||
|
|
||||||
/** Number of attempts made for REQUEST and RENEWAL messages */
|
/** Number of attempts made for REQUEST and RENEWAL messages */
|
||||||
uint8_t attempts;
|
u8_t attempts;
|
||||||
} dhcpv4;
|
} dhcpv4;
|
||||||
#endif
|
#endif
|
||||||
} __net_if_align;
|
} __net_if_align;
|
||||||
|
@ -345,7 +345,7 @@ static inline enum net_verdict net_if_recv_data(struct net_if *iface,
|
||||||
*
|
*
|
||||||
* @return Return the link layer header size
|
* @return Return the link layer header size
|
||||||
*/
|
*/
|
||||||
static inline uint16_t net_if_get_ll_reserve(struct net_if *iface,
|
static inline u16_t net_if_get_ll_reserve(struct net_if *iface,
|
||||||
const struct in6_addr *dst_ip6)
|
const struct in6_addr *dst_ip6)
|
||||||
{
|
{
|
||||||
return iface->l2->reserve(iface, (void *)dst_ip6);
|
return iface->l2->reserve(iface, (void *)dst_ip6);
|
||||||
|
@ -434,14 +434,14 @@ void net_if_start_rs(struct net_if *iface);
|
||||||
* @brief Set a network interface's link address
|
* @brief Set a network interface's link address
|
||||||
*
|
*
|
||||||
* @param iface Pointer to a network interface structure
|
* @param iface Pointer to a network interface structure
|
||||||
* @param addr a pointer on a uint8_t buffer representing the address
|
* @param addr a pointer on a u8_t buffer representing the address
|
||||||
* @param len length of the address buffer
|
* @param len length of the address buffer
|
||||||
* @param type network bearer type of this link address
|
* @param type network bearer type of this link address
|
||||||
*
|
*
|
||||||
* @return 0 on success
|
* @return 0 on success
|
||||||
*/
|
*/
|
||||||
static inline int net_if_set_link_addr(struct net_if *iface,
|
static inline int net_if_set_link_addr(struct net_if *iface,
|
||||||
uint8_t *addr, uint8_t len,
|
u8_t *addr, u8_t len,
|
||||||
enum net_link_type type)
|
enum net_link_type type)
|
||||||
{
|
{
|
||||||
if (atomic_test_bit(iface->flags, NET_IF_UP)) {
|
if (atomic_test_bit(iface->flags, NET_IF_UP)) {
|
||||||
|
@ -462,7 +462,7 @@ static inline int net_if_set_link_addr(struct net_if *iface,
|
||||||
*
|
*
|
||||||
* @return the MTU
|
* @return the MTU
|
||||||
*/
|
*/
|
||||||
static inline uint16_t net_if_get_mtu(struct net_if *iface)
|
static inline u16_t net_if_get_mtu(struct net_if *iface)
|
||||||
{
|
{
|
||||||
return iface->mtu;
|
return iface->mtu;
|
||||||
}
|
}
|
||||||
|
@ -474,7 +474,7 @@ static inline uint16_t net_if_get_mtu(struct net_if *iface)
|
||||||
* @param mtu New MTU, note that we store only 16 bit mtu value.
|
* @param mtu New MTU, note that we store only 16 bit mtu value.
|
||||||
*/
|
*/
|
||||||
static inline void net_if_set_mtu(struct net_if *iface,
|
static inline void net_if_set_mtu(struct net_if *iface,
|
||||||
uint16_t mtu)
|
u16_t mtu)
|
||||||
{
|
{
|
||||||
iface->mtu = mtu;
|
iface->mtu = mtu;
|
||||||
}
|
}
|
||||||
|
@ -583,7 +583,7 @@ struct net_if_addr *net_if_ipv6_addr_lookup_by_iface(struct net_if *iface,
|
||||||
struct net_if_addr *net_if_ipv6_addr_add(struct net_if *iface,
|
struct net_if_addr *net_if_ipv6_addr_add(struct net_if *iface,
|
||||||
struct in6_addr *addr,
|
struct in6_addr *addr,
|
||||||
enum net_addr_type addr_type,
|
enum net_addr_type addr_type,
|
||||||
uint32_t vlifetime);
|
u32_t vlifetime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Update validity lifetime time of an IPv6 address.
|
* @brief Update validity lifetime time of an IPv6 address.
|
||||||
|
@ -592,7 +592,7 @@ struct net_if_addr *net_if_ipv6_addr_add(struct net_if *iface,
|
||||||
* @param vlifetime Validity time for this address
|
* @param vlifetime Validity time for this address
|
||||||
*/
|
*/
|
||||||
void net_if_ipv6_addr_update_lifetime(struct net_if_addr *ifaddr,
|
void net_if_ipv6_addr_update_lifetime(struct net_if_addr *ifaddr,
|
||||||
uint32_t vlifetime);
|
u32_t vlifetime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remove an IPv6 address from an interface
|
* @brief Remove an IPv6 address from an interface
|
||||||
|
@ -688,7 +688,7 @@ static inline void net_if_ipv6_maddr_leave(struct net_if_mcast_addr *addr)
|
||||||
*/
|
*/
|
||||||
struct net_if_ipv6_prefix *net_if_ipv6_prefix_lookup(struct net_if *iface,
|
struct net_if_ipv6_prefix *net_if_ipv6_prefix_lookup(struct net_if *iface,
|
||||||
struct in6_addr *addr,
|
struct in6_addr *addr,
|
||||||
uint8_t len);
|
u8_t len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add a IPv6 prefix to an network interface.
|
* @brief Add a IPv6 prefix to an network interface.
|
||||||
|
@ -702,8 +702,8 @@ struct net_if_ipv6_prefix *net_if_ipv6_prefix_lookup(struct net_if *iface,
|
||||||
*/
|
*/
|
||||||
struct net_if_ipv6_prefix *net_if_ipv6_prefix_add(struct net_if *iface,
|
struct net_if_ipv6_prefix *net_if_ipv6_prefix_add(struct net_if *iface,
|
||||||
struct in6_addr *prefix,
|
struct in6_addr *prefix,
|
||||||
uint8_t len,
|
u8_t len,
|
||||||
uint32_t lifetime);
|
u32_t lifetime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remove an IPv6 prefix from an interface
|
* @brief Remove an IPv6 prefix from an interface
|
||||||
|
@ -715,7 +715,7 @@ struct net_if_ipv6_prefix *net_if_ipv6_prefix_add(struct net_if *iface,
|
||||||
* @return True if successfully removed, false otherwise
|
* @return True if successfully removed, false otherwise
|
||||||
*/
|
*/
|
||||||
bool net_if_ipv6_prefix_rm(struct net_if *iface, struct in6_addr *addr,
|
bool net_if_ipv6_prefix_rm(struct net_if *iface, struct in6_addr *addr,
|
||||||
uint8_t len);
|
u8_t len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set the infinite status of the prefix
|
* @brief Set the infinite status of the prefix
|
||||||
|
@ -736,7 +736,7 @@ static inline void net_if_ipv6_prefix_set_lf(struct net_if_ipv6_prefix *prefix,
|
||||||
* @param lifetime Prefix lifetime in seconds
|
* @param lifetime Prefix lifetime in seconds
|
||||||
*/
|
*/
|
||||||
void net_if_ipv6_prefix_set_timer(struct net_if_ipv6_prefix *prefix,
|
void net_if_ipv6_prefix_set_timer(struct net_if_ipv6_prefix *prefix,
|
||||||
uint32_t lifetime);
|
u32_t lifetime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Unset the prefix lifetime timer.
|
* @brief Unset the prefix lifetime timer.
|
||||||
|
@ -788,7 +788,7 @@ struct net_if_router *net_if_ipv6_router_find_default(struct net_if *iface,
|
||||||
* @param lifetime Lifetime of this router.
|
* @param lifetime Lifetime of this router.
|
||||||
*/
|
*/
|
||||||
void net_if_ipv6_router_update_lifetime(struct net_if_router *router,
|
void net_if_ipv6_router_update_lifetime(struct net_if_router *router,
|
||||||
uint32_t lifetime);
|
u32_t lifetime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Add IPv6 router to the system.
|
* @brief Add IPv6 router to the system.
|
||||||
|
@ -801,7 +801,7 @@ void net_if_ipv6_router_update_lifetime(struct net_if_router *router,
|
||||||
*/
|
*/
|
||||||
struct net_if_router *net_if_ipv6_router_add(struct net_if *iface,
|
struct net_if_router *net_if_ipv6_router_add(struct net_if *iface,
|
||||||
struct in6_addr *addr,
|
struct in6_addr *addr,
|
||||||
uint16_t router_lifetime);
|
u16_t router_lifetime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remove IPv6 router from the system.
|
* @brief Remove IPv6 router from the system.
|
||||||
|
@ -820,7 +820,7 @@ bool net_if_ipv6_router_rm(struct net_if_router *router);
|
||||||
*
|
*
|
||||||
* @return Hop limit
|
* @return Hop limit
|
||||||
*/
|
*/
|
||||||
static inline uint8_t net_if_ipv6_get_hop_limit(struct net_if *iface)
|
static inline u8_t net_if_ipv6_get_hop_limit(struct net_if *iface)
|
||||||
{
|
{
|
||||||
return iface->ipv6.hop_limit;
|
return iface->ipv6.hop_limit;
|
||||||
}
|
}
|
||||||
|
@ -832,7 +832,7 @@ static inline uint8_t net_if_ipv6_get_hop_limit(struct net_if *iface)
|
||||||
* @param hop_limit New hop limit
|
* @param hop_limit New hop limit
|
||||||
*/
|
*/
|
||||||
static inline void net_ipv6_set_hop_limit(struct net_if *iface,
|
static inline void net_ipv6_set_hop_limit(struct net_if *iface,
|
||||||
uint8_t hop_limit)
|
u8_t hop_limit)
|
||||||
{
|
{
|
||||||
iface->ipv6.hop_limit = hop_limit;
|
iface->ipv6.hop_limit = hop_limit;
|
||||||
}
|
}
|
||||||
|
@ -844,7 +844,7 @@ static inline void net_ipv6_set_hop_limit(struct net_if *iface,
|
||||||
* @param reachable_time New reachable time
|
* @param reachable_time New reachable time
|
||||||
*/
|
*/
|
||||||
static inline void net_if_ipv6_set_base_reachable_time(struct net_if *iface,
|
static inline void net_if_ipv6_set_base_reachable_time(struct net_if *iface,
|
||||||
uint32_t reachable_time)
|
u32_t reachable_time)
|
||||||
{
|
{
|
||||||
iface->ipv6.base_reachable_time = reachable_time;
|
iface->ipv6.base_reachable_time = reachable_time;
|
||||||
}
|
}
|
||||||
|
@ -856,7 +856,7 @@ static inline void net_if_ipv6_set_base_reachable_time(struct net_if *iface,
|
||||||
*
|
*
|
||||||
* @return Reachable timeout
|
* @return Reachable timeout
|
||||||
*/
|
*/
|
||||||
static inline uint32_t net_if_ipv6_get_reachable_time(struct net_if *iface)
|
static inline u32_t net_if_ipv6_get_reachable_time(struct net_if *iface)
|
||||||
{
|
{
|
||||||
return iface->ipv6.reachable_time;
|
return iface->ipv6.reachable_time;
|
||||||
}
|
}
|
||||||
|
@ -868,7 +868,7 @@ static inline uint32_t net_if_ipv6_get_reachable_time(struct net_if *iface)
|
||||||
*
|
*
|
||||||
* @return Reachable time
|
* @return Reachable time
|
||||||
*/
|
*/
|
||||||
uint32_t net_if_ipv6_calc_reachable_time(struct net_if *iface);
|
u32_t net_if_ipv6_calc_reachable_time(struct net_if *iface);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set IPv6 reachable time for a given interface. This requires
|
* @brief Set IPv6 reachable time for a given interface. This requires
|
||||||
|
@ -888,7 +888,7 @@ static inline void net_if_ipv6_set_reachable_time(struct net_if *iface)
|
||||||
* @param retrans_timer New retransmit timer
|
* @param retrans_timer New retransmit timer
|
||||||
*/
|
*/
|
||||||
static inline void net_if_ipv6_set_retrans_timer(struct net_if *iface,
|
static inline void net_if_ipv6_set_retrans_timer(struct net_if *iface,
|
||||||
uint32_t retrans_timer)
|
u32_t retrans_timer)
|
||||||
{
|
{
|
||||||
iface->ipv6.retrans_timer = retrans_timer;
|
iface->ipv6.retrans_timer = retrans_timer;
|
||||||
}
|
}
|
||||||
|
@ -900,7 +900,7 @@ static inline void net_if_ipv6_set_retrans_timer(struct net_if *iface,
|
||||||
*
|
*
|
||||||
* @return Retransmit timer
|
* @return Retransmit timer
|
||||||
*/
|
*/
|
||||||
static inline uint32_t net_if_ipv6_get_retrans_timer(struct net_if *iface)
|
static inline u32_t net_if_ipv6_get_retrans_timer(struct net_if *iface)
|
||||||
{
|
{
|
||||||
return iface->ipv6.retrans_timer;
|
return iface->ipv6.retrans_timer;
|
||||||
}
|
}
|
||||||
|
@ -975,7 +975,7 @@ struct in6_addr *net_if_ipv6_get_global_addr(struct net_if **iface);
|
||||||
*
|
*
|
||||||
* @return Time-to-live
|
* @return Time-to-live
|
||||||
*/
|
*/
|
||||||
static inline uint8_t net_if_ipv4_get_ttl(struct net_if *iface)
|
static inline u8_t net_if_ipv4_get_ttl(struct net_if *iface)
|
||||||
{
|
{
|
||||||
return iface->ipv4.ttl;
|
return iface->ipv4.ttl;
|
||||||
}
|
}
|
||||||
|
@ -1004,7 +1004,7 @@ struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr,
|
||||||
struct net_if_addr *net_if_ipv4_addr_add(struct net_if *iface,
|
struct net_if_addr *net_if_ipv4_addr_add(struct net_if *iface,
|
||||||
struct in_addr *addr,
|
struct in_addr *addr,
|
||||||
enum net_addr_type addr_type,
|
enum net_addr_type addr_type,
|
||||||
uint32_t vlifetime);
|
u32_t vlifetime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Remove a IPv4 address from an interface
|
* @brief Remove a IPv4 address from an interface
|
||||||
|
@ -1042,7 +1042,7 @@ struct net_if_router *net_if_ipv4_router_lookup(struct net_if *iface,
|
||||||
struct net_if_router *net_if_ipv4_router_add(struct net_if *iface,
|
struct net_if_router *net_if_ipv4_router_add(struct net_if *iface,
|
||||||
struct in_addr *addr,
|
struct in_addr *addr,
|
||||||
bool is_default,
|
bool is_default,
|
||||||
uint16_t router_lifetime);
|
u16_t router_lifetime);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Check if the given IPv4 address belongs to local subnet.
|
* @brief Check if the given IPv4 address belongs to local subnet.
|
||||||
|
@ -1144,7 +1144,7 @@ void net_if_call_link_cb(struct net_if *iface, struct net_linkaddr *lladdr,
|
||||||
*
|
*
|
||||||
* @return Pointer to interface or NULL if not found.
|
* @return Pointer to interface or NULL if not found.
|
||||||
*/
|
*/
|
||||||
struct net_if *net_if_get_by_index(uint8_t index);
|
struct net_if *net_if_get_by_index(u8_t index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get interface index according to pointer
|
* @brief Get interface index according to pointer
|
||||||
|
@ -1153,7 +1153,7 @@ struct net_if *net_if_get_by_index(uint8_t index);
|
||||||
*
|
*
|
||||||
* @return Interface index
|
* @return Interface index
|
||||||
*/
|
*/
|
||||||
uint8_t net_if_get_by_iface(struct net_if *iface);
|
u8_t net_if_get_by_iface(struct net_if *iface);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef net_if_cb_t
|
* @typedef net_if_cb_t
|
||||||
|
|
|
@ -63,9 +63,9 @@ enum net_sock_type {
|
||||||
/** IPv6 address structure */
|
/** IPv6 address structure */
|
||||||
struct in6_addr {
|
struct in6_addr {
|
||||||
union {
|
union {
|
||||||
uint8_t u6_addr8[16];
|
u8_t u6_addr8[16];
|
||||||
uint16_t u6_addr16[8]; /* In big endian */
|
u16_t u6_addr16[8]; /* In big endian */
|
||||||
uint32_t u6_addr32[4]; /* In big endian */
|
u32_t u6_addr32[4]; /* In big endian */
|
||||||
} in6_u;
|
} in6_u;
|
||||||
#define s6_addr in6_u.u6_addr8
|
#define s6_addr in6_u.u6_addr8
|
||||||
#define s6_addr16 in6_u.u6_addr16
|
#define s6_addr16 in6_u.u6_addr16
|
||||||
|
@ -75,9 +75,9 @@ struct in6_addr {
|
||||||
/** IPv4 address */
|
/** IPv4 address */
|
||||||
struct in_addr {
|
struct in_addr {
|
||||||
union {
|
union {
|
||||||
uint8_t u4_addr8[4];
|
u8_t u4_addr8[4];
|
||||||
uint16_t u4_addr16[2]; /* In big endian */
|
u16_t u4_addr16[2]; /* In big endian */
|
||||||
uint32_t u4_addr32[1]; /* In big endian */
|
u32_t u4_addr32[1]; /* In big endian */
|
||||||
} in4_u;
|
} in4_u;
|
||||||
#define s4_addr in4_u.u4_addr8
|
#define s4_addr in4_u.u4_addr8
|
||||||
#define s4_addr16 in4_u.u4_addr16
|
#define s4_addr16 in4_u.u4_addr16
|
||||||
|
@ -95,27 +95,27 @@ typedef size_t socklen_t;
|
||||||
*/
|
*/
|
||||||
struct sockaddr_in6 {
|
struct sockaddr_in6 {
|
||||||
sa_family_t sin6_family; /* AF_INET6 */
|
sa_family_t sin6_family; /* AF_INET6 */
|
||||||
uint16_t sin6_port; /* Port number */
|
u16_t sin6_port; /* Port number */
|
||||||
struct in6_addr sin6_addr; /* IPv6 address */
|
struct in6_addr sin6_addr; /* IPv6 address */
|
||||||
uint8_t sin6_scope_id; /* interfaces for a scope */
|
u8_t sin6_scope_id; /* interfaces for a scope */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sockaddr_in6_ptr {
|
struct sockaddr_in6_ptr {
|
||||||
sa_family_t sin6_family; /* AF_INET6 */
|
sa_family_t sin6_family; /* AF_INET6 */
|
||||||
uint16_t sin6_port; /* Port number */
|
u16_t sin6_port; /* Port number */
|
||||||
struct in6_addr *sin6_addr; /* IPv6 address */
|
struct in6_addr *sin6_addr; /* IPv6 address */
|
||||||
uint8_t sin6_scope_id; /* interfaces for a scope */
|
u8_t sin6_scope_id; /* interfaces for a scope */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sockaddr_in {
|
struct sockaddr_in {
|
||||||
sa_family_t sin_family; /* AF_INET */
|
sa_family_t sin_family; /* AF_INET */
|
||||||
uint16_t sin_port; /* Port number */
|
u16_t sin_port; /* Port number */
|
||||||
struct in_addr sin_addr; /* IPv4 address */
|
struct in_addr sin_addr; /* IPv4 address */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct sockaddr_in_ptr {
|
struct sockaddr_in_ptr {
|
||||||
sa_family_t sin_family; /* AF_INET */
|
sa_family_t sin_family; /* AF_INET */
|
||||||
uint16_t sin_port; /* Port number */
|
u16_t sin_port; /* Port number */
|
||||||
struct in_addr *sin_addr; /* IPv4 address */
|
struct in_addr *sin_addr; /* IPv4 address */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -184,9 +184,9 @@ struct net_tuple {
|
||||||
/** IPv6/IPv4 local address */
|
/** IPv6/IPv4 local address */
|
||||||
struct net_addr *local_addr;
|
struct net_addr *local_addr;
|
||||||
/** UDP/TCP remote port */
|
/** UDP/TCP remote port */
|
||||||
uint16_t remote_port;
|
u16_t remote_port;
|
||||||
/** UDP/TCP local port */
|
/** UDP/TCP local port */
|
||||||
uint16_t local_port;
|
u16_t local_port;
|
||||||
/** IP protocol */
|
/** IP protocol */
|
||||||
enum net_ip_protocol ip_proto;
|
enum net_ip_protocol ip_proto;
|
||||||
};
|
};
|
||||||
|
@ -234,60 +234,60 @@ enum net_addr_state {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct net_ipv6_hdr {
|
struct net_ipv6_hdr {
|
||||||
uint8_t vtc;
|
u8_t vtc;
|
||||||
uint8_t tcflow;
|
u8_t tcflow;
|
||||||
uint16_t flow;
|
u16_t flow;
|
||||||
uint8_t len[2];
|
u8_t len[2];
|
||||||
uint8_t nexthdr;
|
u8_t nexthdr;
|
||||||
uint8_t hop_limit;
|
u8_t hop_limit;
|
||||||
struct in6_addr src;
|
struct in6_addr src;
|
||||||
struct in6_addr dst;
|
struct in6_addr dst;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct net_ipv6_frag_hdr {
|
struct net_ipv6_frag_hdr {
|
||||||
uint8_t nexthdr;
|
u8_t nexthdr;
|
||||||
uint8_t reserved;
|
u8_t reserved;
|
||||||
uint16_t offset;
|
u16_t offset;
|
||||||
uint32_t id;
|
u32_t id;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct net_ipv4_hdr {
|
struct net_ipv4_hdr {
|
||||||
uint8_t vhl;
|
u8_t vhl;
|
||||||
uint8_t tos;
|
u8_t tos;
|
||||||
uint8_t len[2];
|
u8_t len[2];
|
||||||
uint8_t id[2];
|
u8_t id[2];
|
||||||
uint8_t offset[2];
|
u8_t offset[2];
|
||||||
uint8_t ttl;
|
u8_t ttl;
|
||||||
uint8_t proto;
|
u8_t proto;
|
||||||
uint16_t chksum;
|
u16_t chksum;
|
||||||
struct in_addr src;
|
struct in_addr src;
|
||||||
struct in_addr dst;
|
struct in_addr dst;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct net_icmp_hdr {
|
struct net_icmp_hdr {
|
||||||
uint8_t type;
|
u8_t type;
|
||||||
uint8_t code;
|
u8_t code;
|
||||||
uint16_t chksum;
|
u16_t chksum;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct net_udp_hdr {
|
struct net_udp_hdr {
|
||||||
uint16_t src_port;
|
u16_t src_port;
|
||||||
uint16_t dst_port;
|
u16_t dst_port;
|
||||||
uint16_t len;
|
u16_t len;
|
||||||
uint16_t chksum;
|
u16_t chksum;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct net_tcp_hdr {
|
struct net_tcp_hdr {
|
||||||
uint16_t src_port;
|
u16_t src_port;
|
||||||
uint16_t dst_port;
|
u16_t dst_port;
|
||||||
uint8_t seq[4];
|
u8_t seq[4];
|
||||||
uint8_t ack[4];
|
u8_t ack[4];
|
||||||
uint8_t offset;
|
u8_t offset;
|
||||||
uint8_t flags;
|
u8_t flags;
|
||||||
uint8_t wnd[2];
|
u8_t wnd[2];
|
||||||
uint16_t chksum;
|
u16_t chksum;
|
||||||
uint8_t urg[2];
|
u8_t urg[2];
|
||||||
uint8_t optdata[0];
|
u8_t optdata[0];
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define NET_UDPH_LEN 8 /* Size of UDP header */
|
#define NET_UDPH_LEN 8 /* Size of UDP header */
|
||||||
|
@ -376,14 +376,14 @@ static inline bool net_is_my_ipv6_maddr(struct in6_addr *maddr)
|
||||||
*
|
*
|
||||||
* @return True if IPv6 prefixes are the same, False otherwise.
|
* @return True if IPv6 prefixes are the same, False otherwise.
|
||||||
*/
|
*/
|
||||||
static inline bool net_is_ipv6_prefix(const uint8_t *addr1,
|
static inline bool net_is_ipv6_prefix(const u8_t *addr1,
|
||||||
const uint8_t *addr2,
|
const u8_t *addr2,
|
||||||
uint8_t length)
|
u8_t length)
|
||||||
{
|
{
|
||||||
uint8_t bits = 128 - length;
|
u8_t bits = 128 - length;
|
||||||
uint8_t bytes = length / 8;
|
u8_t bytes = length / 8;
|
||||||
uint8_t remain = bits % 8;
|
u8_t remain = bits % 8;
|
||||||
uint8_t mask;
|
u8_t mask;
|
||||||
|
|
||||||
if (length > 128) {
|
if (length > 128) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -633,10 +633,10 @@ void net_ipv6_addr_create_solicited_node(const struct in6_addr *src,
|
||||||
* @param addr7 16-bit word which is part of the address
|
* @param addr7 16-bit word which is part of the address
|
||||||
*/
|
*/
|
||||||
static inline void net_ipv6_addr_create(struct in6_addr *addr,
|
static inline void net_ipv6_addr_create(struct in6_addr *addr,
|
||||||
uint16_t addr0, uint16_t addr1,
|
u16_t addr0, u16_t addr1,
|
||||||
uint16_t addr2, uint16_t addr3,
|
u16_t addr2, u16_t addr3,
|
||||||
uint16_t addr4, uint16_t addr5,
|
u16_t addr4, u16_t addr5,
|
||||||
uint16_t addr6, uint16_t addr7)
|
u16_t addr6, u16_t addr7)
|
||||||
{
|
{
|
||||||
UNALIGNED_PUT(htons(addr0), &addr->s6_addr16[0]);
|
UNALIGNED_PUT(htons(addr0), &addr->s6_addr16[0]);
|
||||||
UNALIGNED_PUT(htons(addr1), &addr->s6_addr16[1]);
|
UNALIGNED_PUT(htons(addr1), &addr->s6_addr16[1]);
|
||||||
|
|
|
@ -39,7 +39,7 @@ struct net_l2 {
|
||||||
* reserve as headroom in a net packet. Such space is relevant to L2
|
* reserve as headroom in a net packet. Such space is relevant to L2
|
||||||
* layer only.
|
* layer only.
|
||||||
*/
|
*/
|
||||||
uint16_t (*reserve)(struct net_if *iface, void *data);
|
u16_t (*reserve)(struct net_if *iface, void *data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is used to enable/disable traffic over a network
|
* This function is used to enable/disable traffic over a network
|
||||||
|
|
|
@ -29,7 +29,7 @@ extern "C" {
|
||||||
/**
|
/**
|
||||||
* Type of the link address. This indicates the network technology that this
|
* Type of the link address. This indicates the network technology that this
|
||||||
* address is used in. Note that in order to save space we store the value
|
* address is used in. Note that in order to save space we store the value
|
||||||
* into a uint8_t variable, so please do not introduce any values > 255 in
|
* into a u8_t variable, so please do not introduce any values > 255 in
|
||||||
* this enum.
|
* this enum.
|
||||||
*/
|
*/
|
||||||
enum net_link_type {
|
enum net_link_type {
|
||||||
|
@ -47,13 +47,13 @@ enum net_link_type {
|
||||||
*/
|
*/
|
||||||
struct net_linkaddr {
|
struct net_linkaddr {
|
||||||
/** The array of byte representing the address */
|
/** The array of byte representing the address */
|
||||||
uint8_t *addr;
|
u8_t *addr;
|
||||||
|
|
||||||
/** Length of that address array */
|
/** Length of that address array */
|
||||||
uint8_t len;
|
u8_t len;
|
||||||
|
|
||||||
/** What kind of address is this for */
|
/** What kind of address is this for */
|
||||||
uint8_t type;
|
u8_t type;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,19 +62,19 @@ struct net_linkaddr {
|
||||||
* Used to hold the link address information. This variant is needed
|
* Used to hold the link address information. This variant is needed
|
||||||
* when we have to store the link layer address.
|
* when we have to store the link layer address.
|
||||||
*
|
*
|
||||||
* Note that you cannot cast this to net_linkaddr as uint8_t * is
|
* Note that you cannot cast this to net_linkaddr as u8_t * is
|
||||||
* handled differently than uint8_t addr[] and the fields are purposely
|
* handled differently than u8_t addr[] and the fields are purposely
|
||||||
* in a different order.
|
* in a different order.
|
||||||
*/
|
*/
|
||||||
struct net_linkaddr_storage {
|
struct net_linkaddr_storage {
|
||||||
/** What kind of address is this for */
|
/** What kind of address is this for */
|
||||||
uint8_t type;
|
u8_t type;
|
||||||
|
|
||||||
/** The real length of the ll address. */
|
/** The real length of the ll address. */
|
||||||
uint8_t len;
|
u8_t len;
|
||||||
|
|
||||||
/** The array of bytes representing the address */
|
/** The array of bytes representing the address */
|
||||||
uint8_t addr[NET_LINK_ADDR_MAX_LENGTH];
|
u8_t addr[NET_LINK_ADDR_MAX_LENGTH];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -109,7 +109,7 @@ static inline bool net_linkaddr_cmp(struct net_linkaddr *lladdr1,
|
||||||
* This value should always be <= NET_LINK_ADDR_MAX_LENGTH.
|
* This value should always be <= NET_LINK_ADDR_MAX_LENGTH.
|
||||||
*/
|
*/
|
||||||
static inline int net_linkaddr_set(struct net_linkaddr_storage *lladdr_store,
|
static inline int net_linkaddr_set(struct net_linkaddr_storage *lladdr_store,
|
||||||
uint8_t *new_addr, uint8_t new_len)
|
u8_t *new_addr, u8_t new_len)
|
||||||
{
|
{
|
||||||
if (!lladdr_store || !new_addr) {
|
if (!lladdr_store || !new_addr) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
|
@ -78,7 +78,7 @@ struct net_if;
|
||||||
* NULL otherwise.
|
* NULL otherwise.
|
||||||
* @param len Length in byte of the memory pointed by data.
|
* @param len Length in byte of the memory pointed by data.
|
||||||
*/
|
*/
|
||||||
typedef int (*net_mgmt_request_handler_t)(uint32_t mgmt_request,
|
typedef int (*net_mgmt_request_handler_t)(u32_t mgmt_request,
|
||||||
struct net_if *iface,
|
struct net_if *iface,
|
||||||
void *data, size_t len);
|
void *data, size_t len);
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ typedef int (*net_mgmt_request_handler_t)(uint32_t mgmt_request,
|
||||||
net_mgmt_##_mgmt_request(_mgmt_request, _iface, _data, _len)
|
net_mgmt_##_mgmt_request(_mgmt_request, _iface, _data, _len)
|
||||||
|
|
||||||
#define NET_MGMT_DEFINE_REQUEST_HANDLER(_mgmt_request) \
|
#define NET_MGMT_DEFINE_REQUEST_HANDLER(_mgmt_request) \
|
||||||
extern int net_mgmt_##_mgmt_request(uint32_t mgmt_request, \
|
extern int net_mgmt_##_mgmt_request(u32_t mgmt_request, \
|
||||||
struct net_if *iface, \
|
struct net_if *iface, \
|
||||||
void *data, size_t len)
|
void *data, size_t len)
|
||||||
|
|
||||||
|
@ -100,12 +100,12 @@ struct net_mgmt_event_callback;
|
||||||
* @brief Define the user's callback handler function signature
|
* @brief Define the user's callback handler function signature
|
||||||
* @param "struct net_mgmt_event_callback *cb"
|
* @param "struct net_mgmt_event_callback *cb"
|
||||||
* Original struct net_mgmt_event_callback owning this handler.
|
* Original struct net_mgmt_event_callback owning this handler.
|
||||||
* @param "uint32_t mgmt_event" The network event being notified.
|
* @param "u32_t mgmt_event" The network event being notified.
|
||||||
* @param "struct net_if *iface" A pointer on a struct net_if to which the
|
* @param "struct net_if *iface" A pointer on a struct net_if to which the
|
||||||
* the event belongs to, if it's an event on an iface. NULL otherwise.
|
* the event belongs to, if it's an event on an iface. NULL otherwise.
|
||||||
*/
|
*/
|
||||||
typedef void (*net_mgmt_event_handler_t)(struct net_mgmt_event_callback *cb,
|
typedef void (*net_mgmt_event_handler_t)(struct net_mgmt_event_callback *cb,
|
||||||
uint32_t mgmt_event,
|
u32_t mgmt_event,
|
||||||
struct net_if *iface);
|
struct net_if *iface);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -141,11 +141,11 @@ struct net_mgmt_event_callback {
|
||||||
* modified whenever necessary by the owner, and thus will
|
* modified whenever necessary by the owner, and thus will
|
||||||
* affect the handler being called or not.
|
* affect the handler being called or not.
|
||||||
*/
|
*/
|
||||||
uint32_t event_mask;
|
u32_t event_mask;
|
||||||
/** Internal place holder when a synchronous event wait is
|
/** Internal place holder when a synchronous event wait is
|
||||||
* successfully unlocked on a event.
|
* successfully unlocked on a event.
|
||||||
*/
|
*/
|
||||||
uint32_t raised_event;
|
u32_t raised_event;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ struct net_mgmt_event_callback {
|
||||||
static inline
|
static inline
|
||||||
void net_mgmt_init_event_callback(struct net_mgmt_event_callback *cb,
|
void net_mgmt_init_event_callback(struct net_mgmt_event_callback *cb,
|
||||||
net_mgmt_event_handler_t handler,
|
net_mgmt_event_handler_t handler,
|
||||||
uint32_t mgmt_event_mask)
|
u32_t mgmt_event_mask)
|
||||||
{
|
{
|
||||||
__ASSERT(cb, "Callback pointer should not be NULL");
|
__ASSERT(cb, "Callback pointer should not be NULL");
|
||||||
__ASSERT(handler, "Handler pointer should not be NULL");
|
__ASSERT(handler, "Handler pointer should not be NULL");
|
||||||
|
@ -186,12 +186,12 @@ void net_mgmt_del_event_callback(struct net_mgmt_event_callback *cb);
|
||||||
* @param iface a valid pointer on a struct net_if if only the event is
|
* @param iface a valid pointer on a struct net_if if only the event is
|
||||||
* based on an iface. NULL otherwise.
|
* based on an iface. NULL otherwise.
|
||||||
*/
|
*/
|
||||||
void net_mgmt_event_notify(uint32_t mgmt_event, struct net_if *iface);
|
void net_mgmt_event_notify(u32_t mgmt_event, struct net_if *iface);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Used to wait synchronously on an event mask
|
* @brief Used to wait synchronously on an event mask
|
||||||
* @param mgmt_event_mask A mask of relevant events to wait on.
|
* @param mgmt_event_mask A mask of relevant events to wait on.
|
||||||
* @param raised_event a pointer on a uint32_t to get which event from
|
* @param raised_event a pointer on a u32_t to get which event from
|
||||||
* the mask generated the event. Can be NULL if the caller is not
|
* the mask generated the event. Can be NULL if the caller is not
|
||||||
* interested in that information.
|
* interested in that information.
|
||||||
* @param iface a pointer on a place holder for the iface on which the
|
* @param iface a pointer on a place holder for the iface on which the
|
||||||
|
@ -205,8 +205,8 @@ void net_mgmt_event_notify(uint32_t mgmt_event, struct net_if *iface);
|
||||||
* be specifically returned if the timeout kick-in instead of an
|
* be specifically returned if the timeout kick-in instead of an
|
||||||
* actual event.
|
* actual event.
|
||||||
*/
|
*/
|
||||||
int net_mgmt_event_wait(uint32_t mgmt_event_mask,
|
int net_mgmt_event_wait(u32_t mgmt_event_mask,
|
||||||
uint32_t *raised_event,
|
u32_t *raised_event,
|
||||||
struct net_if **iface,
|
struct net_if **iface,
|
||||||
int timeout);
|
int timeout);
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ int net_mgmt_event_wait(uint32_t mgmt_event_mask,
|
||||||
* @param mgmt_event_mask A mask of relevant events to wait on. Listened
|
* @param mgmt_event_mask A mask of relevant events to wait on. Listened
|
||||||
* to events should be relevant to iface events and thus have the bit
|
* to events should be relevant to iface events and thus have the bit
|
||||||
* NET_MGMT_IFACE_BIT set.
|
* NET_MGMT_IFACE_BIT set.
|
||||||
* @param raised_event a pointer on a uint32_t to get which event from
|
* @param raised_event a pointer on a u32_t to get which event from
|
||||||
* the mask generated the event. Can be NULL if the caller is not
|
* the mask generated the event. Can be NULL if the caller is not
|
||||||
* interested in that information.
|
* interested in that information.
|
||||||
* @param timeout a delay in milliseconds. K_FOREVER can be used to wait
|
* @param timeout a delay in milliseconds. K_FOREVER can be used to wait
|
||||||
|
@ -227,8 +227,8 @@ int net_mgmt_event_wait(uint32_t mgmt_event_mask,
|
||||||
* actual event.
|
* actual event.
|
||||||
*/
|
*/
|
||||||
int net_mgmt_event_wait_on_iface(struct net_if *iface,
|
int net_mgmt_event_wait_on_iface(struct net_if *iface,
|
||||||
uint32_t mgmt_event_mask,
|
u32_t mgmt_event_mask,
|
||||||
uint32_t *raised_event,
|
u32_t *raised_event,
|
||||||
int timeout);
|
int timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -242,8 +242,8 @@ void net_mgmt_event_init(void);
|
||||||
#define net_mgmt_event_notify(...)
|
#define net_mgmt_event_notify(...)
|
||||||
#define net_mgmt_event_init(...)
|
#define net_mgmt_event_init(...)
|
||||||
|
|
||||||
static inline int net_mgmt_event_wait(uint32_t mgmt_event_mask,
|
static inline int net_mgmt_event_wait(u32_t mgmt_event_mask,
|
||||||
uint32_t *raised_event,
|
u32_t *raised_event,
|
||||||
struct net_if **iface,
|
struct net_if **iface,
|
||||||
int timeout)
|
int timeout)
|
||||||
{
|
{
|
||||||
|
@ -251,8 +251,8 @@ static inline int net_mgmt_event_wait(uint32_t mgmt_event_mask,
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int net_mgmt_event_wait_on_iface(struct net_if *iface,
|
static inline int net_mgmt_event_wait_on_iface(struct net_if *iface,
|
||||||
uint32_t mgmt_event_mask,
|
u32_t mgmt_event_mask,
|
||||||
uint32_t *raised_event,
|
u32_t *raised_event,
|
||||||
int timeout)
|
int timeout)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -55,7 +55,7 @@ struct net_offload {
|
||||||
const struct sockaddr *addr,
|
const struct sockaddr *addr,
|
||||||
socklen_t addrlen,
|
socklen_t addrlen,
|
||||||
net_context_connect_cb_t cb,
|
net_context_connect_cb_t cb,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,7 +64,7 @@ struct net_offload {
|
||||||
*/
|
*/
|
||||||
int (*accept)(struct net_context *context,
|
int (*accept)(struct net_context *context,
|
||||||
net_tcp_accept_cb_t cb,
|
net_tcp_accept_cb_t cb,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,7 +72,7 @@ struct net_offload {
|
||||||
*/
|
*/
|
||||||
int (*send)(struct net_pkt *pkt,
|
int (*send)(struct net_pkt *pkt,
|
||||||
net_context_send_cb_t cb,
|
net_context_send_cb_t cb,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
void *token,
|
void *token,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ struct net_offload {
|
||||||
const struct sockaddr *dst_addr,
|
const struct sockaddr *dst_addr,
|
||||||
socklen_t addrlen,
|
socklen_t addrlen,
|
||||||
net_context_send_cb_t cb,
|
net_context_send_cb_t cb,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
void *token,
|
void *token,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ struct net_offload {
|
||||||
*/
|
*/
|
||||||
int (*recv)(struct net_context *context,
|
int (*recv)(struct net_context *context,
|
||||||
net_context_recv_cb_t cb,
|
net_context_recv_cb_t cb,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -214,7 +214,7 @@ static inline int net_offload_connect(struct net_if *iface,
|
||||||
const struct sockaddr *addr,
|
const struct sockaddr *addr,
|
||||||
socklen_t addrlen,
|
socklen_t addrlen,
|
||||||
net_context_connect_cb_t cb,
|
net_context_connect_cb_t cb,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
NET_ASSERT(iface);
|
NET_ASSERT(iface);
|
||||||
|
@ -255,7 +255,7 @@ static inline int net_offload_connect(struct net_if *iface,
|
||||||
static inline int net_offload_accept(struct net_if *iface,
|
static inline int net_offload_accept(struct net_if *iface,
|
||||||
struct net_context *context,
|
struct net_context *context,
|
||||||
net_tcp_accept_cb_t cb,
|
net_tcp_accept_cb_t cb,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
NET_ASSERT(iface);
|
NET_ASSERT(iface);
|
||||||
|
@ -295,7 +295,7 @@ static inline int net_offload_accept(struct net_if *iface,
|
||||||
static inline int net_offload_send(struct net_if *iface,
|
static inline int net_offload_send(struct net_if *iface,
|
||||||
struct net_pkt *pkt,
|
struct net_pkt *pkt,
|
||||||
net_context_send_cb_t cb,
|
net_context_send_cb_t cb,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
void *token,
|
void *token,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
|
@ -340,7 +340,7 @@ static inline int net_offload_sendto(struct net_if *iface,
|
||||||
const struct sockaddr *dst_addr,
|
const struct sockaddr *dst_addr,
|
||||||
socklen_t addrlen,
|
socklen_t addrlen,
|
||||||
net_context_send_cb_t cb,
|
net_context_send_cb_t cb,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
void *token,
|
void *token,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
|
@ -388,7 +388,7 @@ static inline int net_offload_sendto(struct net_if *iface,
|
||||||
static inline int net_offload_recv(struct net_if *iface,
|
static inline int net_offload_recv(struct net_if *iface,
|
||||||
struct net_context *context,
|
struct net_context *context,
|
||||||
net_context_recv_cb_t cb,
|
net_context_recv_cb_t cb,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
NET_ASSERT(iface);
|
NET_ASSERT(iface);
|
||||||
|
|
|
@ -56,56 +56,56 @@ struct net_pkt {
|
||||||
|
|
||||||
/** @cond ignore */
|
/** @cond ignore */
|
||||||
|
|
||||||
uint8_t *appdata; /* application data starts here */
|
u8_t *appdata; /* application data starts here */
|
||||||
uint8_t *next_hdr; /* where is the next header */
|
u8_t *next_hdr; /* where is the next header */
|
||||||
|
|
||||||
/* Filled by layer 2 when network packet is received. */
|
/* Filled by layer 2 when network packet is received. */
|
||||||
struct net_linkaddr lladdr_src;
|
struct net_linkaddr lladdr_src;
|
||||||
struct net_linkaddr lladdr_dst;
|
struct net_linkaddr lladdr_dst;
|
||||||
|
|
||||||
uint16_t appdatalen;
|
u16_t appdatalen;
|
||||||
uint8_t ll_reserve; /* link layer header length */
|
u8_t ll_reserve; /* link layer header length */
|
||||||
uint8_t ip_hdr_len; /* pre-filled in order to avoid func call */
|
u8_t ip_hdr_len; /* pre-filled in order to avoid func call */
|
||||||
|
|
||||||
#if defined(CONFIG_NET_TCP)
|
#if defined(CONFIG_NET_TCP)
|
||||||
sys_snode_t sent_list;
|
sys_snode_t sent_list;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t sent : 1; /* Is this sent or not
|
u8_t sent : 1; /* Is this sent or not
|
||||||
* Used only if defined(CONFIG_NET_TCP)
|
* Used only if defined(CONFIG_NET_TCP)
|
||||||
*/
|
*/
|
||||||
uint8_t forwarding : 1; /* Are we forwarding this pkt
|
u8_t forwarding : 1; /* Are we forwarding this pkt
|
||||||
* Used only if defined(CONFIG_NET_ROUTE)
|
* Used only if defined(CONFIG_NET_ROUTE)
|
||||||
*/
|
*/
|
||||||
uint8_t family : 4; /* IPv4 vs IPv6 */
|
u8_t family : 4; /* IPv4 vs IPv6 */
|
||||||
uint8_t _unused : 4;
|
u8_t _unused : 4;
|
||||||
|
|
||||||
#if defined(CONFIG_NET_IPV6)
|
#if defined(CONFIG_NET_IPV6)
|
||||||
uint8_t ipv6_hop_limit; /* IPv6 hop limit for this network packet. */
|
u8_t ipv6_hop_limit; /* IPv6 hop limit for this network packet. */
|
||||||
uint8_t ipv6_ext_len; /* length of extension headers */
|
u8_t ipv6_ext_len; /* length of extension headers */
|
||||||
uint8_t ipv6_ext_opt_len; /* IPv6 ND option length */
|
u8_t ipv6_ext_opt_len; /* IPv6 ND option length */
|
||||||
|
|
||||||
/* Where is the start of the last header before payload data
|
/* Where is the start of the last header before payload data
|
||||||
* in IPv6 packet. This is offset value from start of the IPv6
|
* in IPv6 packet. This is offset value from start of the IPv6
|
||||||
* packet. Note that this value should be updated by who ever
|
* packet. Note that this value should be updated by who ever
|
||||||
* adds IPv6 extension headers to the network packet.
|
* adds IPv6 extension headers to the network packet.
|
||||||
*/
|
*/
|
||||||
uint16_t ipv6_prev_hdr_start;
|
u16_t ipv6_prev_hdr_start;
|
||||||
|
|
||||||
#if defined(CONFIG_NET_IPV6_FRAGMENT)
|
#if defined(CONFIG_NET_IPV6_FRAGMENT)
|
||||||
uint16_t ipv6_fragment_offset; /* Fragment offset of this packet */
|
u16_t ipv6_fragment_offset; /* Fragment offset of this packet */
|
||||||
uint32_t ipv6_fragment_id; /* Fragment id */
|
u32_t ipv6_fragment_id; /* Fragment id */
|
||||||
uint8_t *ipv6_frag_hdr_start; /* Where starts the fragment header */
|
u8_t *ipv6_frag_hdr_start; /* Where starts the fragment header */
|
||||||
#endif /* CONFIG_NET_IPV6_FRAGMENT */
|
#endif /* CONFIG_NET_IPV6_FRAGMENT */
|
||||||
#endif /* CONFIG_NET_IPV6 */
|
#endif /* CONFIG_NET_IPV6 */
|
||||||
|
|
||||||
#if defined(CONFIG_NET_L2_IEEE802154)
|
#if defined(CONFIG_NET_L2_IEEE802154)
|
||||||
uint8_t ieee802154_rssi;
|
u8_t ieee802154_rssi;
|
||||||
#endif
|
#endif
|
||||||
/* @endcond */
|
/* @endcond */
|
||||||
|
|
||||||
/** Reference counter */
|
/** Reference counter */
|
||||||
uint8_t ref;
|
u8_t ref;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @cond ignore */
|
/** @cond ignore */
|
||||||
|
@ -155,38 +155,38 @@ static inline void net_pkt_set_iface(struct net_pkt *pkt, struct net_if *iface)
|
||||||
pkt->lladdr_dst.type = iface->link_addr.type;
|
pkt->lladdr_dst.type = iface->link_addr.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t net_pkt_family(struct net_pkt *pkt)
|
static inline u8_t net_pkt_family(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return pkt->family;
|
return pkt->family;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void net_pkt_set_family(struct net_pkt *pkt, uint8_t family)
|
static inline void net_pkt_set_family(struct net_pkt *pkt, u8_t family)
|
||||||
{
|
{
|
||||||
pkt->family = family;
|
pkt->family = family;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
|
static inline u8_t net_pkt_ip_hdr_len(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return pkt->ip_hdr_len;
|
return pkt->ip_hdr_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, uint8_t len)
|
static inline void net_pkt_set_ip_hdr_len(struct net_pkt *pkt, u8_t len)
|
||||||
{
|
{
|
||||||
pkt->ip_hdr_len = len;
|
pkt->ip_hdr_len = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t *net_pkt_next_hdr(struct net_pkt *pkt)
|
static inline u8_t *net_pkt_next_hdr(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return pkt->next_hdr;
|
return pkt->next_hdr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void net_pkt_set_next_hdr(struct net_pkt *pkt, uint8_t *hdr)
|
static inline void net_pkt_set_next_hdr(struct net_pkt *pkt, u8_t *hdr)
|
||||||
{
|
{
|
||||||
pkt->next_hdr = hdr;
|
pkt->next_hdr = hdr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NET_TCP)
|
#if defined(CONFIG_NET_TCP)
|
||||||
static inline uint8_t net_pkt_sent(struct net_pkt *pkt)
|
static inline u8_t net_pkt_sent(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return pkt->sent;
|
return pkt->sent;
|
||||||
}
|
}
|
||||||
|
@ -215,79 +215,79 @@ static inline bool net_pkt_forwarding(struct net_pkt *pkt)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_NET_IPV6)
|
#if defined(CONFIG_NET_IPV6)
|
||||||
static inline uint8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
|
static inline u8_t net_pkt_ipv6_ext_opt_len(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return pkt->ipv6_ext_opt_len;
|
return pkt->ipv6_ext_opt_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
|
static inline void net_pkt_set_ipv6_ext_opt_len(struct net_pkt *pkt,
|
||||||
uint8_t len)
|
u8_t len)
|
||||||
{
|
{
|
||||||
pkt->ipv6_ext_opt_len = len;
|
pkt->ipv6_ext_opt_len = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
|
static inline u8_t net_pkt_ipv6_ext_len(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return pkt->ipv6_ext_len;
|
return pkt->ipv6_ext_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, uint8_t len)
|
static inline void net_pkt_set_ipv6_ext_len(struct net_pkt *pkt, u8_t len)
|
||||||
{
|
{
|
||||||
pkt->ipv6_ext_len = len;
|
pkt->ipv6_ext_len = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
|
static inline u16_t net_pkt_ipv6_hdr_prev(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return pkt->ipv6_prev_hdr_start;
|
return pkt->ipv6_prev_hdr_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
|
static inline void net_pkt_set_ipv6_hdr_prev(struct net_pkt *pkt,
|
||||||
uint16_t offset)
|
u16_t offset)
|
||||||
{
|
{
|
||||||
pkt->ipv6_prev_hdr_start = offset;
|
pkt->ipv6_prev_hdr_start = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
|
static inline u8_t net_pkt_ipv6_hop_limit(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return pkt->ipv6_hop_limit;
|
return pkt->ipv6_hop_limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
|
static inline void net_pkt_set_ipv6_hop_limit(struct net_pkt *pkt,
|
||||||
uint8_t hop_limit)
|
u8_t hop_limit)
|
||||||
{
|
{
|
||||||
pkt->ipv6_hop_limit = hop_limit;
|
pkt->ipv6_hop_limit = hop_limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NET_IPV6_FRAGMENT)
|
#if defined(CONFIG_NET_IPV6_FRAGMENT)
|
||||||
static inline uint8_t *net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
|
static inline u8_t *net_pkt_ipv6_fragment_start(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return pkt->ipv6_frag_hdr_start;
|
return pkt->ipv6_frag_hdr_start;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
|
static inline void net_pkt_set_ipv6_fragment_start(struct net_pkt *pkt,
|
||||||
uint8_t *start)
|
u8_t *start)
|
||||||
{
|
{
|
||||||
pkt->ipv6_frag_hdr_start = start;
|
pkt->ipv6_frag_hdr_start = start;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
|
static inline u16_t net_pkt_ipv6_fragment_offset(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return pkt->ipv6_fragment_offset;
|
return pkt->ipv6_fragment_offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void net_pkt_set_ipv6_fragment_offset(struct net_pkt *pkt,
|
static inline void net_pkt_set_ipv6_fragment_offset(struct net_pkt *pkt,
|
||||||
uint16_t offset)
|
u16_t offset)
|
||||||
{
|
{
|
||||||
pkt->ipv6_fragment_offset = offset;
|
pkt->ipv6_fragment_offset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
|
static inline u32_t net_pkt_ipv6_fragment_id(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return pkt->ipv6_fragment_id;
|
return pkt->ipv6_fragment_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
|
static inline void net_pkt_set_ipv6_fragment_id(struct net_pkt *pkt,
|
||||||
uint32_t id)
|
u32_t id)
|
||||||
{
|
{
|
||||||
pkt->ipv6_fragment_id = id;
|
pkt->ipv6_fragment_id = id;
|
||||||
}
|
}
|
||||||
|
@ -302,60 +302,60 @@ static inline size_t net_pkt_get_len(struct net_pkt *pkt)
|
||||||
return net_buf_frags_len(pkt->frags);
|
return net_buf_frags_len(pkt->frags);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t *net_pkt_ip_data(struct net_pkt *pkt)
|
static inline u8_t *net_pkt_ip_data(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return pkt->frags->data;
|
return pkt->frags->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t *net_pkt_udp_data(struct net_pkt *pkt)
|
static inline u8_t *net_pkt_udp_data(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return &pkt->frags->data[net_pkt_ip_hdr_len(pkt) +
|
return &pkt->frags->data[net_pkt_ip_hdr_len(pkt) +
|
||||||
net_pkt_ipv6_ext_len(pkt)];
|
net_pkt_ipv6_ext_len(pkt)];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t *net_pkt_tcp_data(struct net_pkt *pkt)
|
static inline u8_t *net_pkt_tcp_data(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return &pkt->frags->data[net_pkt_ip_hdr_len(pkt) +
|
return &pkt->frags->data[net_pkt_ip_hdr_len(pkt) +
|
||||||
net_pkt_ipv6_ext_len(pkt)];
|
net_pkt_ipv6_ext_len(pkt)];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t *net_pkt_icmp_data(struct net_pkt *pkt)
|
static inline u8_t *net_pkt_icmp_data(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return &pkt->frags->data[net_pkt_ip_hdr_len(pkt) +
|
return &pkt->frags->data[net_pkt_ip_hdr_len(pkt) +
|
||||||
net_pkt_ipv6_ext_len(pkt)];
|
net_pkt_ipv6_ext_len(pkt)];
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t *net_pkt_appdata(struct net_pkt *pkt)
|
static inline u8_t *net_pkt_appdata(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return pkt->appdata;
|
return pkt->appdata;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void net_pkt_set_appdata(struct net_pkt *pkt, uint8_t *data)
|
static inline void net_pkt_set_appdata(struct net_pkt *pkt, u8_t *data)
|
||||||
{
|
{
|
||||||
pkt->appdata = data;
|
pkt->appdata = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint16_t net_pkt_appdatalen(struct net_pkt *pkt)
|
static inline u16_t net_pkt_appdatalen(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return pkt->appdatalen;
|
return pkt->appdatalen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void net_pkt_set_appdatalen(struct net_pkt *pkt, uint16_t len)
|
static inline void net_pkt_set_appdatalen(struct net_pkt *pkt, u16_t len)
|
||||||
{
|
{
|
||||||
pkt->appdatalen = len;
|
pkt->appdatalen = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t net_pkt_ll_reserve(struct net_pkt *pkt)
|
static inline u8_t net_pkt_ll_reserve(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return pkt->ll_reserve;
|
return pkt->ll_reserve;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void net_pkt_set_ll_reserve(struct net_pkt *pkt, uint8_t len)
|
static inline void net_pkt_set_ll_reserve(struct net_pkt *pkt, u8_t len)
|
||||||
{
|
{
|
||||||
pkt->ll_reserve = len;
|
pkt->ll_reserve = len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t *net_pkt_ll(struct net_pkt *pkt)
|
static inline u8_t *net_pkt_ll(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return net_pkt_ip_data(pkt) - net_pkt_ll_reserve(pkt);
|
return net_pkt_ip_data(pkt) - net_pkt_ll_reserve(pkt);
|
||||||
}
|
}
|
||||||
|
@ -379,20 +379,20 @@ static inline void net_pkt_ll_clear(struct net_pkt *pkt)
|
||||||
|
|
||||||
static inline void net_pkt_ll_swap(struct net_pkt *pkt)
|
static inline void net_pkt_ll_swap(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
uint8_t *addr = net_pkt_ll_src(pkt)->addr;
|
u8_t *addr = net_pkt_ll_src(pkt)->addr;
|
||||||
|
|
||||||
net_pkt_ll_src(pkt)->addr = net_pkt_ll_dst(pkt)->addr;
|
net_pkt_ll_src(pkt)->addr = net_pkt_ll_dst(pkt)->addr;
|
||||||
net_pkt_ll_dst(pkt)->addr = addr;
|
net_pkt_ll_dst(pkt)->addr = addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NET_L2_IEEE802154)
|
#if defined(CONFIG_NET_L2_IEEE802154)
|
||||||
static inline uint8_t net_pkt_ieee802154_rssi(struct net_pkt *pkt)
|
static inline u8_t net_pkt_ieee802154_rssi(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
return pkt->ieee802154_rssi;
|
return pkt->ieee802154_rssi;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void net_pkt_set_ieee802154_rssi(struct net_pkt *pkt,
|
static inline void net_pkt_set_ieee802154_rssi(struct net_pkt *pkt,
|
||||||
uint8_t rssi)
|
u8_t rssi)
|
||||||
{
|
{
|
||||||
pkt->ieee802154_rssi = rssi;
|
pkt->ieee802154_rssi = rssi;
|
||||||
}
|
}
|
||||||
|
@ -441,8 +441,8 @@ static inline void net_pkt_set_src_ipv6_addr(struct net_pkt *pkt)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct net_pkt *net_pkt_get_reserve_debug(struct k_mem_slab *slab,
|
struct net_pkt *net_pkt_get_reserve_debug(struct k_mem_slab *slab,
|
||||||
uint16_t reserve_head,
|
u16_t reserve_head,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
const char *caller,
|
const char *caller,
|
||||||
int line);
|
int line);
|
||||||
#define net_pkt_get_reserve(slab, reserve_head, timeout) \
|
#define net_pkt_get_reserve(slab, reserve_head, timeout) \
|
||||||
|
@ -450,8 +450,8 @@ struct net_pkt *net_pkt_get_reserve_debug(struct k_mem_slab *slab,
|
||||||
__func__, __LINE__)
|
__func__, __LINE__)
|
||||||
|
|
||||||
struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
|
struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
|
||||||
uint16_t reserve_head,
|
u16_t reserve_head,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
const char *caller,
|
const char *caller,
|
||||||
int line);
|
int line);
|
||||||
|
|
||||||
|
@ -460,51 +460,51 @@ struct net_buf *net_pkt_get_reserve_data_debug(struct net_buf_pool *pool,
|
||||||
__func__, __LINE__)
|
__func__, __LINE__)
|
||||||
|
|
||||||
struct net_pkt *net_pkt_get_rx_debug(struct net_context *context,
|
struct net_pkt *net_pkt_get_rx_debug(struct net_context *context,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
const char *caller, int line);
|
const char *caller, int line);
|
||||||
#define net_pkt_get_rx(context, timeout) \
|
#define net_pkt_get_rx(context, timeout) \
|
||||||
net_pkt_get_rx_debug(context, timeout, __func__, __LINE__)
|
net_pkt_get_rx_debug(context, timeout, __func__, __LINE__)
|
||||||
|
|
||||||
struct net_pkt *net_pkt_get_tx_debug(struct net_context *context,
|
struct net_pkt *net_pkt_get_tx_debug(struct net_context *context,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
const char *caller, int line);
|
const char *caller, int line);
|
||||||
#define net_pkt_get_tx(context, timeout) \
|
#define net_pkt_get_tx(context, timeout) \
|
||||||
net_pkt_get_tx_debug(context, timeout, __func__, __LINE__)
|
net_pkt_get_tx_debug(context, timeout, __func__, __LINE__)
|
||||||
|
|
||||||
struct net_buf *net_pkt_get_data_debug(struct net_context *context,
|
struct net_buf *net_pkt_get_data_debug(struct net_context *context,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
const char *caller, int line);
|
const char *caller, int line);
|
||||||
#define net_pkt_get_data(context, timeout) \
|
#define net_pkt_get_data(context, timeout) \
|
||||||
net_pkt_get_data_debug(context, timeout, __func__, __LINE__)
|
net_pkt_get_data_debug(context, timeout, __func__, __LINE__)
|
||||||
|
|
||||||
struct net_pkt *net_pkt_get_reserve_rx_debug(uint16_t reserve_head,
|
struct net_pkt *net_pkt_get_reserve_rx_debug(u16_t reserve_head,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
const char *caller, int line);
|
const char *caller, int line);
|
||||||
#define net_pkt_get_reserve_rx(res, timeout) \
|
#define net_pkt_get_reserve_rx(res, timeout) \
|
||||||
net_pkt_get_reserve_rx_debug(res, timeout, __func__, __LINE__)
|
net_pkt_get_reserve_rx_debug(res, timeout, __func__, __LINE__)
|
||||||
|
|
||||||
struct net_pkt *net_pkt_get_reserve_tx_debug(uint16_t reserve_head,
|
struct net_pkt *net_pkt_get_reserve_tx_debug(u16_t reserve_head,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
const char *caller, int line);
|
const char *caller, int line);
|
||||||
#define net_pkt_get_reserve_tx(res, timeout) \
|
#define net_pkt_get_reserve_tx(res, timeout) \
|
||||||
net_pkt_get_reserve_tx_debug(res, timeout, __func__, __LINE__)
|
net_pkt_get_reserve_tx_debug(res, timeout, __func__, __LINE__)
|
||||||
|
|
||||||
struct net_buf *net_pkt_get_reserve_rx_data_debug(uint16_t reserve_head,
|
struct net_buf *net_pkt_get_reserve_rx_data_debug(u16_t reserve_head,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
const char *caller,
|
const char *caller,
|
||||||
int line);
|
int line);
|
||||||
#define net_pkt_get_reserve_rx_data(res, timeout) \
|
#define net_pkt_get_reserve_rx_data(res, timeout) \
|
||||||
net_pkt_get_reserve_rx_data_debug(res, timeout, __func__, __LINE__)
|
net_pkt_get_reserve_rx_data_debug(res, timeout, __func__, __LINE__)
|
||||||
|
|
||||||
struct net_buf *net_pkt_get_reserve_tx_data_debug(uint16_t reserve_head,
|
struct net_buf *net_pkt_get_reserve_tx_data_debug(u16_t reserve_head,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
const char *caller,
|
const char *caller,
|
||||||
int line);
|
int line);
|
||||||
#define net_pkt_get_reserve_tx_data(res, timeout) \
|
#define net_pkt_get_reserve_tx_data(res, timeout) \
|
||||||
net_pkt_get_reserve_tx_data_debug(res, timeout, __func__, __LINE__)
|
net_pkt_get_reserve_tx_data_debug(res, timeout, __func__, __LINE__)
|
||||||
|
|
||||||
struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt,
|
struct net_buf *net_pkt_get_frag_debug(struct net_pkt *pkt,
|
||||||
int32_t timeout,
|
s32_t timeout,
|
||||||
const char *caller, int line);
|
const char *caller, int line);
|
||||||
#define net_pkt_get_frag(pkt, timeout) \
|
#define net_pkt_get_frag(pkt, timeout) \
|
||||||
net_pkt_get_frag_debug(pkt, timeout, __func__, __LINE__)
|
net_pkt_get_frag_debug(pkt, timeout, __func__, __LINE__)
|
||||||
|
@ -570,8 +570,8 @@ void net_pkt_print_frags(struct net_pkt *pkt);
|
||||||
* @return Network packet if successful, NULL otherwise.
|
* @return Network packet if successful, NULL otherwise.
|
||||||
*/
|
*/
|
||||||
struct net_pkt *net_pkt_get_reserve(struct k_mem_slab *slab,
|
struct net_pkt *net_pkt_get_reserve(struct k_mem_slab *slab,
|
||||||
uint16_t reserve_head,
|
u16_t reserve_head,
|
||||||
int32_t timeout);
|
s32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get packet from the RX packet slab.
|
* @brief Get packet from the RX packet slab.
|
||||||
|
@ -588,7 +588,7 @@ struct net_pkt *net_pkt_get_reserve(struct k_mem_slab *slab,
|
||||||
* @return Network packet if successful, NULL otherwise.
|
* @return Network packet if successful, NULL otherwise.
|
||||||
*/
|
*/
|
||||||
struct net_pkt *net_pkt_get_rx(struct net_context *context,
|
struct net_pkt *net_pkt_get_rx(struct net_context *context,
|
||||||
int32_t timeout);
|
s32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get packet from the TX packets slab.
|
* @brief Get packet from the TX packets slab.
|
||||||
|
@ -606,7 +606,7 @@ struct net_pkt *net_pkt_get_rx(struct net_context *context,
|
||||||
* @return Network packet if successful, NULL otherwise.
|
* @return Network packet if successful, NULL otherwise.
|
||||||
*/
|
*/
|
||||||
struct net_pkt *net_pkt_get_tx(struct net_context *context,
|
struct net_pkt *net_pkt_get_tx(struct net_context *context,
|
||||||
int32_t timeout);
|
s32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get buffer from the DATA buffers pool.
|
* @brief Get buffer from the DATA buffers pool.
|
||||||
|
@ -624,7 +624,7 @@ struct net_pkt *net_pkt_get_tx(struct net_context *context,
|
||||||
* @return Network buffer if successful, NULL otherwise.
|
* @return Network buffer if successful, NULL otherwise.
|
||||||
*/
|
*/
|
||||||
struct net_buf *net_pkt_get_data(struct net_context *context,
|
struct net_buf *net_pkt_get_data(struct net_context *context,
|
||||||
int32_t timeout);
|
s32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get RX packet from slab but also reserve headroom for
|
* @brief Get RX packet from slab but also reserve headroom for
|
||||||
|
@ -641,8 +641,8 @@ struct net_buf *net_pkt_get_data(struct net_context *context,
|
||||||
*
|
*
|
||||||
* @return Network packet if successful, NULL otherwise.
|
* @return Network packet if successful, NULL otherwise.
|
||||||
*/
|
*/
|
||||||
struct net_pkt *net_pkt_get_reserve_rx(uint16_t reserve_head,
|
struct net_pkt *net_pkt_get_reserve_rx(u16_t reserve_head,
|
||||||
int32_t timeout);
|
s32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get TX packet from slab but also reserve headroom for
|
* @brief Get TX packet from slab but also reserve headroom for
|
||||||
|
@ -659,8 +659,8 @@ struct net_pkt *net_pkt_get_reserve_rx(uint16_t reserve_head,
|
||||||
*
|
*
|
||||||
* @return Network packet if successful, NULL otherwise.
|
* @return Network packet if successful, NULL otherwise.
|
||||||
*/
|
*/
|
||||||
struct net_pkt *net_pkt_get_reserve_tx(uint16_t reserve_head,
|
struct net_pkt *net_pkt_get_reserve_tx(u16_t reserve_head,
|
||||||
int32_t timeout);
|
s32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get RX DATA buffer from pool but also reserve headroom for
|
* @brief Get RX DATA buffer from pool but also reserve headroom for
|
||||||
|
@ -677,8 +677,8 @@ struct net_pkt *net_pkt_get_reserve_tx(uint16_t reserve_head,
|
||||||
*
|
*
|
||||||
* @return Network buffer if successful, NULL otherwise.
|
* @return Network buffer if successful, NULL otherwise.
|
||||||
*/
|
*/
|
||||||
struct net_buf *net_pkt_get_reserve_rx_data(uint16_t reserve_head,
|
struct net_buf *net_pkt_get_reserve_rx_data(u16_t reserve_head,
|
||||||
int32_t timeout);
|
s32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get TX DATA buffer from pool but also reserve headroom for
|
* @brief Get TX DATA buffer from pool but also reserve headroom for
|
||||||
|
@ -695,8 +695,8 @@ struct net_buf *net_pkt_get_reserve_rx_data(uint16_t reserve_head,
|
||||||
*
|
*
|
||||||
* @return Network buffer if successful, NULL otherwise.
|
* @return Network buffer if successful, NULL otherwise.
|
||||||
*/
|
*/
|
||||||
struct net_buf *net_pkt_get_reserve_tx_data(uint16_t reserve_head,
|
struct net_buf *net_pkt_get_reserve_tx_data(u16_t reserve_head,
|
||||||
int32_t timeout);
|
s32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get a data fragment that might be from user specific
|
* @brief Get a data fragment that might be from user specific
|
||||||
|
@ -710,7 +710,7 @@ struct net_buf *net_pkt_get_reserve_tx_data(uint16_t reserve_head,
|
||||||
*
|
*
|
||||||
* @return Network buffer if successful, NULL otherwise.
|
* @return Network buffer if successful, NULL otherwise.
|
||||||
*/
|
*/
|
||||||
struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, int32_t timeout);
|
struct net_buf *net_pkt_get_frag(struct net_pkt *pkt, s32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Place packet back into the available packets slab
|
* @brief Place packet back into the available packets slab
|
||||||
|
@ -801,7 +801,7 @@ void net_pkt_frag_insert(struct net_pkt *pkt, struct net_buf *frag);
|
||||||
* @return New fragment list if successful, NULL otherwise.
|
* @return New fragment list if successful, NULL otherwise.
|
||||||
*/
|
*/
|
||||||
struct net_buf *net_pkt_copy(struct net_pkt *pkt, size_t amount,
|
struct net_buf *net_pkt_copy(struct net_pkt *pkt, size_t amount,
|
||||||
size_t reserve, int32_t timeout);
|
size_t reserve, s32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Copy a packet fragment list while reserving some extra space
|
* @brief Copy a packet fragment list while reserving some extra space
|
||||||
|
@ -820,7 +820,7 @@ struct net_buf *net_pkt_copy(struct net_pkt *pkt, size_t amount,
|
||||||
*/
|
*/
|
||||||
static inline struct net_buf *net_pkt_copy_all(struct net_pkt *pkt,
|
static inline struct net_buf *net_pkt_copy_all(struct net_pkt *pkt,
|
||||||
size_t reserve,
|
size_t reserve,
|
||||||
int32_t timeout)
|
s32_t timeout)
|
||||||
{
|
{
|
||||||
return net_pkt_copy(pkt, net_buf_frags_len(pkt->frags),
|
return net_pkt_copy(pkt, net_buf_frags_len(pkt->frags),
|
||||||
reserve, timeout);
|
reserve, timeout);
|
||||||
|
@ -840,7 +840,7 @@ static inline struct net_buf *net_pkt_copy_all(struct net_pkt *pkt,
|
||||||
* @return -ENOMEM on error
|
* @return -ENOMEM on error
|
||||||
*/
|
*/
|
||||||
int net_frag_linear_copy(struct net_buf *dst, struct net_buf *src,
|
int net_frag_linear_copy(struct net_buf *dst, struct net_buf *src,
|
||||||
uint16_t offset, uint16_t len);
|
u16_t offset, u16_t len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Compact the fragment list of a packet.
|
* @brief Compact the fragment list of a packet.
|
||||||
|
@ -871,11 +871,11 @@ bool net_pkt_compact(struct net_pkt *pkt);
|
||||||
* False otherwise (In-case of false pkt might contain input
|
* False otherwise (In-case of false pkt might contain input
|
||||||
* data in the process of placing into fragments).
|
* data in the process of placing into fragments).
|
||||||
*/
|
*/
|
||||||
bool net_pkt_append(struct net_pkt *pkt, uint16_t len, const uint8_t *data,
|
bool net_pkt_append(struct net_pkt *pkt, u16_t len, const u8_t *data,
|
||||||
int32_t timeout);
|
s32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Append uint8_t data to last fragment in fragment list of a packet
|
* @brief Append u8_t data to last fragment in fragment list of a packet
|
||||||
*
|
*
|
||||||
* @details Append data to last fragment. If there is not enough space in last
|
* @details Append data to last fragment. If there is not enough space in last
|
||||||
* fragment then new data fragment will be created and will be added to
|
* fragment then new data fragment will be created and will be added to
|
||||||
|
@ -888,13 +888,13 @@ bool net_pkt_append(struct net_pkt *pkt, uint16_t len, const uint8_t *data,
|
||||||
* False otherwise (In-case of false pkt might contain input
|
* False otherwise (In-case of false pkt might contain input
|
||||||
* data in the process of placing into fragments).
|
* data in the process of placing into fragments).
|
||||||
*/
|
*/
|
||||||
static inline bool net_pkt_append_u8(struct net_pkt *pkt, uint8_t data)
|
static inline bool net_pkt_append_u8(struct net_pkt *pkt, u8_t data)
|
||||||
{
|
{
|
||||||
return net_pkt_append(pkt, 1, &data, K_FOREVER);
|
return net_pkt_append(pkt, 1, &data, K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Append uint16_t data to last fragment in fragment list of a packet
|
* @brief Append u16_t data to last fragment in fragment list of a packet
|
||||||
*
|
*
|
||||||
* @details Append data to last fragment. If there is not enough space in last
|
* @details Append data to last fragment. If there is not enough space in last
|
||||||
* fragment then new data fragment will be created and will be added to
|
* fragment then new data fragment will be created and will be added to
|
||||||
|
@ -907,16 +907,16 @@ static inline bool net_pkt_append_u8(struct net_pkt *pkt, uint8_t data)
|
||||||
* False otherwise (In-case of false pkt might contain input data
|
* False otherwise (In-case of false pkt might contain input data
|
||||||
* in the process of placing into fragments).
|
* in the process of placing into fragments).
|
||||||
*/
|
*/
|
||||||
static inline bool net_pkt_append_be16(struct net_pkt *pkt, uint16_t data)
|
static inline bool net_pkt_append_be16(struct net_pkt *pkt, u16_t data)
|
||||||
{
|
{
|
||||||
uint16_t value = sys_cpu_to_be16(data);
|
u16_t value = sys_cpu_to_be16(data);
|
||||||
|
|
||||||
return net_pkt_append(pkt, sizeof(uint16_t), (uint8_t *)&value,
|
return net_pkt_append(pkt, sizeof(u16_t), (u8_t *)&value,
|
||||||
K_FOREVER);
|
K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Append uint32_t data to last fragment in fragment list of a packet
|
* @brief Append u32_t data to last fragment in fragment list of a packet
|
||||||
*
|
*
|
||||||
* @details Append data to last fragment. If there is not enough space in last
|
* @details Append data to last fragment. If there is not enough space in last
|
||||||
* fragment then new data fragment will be created and will be added to
|
* fragment then new data fragment will be created and will be added to
|
||||||
|
@ -929,16 +929,16 @@ static inline bool net_pkt_append_be16(struct net_pkt *pkt, uint16_t data)
|
||||||
* False otherwise (In-case of false pkt might contain input data
|
* False otherwise (In-case of false pkt might contain input data
|
||||||
* in the process of placing into fragments).
|
* in the process of placing into fragments).
|
||||||
*/
|
*/
|
||||||
static inline bool net_pkt_append_be32(struct net_pkt *pkt, uint32_t data)
|
static inline bool net_pkt_append_be32(struct net_pkt *pkt, u32_t data)
|
||||||
{
|
{
|
||||||
uint32_t value = sys_cpu_to_be32(data);
|
u32_t value = sys_cpu_to_be32(data);
|
||||||
|
|
||||||
return net_pkt_append(pkt, sizeof(uint32_t), (uint8_t *)&value,
|
return net_pkt_append(pkt, sizeof(u32_t), (u8_t *)&value,
|
||||||
K_FOREVER);
|
K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Append uint32_t data to last fragment in fragment list
|
* @brief Append u32_t data to last fragment in fragment list
|
||||||
*
|
*
|
||||||
* @details Append data to last fragment. If there is not enough space in last
|
* @details Append data to last fragment. If there is not enough space in last
|
||||||
* fragment then new data fragment will be created and will be added to
|
* fragment then new data fragment will be created and will be added to
|
||||||
|
@ -951,11 +951,11 @@ static inline bool net_pkt_append_be32(struct net_pkt *pkt, uint32_t data)
|
||||||
* False otherwise (In-case of false pkt might contain input data
|
* False otherwise (In-case of false pkt might contain input data
|
||||||
* in the process of placing into fragments).
|
* in the process of placing into fragments).
|
||||||
*/
|
*/
|
||||||
static inline bool net_pkt_append_le32(struct net_pkt *pkt, uint32_t data)
|
static inline bool net_pkt_append_le32(struct net_pkt *pkt, u32_t data)
|
||||||
{
|
{
|
||||||
uint32_t value = sys_cpu_to_le32(data);
|
u32_t value = sys_cpu_to_le32(data);
|
||||||
|
|
||||||
return net_pkt_append(pkt, sizeof(uint32_t), (uint8_t *)&value,
|
return net_pkt_append(pkt, sizeof(u32_t), (u8_t *)&value,
|
||||||
K_FOREVER);
|
K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -978,8 +978,8 @@ static inline bool net_pkt_append_le32(struct net_pkt *pkt, uint32_t data)
|
||||||
* NULL and pos is 0 after successful read,
|
* NULL and pos is 0 after successful read,
|
||||||
* NULL and pos is 0xffff otherwise.
|
* NULL and pos is 0xffff otherwise.
|
||||||
*/
|
*/
|
||||||
struct net_buf *net_frag_read(struct net_buf *frag, uint16_t offset,
|
struct net_buf *net_frag_read(struct net_buf *frag, u16_t offset,
|
||||||
uint16_t *pos, uint16_t len, uint8_t *data);
|
u16_t *pos, u16_t len, u8_t *data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Skip N number of bytes while reading buffer
|
* @brief Skip N number of bytes while reading buffer
|
||||||
|
@ -1001,8 +1001,8 @@ struct net_buf *net_frag_read(struct net_buf *frag, uint16_t offset,
|
||||||
* NULL and pos is 0xffff otherwise.
|
* NULL and pos is 0xffff otherwise.
|
||||||
*/
|
*/
|
||||||
static inline struct net_buf *net_frag_skip(struct net_buf *frag,
|
static inline struct net_buf *net_frag_skip(struct net_buf *frag,
|
||||||
uint16_t offset,
|
u16_t offset,
|
||||||
uint16_t *pos, uint16_t len)
|
u16_t *pos, u16_t len)
|
||||||
{
|
{
|
||||||
return net_frag_read(frag, offset, pos, len, NULL);
|
return net_frag_read(frag, offset, pos, len, NULL);
|
||||||
}
|
}
|
||||||
|
@ -1020,9 +1020,9 @@ static inline struct net_buf *net_frag_skip(struct net_buf *frag,
|
||||||
* NULL otherwise (if pos is 0, NULL is not a failure case).
|
* NULL otherwise (if pos is 0, NULL is not a failure case).
|
||||||
*/
|
*/
|
||||||
static inline struct net_buf *net_frag_read_u8(struct net_buf *frag,
|
static inline struct net_buf *net_frag_read_u8(struct net_buf *frag,
|
||||||
uint16_t offset,
|
u16_t offset,
|
||||||
uint16_t *pos,
|
u16_t *pos,
|
||||||
uint8_t *value)
|
u8_t *value)
|
||||||
{
|
{
|
||||||
return net_frag_read(frag, offset, pos, 1, value);
|
return net_frag_read(frag, offset, pos, 1, value);
|
||||||
}
|
}
|
||||||
|
@ -1039,8 +1039,8 @@ static inline struct net_buf *net_frag_read_u8(struct net_buf *frag,
|
||||||
* @return Pointer to fragment after successful read,
|
* @return Pointer to fragment after successful read,
|
||||||
* NULL otherwise (if pos is 0, NULL is not a failure case).
|
* NULL otherwise (if pos is 0, NULL is not a failure case).
|
||||||
*/
|
*/
|
||||||
struct net_buf *net_frag_read_be16(struct net_buf *frag, uint16_t offset,
|
struct net_buf *net_frag_read_be16(struct net_buf *frag, u16_t offset,
|
||||||
uint16_t *pos, uint16_t *value);
|
u16_t *pos, u16_t *value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get 32 bit big endian value from fragmented buffer
|
* @brief Get 32 bit big endian value from fragmented buffer
|
||||||
|
@ -1054,8 +1054,8 @@ struct net_buf *net_frag_read_be16(struct net_buf *frag, uint16_t offset,
|
||||||
* @return Pointer to fragment after successful read,
|
* @return Pointer to fragment after successful read,
|
||||||
* NULL otherwise (if pos is 0, NULL is not a failure case).
|
* NULL otherwise (if pos is 0, NULL is not a failure case).
|
||||||
*/
|
*/
|
||||||
struct net_buf *net_frag_read_be32(struct net_buf *frag, uint16_t offset,
|
struct net_buf *net_frag_read_be32(struct net_buf *frag, u16_t offset,
|
||||||
uint16_t *pos, uint32_t *value);
|
u16_t *pos, u32_t *value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Write data to an arbitrary offset in fragments list of a packet.
|
* @brief Write data to an arbitrary offset in fragments list of a packet.
|
||||||
|
@ -1118,44 +1118,44 @@ struct net_buf *net_frag_read_be32(struct net_buf *frag, uint16_t offset,
|
||||||
* NULL and pos is 0xffff otherwise.
|
* NULL and pos is 0xffff otherwise.
|
||||||
*/
|
*/
|
||||||
struct net_buf *net_pkt_write(struct net_pkt *pkt, struct net_buf *frag,
|
struct net_buf *net_pkt_write(struct net_pkt *pkt, struct net_buf *frag,
|
||||||
uint16_t offset, uint16_t *pos, uint16_t len,
|
u16_t offset, u16_t *pos, u16_t len,
|
||||||
uint8_t *data, int32_t timeout);
|
u8_t *data, s32_t timeout);
|
||||||
|
|
||||||
/* Write uint8_t data to an arbitrary offset in fragment. */
|
/* Write u8_t data to an arbitrary offset in fragment. */
|
||||||
static inline struct net_buf *net_pkt_write_u8(struct net_pkt *pkt,
|
static inline struct net_buf *net_pkt_write_u8(struct net_pkt *pkt,
|
||||||
struct net_buf *frag,
|
struct net_buf *frag,
|
||||||
uint16_t offset,
|
u16_t offset,
|
||||||
uint16_t *pos,
|
u16_t *pos,
|
||||||
uint8_t data)
|
u8_t data)
|
||||||
{
|
{
|
||||||
return net_pkt_write(pkt, frag, offset, pos, sizeof(uint8_t),
|
return net_pkt_write(pkt, frag, offset, pos, sizeof(u8_t),
|
||||||
&data, K_FOREVER);
|
&data, K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write uint16_t big endian value to an arbitrary offset in fragment. */
|
/* Write u16_t big endian value to an arbitrary offset in fragment. */
|
||||||
static inline struct net_buf *net_pkt_write_be16(struct net_pkt *pkt,
|
static inline struct net_buf *net_pkt_write_be16(struct net_pkt *pkt,
|
||||||
struct net_buf *frag,
|
struct net_buf *frag,
|
||||||
uint16_t offset,
|
u16_t offset,
|
||||||
uint16_t *pos,
|
u16_t *pos,
|
||||||
uint16_t data)
|
u16_t data)
|
||||||
{
|
{
|
||||||
uint16_t value = htons(data);
|
u16_t value = htons(data);
|
||||||
|
|
||||||
return net_pkt_write(pkt, frag, offset, pos, sizeof(uint16_t),
|
return net_pkt_write(pkt, frag, offset, pos, sizeof(u16_t),
|
||||||
(uint8_t *)&value, K_FOREVER);
|
(u8_t *)&value, K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write uint32_t big endian value to an arbitrary offset in fragment. */
|
/* Write u32_t big endian value to an arbitrary offset in fragment. */
|
||||||
static inline struct net_buf *net_pkt_write_be32(struct net_pkt *pkt,
|
static inline struct net_buf *net_pkt_write_be32(struct net_pkt *pkt,
|
||||||
struct net_buf *frag,
|
struct net_buf *frag,
|
||||||
uint16_t offset,
|
u16_t offset,
|
||||||
uint16_t *pos,
|
u16_t *pos,
|
||||||
uint32_t data)
|
u32_t data)
|
||||||
{
|
{
|
||||||
uint32_t value = htonl(data);
|
u32_t value = htonl(data);
|
||||||
|
|
||||||
return net_pkt_write(pkt, frag, offset, pos, sizeof(uint32_t),
|
return net_pkt_write(pkt, frag, offset, pos, sizeof(u32_t),
|
||||||
(uint8_t *)&value, K_FOREVER);
|
(u8_t *)&value, K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1183,45 +1183,45 @@ static inline struct net_buf *net_pkt_write_be32(struct net_pkt *pkt,
|
||||||
* @return True on success, False otherwise.
|
* @return True on success, False otherwise.
|
||||||
*/
|
*/
|
||||||
bool net_pkt_insert(struct net_pkt *pkt, struct net_buf *frag,
|
bool net_pkt_insert(struct net_pkt *pkt, struct net_buf *frag,
|
||||||
uint16_t offset, uint16_t len, uint8_t *data,
|
u16_t offset, u16_t len, u8_t *data,
|
||||||
int32_t timeout);
|
s32_t timeout);
|
||||||
|
|
||||||
/* Insert uint8_t data at an arbitrary offset in a series of fragments. */
|
/* Insert u8_t data at an arbitrary offset in a series of fragments. */
|
||||||
static inline bool net_pkt_insert_u8(struct net_pkt *pkt,
|
static inline bool net_pkt_insert_u8(struct net_pkt *pkt,
|
||||||
struct net_buf *frag,
|
struct net_buf *frag,
|
||||||
uint16_t offset,
|
u16_t offset,
|
||||||
uint8_t data)
|
u8_t data)
|
||||||
{
|
{
|
||||||
return net_pkt_insert(pkt, frag, offset, sizeof(uint8_t), &data,
|
return net_pkt_insert(pkt, frag, offset, sizeof(u8_t), &data,
|
||||||
K_FOREVER);
|
K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Insert uint16_t big endian value at an arbitrary offset in a series of
|
/* Insert u16_t big endian value at an arbitrary offset in a series of
|
||||||
* fragments.
|
* fragments.
|
||||||
*/
|
*/
|
||||||
static inline bool net_pkt_insert_be16(struct net_pkt *pkt,
|
static inline bool net_pkt_insert_be16(struct net_pkt *pkt,
|
||||||
struct net_buf *frag,
|
struct net_buf *frag,
|
||||||
uint16_t offset,
|
u16_t offset,
|
||||||
uint16_t data)
|
u16_t data)
|
||||||
{
|
{
|
||||||
uint16_t value = htons(data);
|
u16_t value = htons(data);
|
||||||
|
|
||||||
return net_pkt_insert(pkt, frag, offset, sizeof(uint16_t),
|
return net_pkt_insert(pkt, frag, offset, sizeof(u16_t),
|
||||||
(uint8_t *)&value, K_FOREVER);
|
(u8_t *)&value, K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Insert uint32_t big endian value at an arbitrary offset in a series of
|
/* Insert u32_t big endian value at an arbitrary offset in a series of
|
||||||
* fragments.
|
* fragments.
|
||||||
*/
|
*/
|
||||||
static inline bool net_pkt_insert_be32(struct net_pkt *pkt,
|
static inline bool net_pkt_insert_be32(struct net_pkt *pkt,
|
||||||
struct net_buf *frag,
|
struct net_buf *frag,
|
||||||
uint16_t offset,
|
u16_t offset,
|
||||||
uint32_t data)
|
u32_t data)
|
||||||
{
|
{
|
||||||
uint32_t value = htonl(data);
|
u32_t value = htonl(data);
|
||||||
|
|
||||||
return net_pkt_insert(pkt, frag, offset, sizeof(uint32_t),
|
return net_pkt_insert(pkt, frag, offset, sizeof(u32_t),
|
||||||
(uint8_t *)&value, K_FOREVER);
|
(u8_t *)&value, K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1250,8 +1250,8 @@ static inline bool net_pkt_insert_be32(struct net_pkt *pkt,
|
||||||
* @return 0 on success, <0 otherwise.
|
* @return 0 on success, <0 otherwise.
|
||||||
*/
|
*/
|
||||||
int net_pkt_split(struct net_pkt *pkt, struct net_buf *orig_frag,
|
int net_pkt_split(struct net_pkt *pkt, struct net_buf *orig_frag,
|
||||||
uint16_t len, struct net_buf **fragA,
|
u16_t len, struct net_buf **fragA,
|
||||||
struct net_buf **fragB, int32_t timeout);
|
struct net_buf **fragB, s32_t timeout);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get information about pre-defined RX, TX and DATA pools.
|
* @brief Get information about pre-defined RX, TX and DATA pools.
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef uint32_t net_stats_t;
|
typedef u32_t net_stats_t;
|
||||||
|
|
||||||
struct net_stats_ip {
|
struct net_stats_ip {
|
||||||
/** Number of received packets at the IP layer. */
|
/** Number of received packets at the IP layer. */
|
||||||
|
@ -179,16 +179,16 @@ struct net_stats_rpl_dao_ack {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct net_stats_rpl {
|
struct net_stats_rpl {
|
||||||
uint16_t mem_overflows;
|
u16_t mem_overflows;
|
||||||
uint16_t local_repairs;
|
u16_t local_repairs;
|
||||||
uint16_t global_repairs;
|
u16_t global_repairs;
|
||||||
uint16_t malformed_msgs;
|
u16_t malformed_msgs;
|
||||||
uint16_t resets;
|
u16_t resets;
|
||||||
uint16_t parent_switch;
|
u16_t parent_switch;
|
||||||
uint16_t forward_errors;
|
u16_t forward_errors;
|
||||||
uint16_t loop_errors;
|
u16_t loop_errors;
|
||||||
uint16_t loop_warnings;
|
u16_t loop_warnings;
|
||||||
uint16_t root_repairs;
|
u16_t root_repairs;
|
||||||
|
|
||||||
struct net_stats_rpl_dis dis;
|
struct net_stats_rpl_dis dis;
|
||||||
struct net_stats_rpl_dio dio;
|
struct net_stats_rpl_dio dio;
|
||||||
|
@ -208,8 +208,8 @@ struct net_stats_ipv6_mld {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct net_stats_bytes {
|
struct net_stats_bytes {
|
||||||
uint32_t sent;
|
u32_t sent;
|
||||||
uint32_t received;
|
u32_t received;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct net_stats {
|
struct net_stats {
|
||||||
|
|
|
@ -34,15 +34,15 @@ typedef void (*net_trickle_cb_t)(struct net_trickle *trickle,
|
||||||
* only via the Trickle API.
|
* only via the Trickle API.
|
||||||
*/
|
*/
|
||||||
struct net_trickle {
|
struct net_trickle {
|
||||||
uint32_t Imin; /* Min interval size in ms */
|
u32_t Imin; /* Min interval size in ms */
|
||||||
uint8_t Imax; /* Max number of doublings */
|
u8_t Imax; /* Max number of doublings */
|
||||||
uint8_t k; /* Redundancy constant */
|
u8_t k; /* Redundancy constant */
|
||||||
|
|
||||||
uint32_t I; /* Current interval size */
|
u32_t I; /* Current interval size */
|
||||||
uint32_t Istart; /* Start of the interval in ms */
|
u32_t Istart; /* Start of the interval in ms */
|
||||||
uint8_t c; /* Consistency counter */
|
u8_t c; /* Consistency counter */
|
||||||
|
|
||||||
uint32_t Imax_abs; /* Max interval size in ms (not doublings)
|
u32_t Imax_abs; /* Max interval size in ms (not doublings)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
struct k_delayed_work timer;
|
struct k_delayed_work timer;
|
||||||
|
@ -63,9 +63,9 @@ struct net_trickle {
|
||||||
* @return Return 0 if ok and <0 if error.
|
* @return Return 0 if ok and <0 if error.
|
||||||
*/
|
*/
|
||||||
int net_trickle_create(struct net_trickle *trickle,
|
int net_trickle_create(struct net_trickle *trickle,
|
||||||
uint32_t Imin,
|
u32_t Imin,
|
||||||
uint8_t Imax,
|
u8_t Imax,
|
||||||
uint8_t k);
|
u8_t k);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Start a Trickle timer.
|
* @brief Start a Trickle timer.
|
||||||
|
|
|
@ -185,8 +185,8 @@ struct zoap_resource {
|
||||||
struct zoap_observer {
|
struct zoap_observer {
|
||||||
sys_snode_t list;
|
sys_snode_t list;
|
||||||
struct sockaddr addr;
|
struct sockaddr addr;
|
||||||
uint8_t token[8];
|
u8_t token[8];
|
||||||
uint8_t tkl;
|
u8_t tkl;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -194,8 +194,8 @@ struct zoap_observer {
|
||||||
*/
|
*/
|
||||||
struct zoap_packet {
|
struct zoap_packet {
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
uint8_t *start; /* Start of the payload */
|
u8_t *start; /* Start of the payload */
|
||||||
uint16_t total_size;
|
u16_t total_size;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -213,8 +213,8 @@ typedef int (*zoap_reply_t)(const struct zoap_packet *response,
|
||||||
struct zoap_pending {
|
struct zoap_pending {
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct sockaddr addr;
|
struct sockaddr addr;
|
||||||
int32_t timeout;
|
s32_t timeout;
|
||||||
uint16_t id;
|
u16_t id;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -225,8 +225,8 @@ struct zoap_reply {
|
||||||
zoap_reply_t reply;
|
zoap_reply_t reply;
|
||||||
void *user_data;
|
void *user_data;
|
||||||
int age;
|
int age;
|
||||||
uint8_t token[8];
|
u8_t token[8];
|
||||||
uint8_t tkl;
|
u8_t tkl;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -304,8 +304,8 @@ void zoap_reply_init(struct zoap_reply *reply,
|
||||||
* To be used with zoap_find_options().
|
* To be used with zoap_find_options().
|
||||||
*/
|
*/
|
||||||
struct zoap_option {
|
struct zoap_option {
|
||||||
uint8_t *value;
|
u8_t *value;
|
||||||
uint16_t len;
|
u16_t len;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -492,7 +492,7 @@ bool zoap_request_is_observe(const struct zoap_packet *request);
|
||||||
*
|
*
|
||||||
* @return pointer to the start of the payload, NULL in case of error.
|
* @return pointer to the start of the payload, NULL in case of error.
|
||||||
*/
|
*/
|
||||||
uint8_t *zoap_packet_get_payload(struct zoap_packet *zpkt, uint16_t *len);
|
u8_t *zoap_packet_get_payload(struct zoap_packet *zpkt, u16_t *len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets how much space was used by the payload.
|
* @brief Sets how much space was used by the payload.
|
||||||
|
@ -506,7 +506,7 @@ uint8_t *zoap_packet_get_payload(struct zoap_packet *zpkt, uint16_t *len);
|
||||||
*
|
*
|
||||||
* @return 0 in case of success or negative in case of error.
|
* @return 0 in case of success or negative in case of error.
|
||||||
*/
|
*/
|
||||||
int zoap_packet_set_used(struct zoap_packet *zpkt, uint16_t len);
|
int zoap_packet_set_used(struct zoap_packet *zpkt, u16_t len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Adds an option to the packet.
|
* @brief Adds an option to the packet.
|
||||||
|
@ -520,8 +520,8 @@ int zoap_packet_set_used(struct zoap_packet *zpkt, uint16_t len);
|
||||||
*
|
*
|
||||||
* @return 0 in case of success or negative in case of error.
|
* @return 0 in case of success or negative in case of error.
|
||||||
*/
|
*/
|
||||||
int zoap_add_option(struct zoap_packet *zpkt, uint16_t code,
|
int zoap_add_option(struct zoap_packet *zpkt, u16_t code,
|
||||||
const void *value, uint16_t len);
|
const void *value, u16_t len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Converts an option to its integer representation.
|
* @brief Converts an option to its integer representation.
|
||||||
|
@ -548,7 +548,7 @@ unsigned int zoap_option_value_to_int(const struct zoap_option *option);
|
||||||
*
|
*
|
||||||
* @return 0 in case of success or negative in case of error.
|
* @return 0 in case of success or negative in case of error.
|
||||||
*/
|
*/
|
||||||
int zoap_add_option_int(struct zoap_packet *zpkt, uint16_t code,
|
int zoap_add_option_int(struct zoap_packet *zpkt, u16_t code,
|
||||||
unsigned int val);
|
unsigned int val);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -564,8 +564,8 @@ int zoap_add_option_int(struct zoap_packet *zpkt, uint16_t code,
|
||||||
* @return The number of options found in packet matching code,
|
* @return The number of options found in packet matching code,
|
||||||
* negative on error.
|
* negative on error.
|
||||||
*/
|
*/
|
||||||
int zoap_find_options(const struct zoap_packet *zpkt, uint16_t code,
|
int zoap_find_options(const struct zoap_packet *zpkt, u16_t code,
|
||||||
struct zoap_option *options, uint16_t veclen);
|
struct zoap_option *options, u16_t veclen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the size of each block that will be transferred using
|
* Represents the size of each block that will be transferred using
|
||||||
|
@ -593,7 +593,7 @@ enum zoap_block_size {
|
||||||
*
|
*
|
||||||
* @return The size in bytes that the block_size represents
|
* @return The size in bytes that the block_size represents
|
||||||
*/
|
*/
|
||||||
static inline uint16_t zoap_block_size_to_bytes(
|
static inline u16_t zoap_block_size_to_bytes(
|
||||||
enum zoap_block_size block_size)
|
enum zoap_block_size block_size)
|
||||||
{
|
{
|
||||||
return (1 << (block_size + 4));
|
return (1 << (block_size + 4));
|
||||||
|
@ -700,7 +700,7 @@ size_t zoap_next_block(struct zoap_block_context *ctx);
|
||||||
*
|
*
|
||||||
* @return the CoAP version in packet
|
* @return the CoAP version in packet
|
||||||
*/
|
*/
|
||||||
uint8_t zoap_header_get_version(const struct zoap_packet *zpkt);
|
u8_t zoap_header_get_version(const struct zoap_packet *zpkt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the type of the CoAP packet.
|
* @brief Returns the type of the CoAP packet.
|
||||||
|
@ -709,7 +709,7 @@ uint8_t zoap_header_get_version(const struct zoap_packet *zpkt);
|
||||||
*
|
*
|
||||||
* @return the type of the packet
|
* @return the type of the packet
|
||||||
*/
|
*/
|
||||||
uint8_t zoap_header_get_type(const struct zoap_packet *zpkt);
|
u8_t zoap_header_get_type(const struct zoap_packet *zpkt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the token (if any) in the CoAP packet.
|
* @brief Returns the token (if any) in the CoAP packet.
|
||||||
|
@ -719,8 +719,8 @@ uint8_t zoap_header_get_type(const struct zoap_packet *zpkt);
|
||||||
*
|
*
|
||||||
* @return pointer to the start of the token in the CoAP packet.
|
* @return pointer to the start of the token in the CoAP packet.
|
||||||
*/
|
*/
|
||||||
const uint8_t *zoap_header_get_token(const struct zoap_packet *zpkt,
|
const u8_t *zoap_header_get_token(const struct zoap_packet *zpkt,
|
||||||
uint8_t *len);
|
u8_t *len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the code of the CoAP packet.
|
* @brief Returns the code of the CoAP packet.
|
||||||
|
@ -729,7 +729,7 @@ const uint8_t *zoap_header_get_token(const struct zoap_packet *zpkt,
|
||||||
*
|
*
|
||||||
* @return the code present in the packet
|
* @return the code present in the packet
|
||||||
*/
|
*/
|
||||||
uint8_t zoap_header_get_code(const struct zoap_packet *zpkt);
|
u8_t zoap_header_get_code(const struct zoap_packet *zpkt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Returns the message id associated with the CoAP packet.
|
* @brief Returns the message id associated with the CoAP packet.
|
||||||
|
@ -738,7 +738,7 @@ uint8_t zoap_header_get_code(const struct zoap_packet *zpkt);
|
||||||
*
|
*
|
||||||
* @return the message id present in the packet
|
* @return the message id present in the packet
|
||||||
*/
|
*/
|
||||||
uint16_t zoap_header_get_id(const struct zoap_packet *zpkt);
|
u16_t zoap_header_get_id(const struct zoap_packet *zpkt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the version of the CoAP packet.
|
* @brief Sets the version of the CoAP packet.
|
||||||
|
@ -746,7 +746,7 @@ uint16_t zoap_header_get_id(const struct zoap_packet *zpkt);
|
||||||
* @param zpkt CoAP packet representation
|
* @param zpkt CoAP packet representation
|
||||||
* @param ver The CoAP version to set in the packet
|
* @param ver The CoAP version to set in the packet
|
||||||
*/
|
*/
|
||||||
void zoap_header_set_version(struct zoap_packet *zpkt, uint8_t ver);
|
void zoap_header_set_version(struct zoap_packet *zpkt, u8_t ver);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the type of the CoAP packet.
|
* @brief Sets the type of the CoAP packet.
|
||||||
|
@ -754,7 +754,7 @@ void zoap_header_set_version(struct zoap_packet *zpkt, uint8_t ver);
|
||||||
* @param zpkt CoAP packet representation
|
* @param zpkt CoAP packet representation
|
||||||
* @param type The packet type to set
|
* @param type The packet type to set
|
||||||
*/
|
*/
|
||||||
void zoap_header_set_type(struct zoap_packet *zpkt, uint8_t type);
|
void zoap_header_set_type(struct zoap_packet *zpkt, u8_t type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the token in the CoAP packet.
|
* @brief Sets the token in the CoAP packet.
|
||||||
|
@ -765,8 +765,8 @@ void zoap_header_set_type(struct zoap_packet *zpkt, uint8_t type);
|
||||||
*
|
*
|
||||||
* @return 0 in case of success or negative in case of error.
|
* @return 0 in case of success or negative in case of error.
|
||||||
*/
|
*/
|
||||||
int zoap_header_set_token(struct zoap_packet *zpkt, const uint8_t *token,
|
int zoap_header_set_token(struct zoap_packet *zpkt, const u8_t *token,
|
||||||
uint8_t tokenlen);
|
u8_t tokenlen);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the code present in the CoAP packet.
|
* @brief Sets the code present in the CoAP packet.
|
||||||
|
@ -774,7 +774,7 @@ int zoap_header_set_token(struct zoap_packet *zpkt, const uint8_t *token,
|
||||||
* @param zpkt CoAP packet representation
|
* @param zpkt CoAP packet representation
|
||||||
* @param code The code set in the packet
|
* @param code The code set in the packet
|
||||||
*/
|
*/
|
||||||
void zoap_header_set_code(struct zoap_packet *zpkt, uint8_t code);
|
void zoap_header_set_code(struct zoap_packet *zpkt, u8_t code);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Sets the message id present in the CoAP packet.
|
* @brief Sets the message id present in the CoAP packet.
|
||||||
|
@ -782,16 +782,16 @@ void zoap_header_set_code(struct zoap_packet *zpkt, uint8_t code);
|
||||||
* @param zpkt CoAP packet representation
|
* @param zpkt CoAP packet representation
|
||||||
* @param id The message id to set in the packet
|
* @param id The message id to set in the packet
|
||||||
*/
|
*/
|
||||||
void zoap_header_set_id(struct zoap_packet *zpkt, uint16_t id);
|
void zoap_header_set_id(struct zoap_packet *zpkt, u16_t id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Helper to generate message ids
|
* @brief Helper to generate message ids
|
||||||
*
|
*
|
||||||
* @return a new message id
|
* @return a new message id
|
||||||
*/
|
*/
|
||||||
static inline uint16_t zoap_next_id(void)
|
static inline u16_t zoap_next_id(void)
|
||||||
{
|
{
|
||||||
static uint16_t message_id;
|
static u16_t message_id;
|
||||||
|
|
||||||
return ++message_id;
|
return ++message_id;
|
||||||
}
|
}
|
||||||
|
@ -802,7 +802,7 @@ static inline uint16_t zoap_next_id(void)
|
||||||
*
|
*
|
||||||
* @return a 8-byte pseudo-random token.
|
* @return a 8-byte pseudo-random token.
|
||||||
*/
|
*/
|
||||||
uint8_t *zoap_next_token(void);
|
u8_t *zoap_next_token(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
|
|
|
@ -78,12 +78,12 @@ static const char *const test_path[] = { "test", NULL };
|
||||||
static struct in6_addr mcast_addr = MCAST_IP_ADDR;
|
static struct in6_addr mcast_addr = MCAST_IP_ADDR;
|
||||||
|
|
||||||
struct dtls_timing_context {
|
struct dtls_timing_context {
|
||||||
uint32_t snapshot;
|
u32_t snapshot;
|
||||||
uint32_t int_ms;
|
u32_t int_ms;
|
||||||
uint32_t fin_ms;
|
u32_t fin_ms;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void msg_dump(const char *s, uint8_t *data, unsigned int len)
|
static void msg_dump(const char *s, u8_t *data, unsigned int len)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
|
@ -125,7 +125,7 @@ static void my_debug(void *ctx, int level,
|
||||||
mbedtls_printf("%s:%04d: |%d| %s", basename, line, level, str);
|
mbedtls_printf("%s:%04d: |%d| %s", basename, line, level, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dtls_timing_set_delay(void *data, uint32_t int_ms, uint32_t fin_ms)
|
void dtls_timing_set_delay(void *data, u32_t int_ms, u32_t fin_ms)
|
||||||
{
|
{
|
||||||
struct dtls_timing_context *ctx = (struct dtls_timing_context *)data;
|
struct dtls_timing_context *ctx = (struct dtls_timing_context *)data;
|
||||||
|
|
||||||
|
@ -162,7 +162,7 @@ int dtls_timing_get_delay(void *data)
|
||||||
static int entropy_source(void *data, unsigned char *output, size_t len,
|
static int entropy_source(void *data, unsigned char *output, size_t len,
|
||||||
size_t *olen)
|
size_t *olen)
|
||||||
{
|
{
|
||||||
uint32_t seed;
|
u32_t seed;
|
||||||
|
|
||||||
ARG_UNUSED(data);
|
ARG_UNUSED(data);
|
||||||
|
|
||||||
|
@ -188,9 +188,9 @@ void dtls_client(void)
|
||||||
struct zoap_reply *reply;
|
struct zoap_reply *reply;
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
uint8_t observe = 0;
|
u8_t observe = 0;
|
||||||
const char *const *p;
|
const char *const *p;
|
||||||
uint16_t len;
|
u16_t len;
|
||||||
|
|
||||||
mbedtls_entropy_context entropy;
|
mbedtls_entropy_context entropy;
|
||||||
mbedtls_ctr_drbg_context ctr_drbg;
|
mbedtls_ctr_drbg_context ctr_drbg;
|
||||||
|
@ -411,7 +411,7 @@ exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
#define STACK_SIZE 4096
|
#define STACK_SIZE 4096
|
||||||
uint8_t stack[STACK_SIZE];
|
u8_t stack[STACK_SIZE];
|
||||||
|
|
||||||
static inline int init_app(void)
|
static inline int init_app(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -63,7 +63,7 @@ int udp_tx(void *context, const unsigned char *buf, size_t size)
|
||||||
return MBEDTLS_ERR_SSL_ALLOC_FAILED;
|
return MBEDTLS_ERR_SSL_ALLOC_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = net_pkt_append(send_pkt, size, (uint8_t *) buf, K_FOREVER);
|
rc = net_pkt_append(send_pkt, size, (u8_t *) buf, K_FOREVER);
|
||||||
if (!rc) {
|
if (!rc) {
|
||||||
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
|
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -82,12 +82,12 @@ int udp_tx(void *context, const unsigned char *buf, size_t size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int udp_rx(void *context, unsigned char *buf, size_t size, uint32_t timeout)
|
int udp_rx(void *context, unsigned char *buf, size_t size, u32_t timeout)
|
||||||
{
|
{
|
||||||
struct udp_context *ctx = context;
|
struct udp_context *ctx = context;
|
||||||
struct net_buf *rx_buf = NULL;
|
struct net_buf *rx_buf = NULL;
|
||||||
uint16_t read_bytes;
|
u16_t read_bytes;
|
||||||
uint8_t *ptr;
|
u8_t *ptr;
|
||||||
int pos;
|
int pos;
|
||||||
int len;
|
int len;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
|
@ -18,6 +18,6 @@ struct udp_context {
|
||||||
|
|
||||||
int udp_init(struct udp_context *ctx);
|
int udp_init(struct udp_context *ctx);
|
||||||
int udp_tx(void *ctx, const unsigned char *buf, size_t size);
|
int udp_tx(void *ctx, const unsigned char *buf, size_t size);
|
||||||
int udp_rx(void *ctx, unsigned char *buf, size_t size, uint32_t timeout);
|
int udp_rx(void *ctx, unsigned char *buf, size_t size, u32_t timeout);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -76,13 +76,13 @@ const char psk_id[] = "Client_identity\0";
|
||||||
|
|
||||||
static mbedtls_ssl_context *curr_ctx;
|
static mbedtls_ssl_context *curr_ctx;
|
||||||
|
|
||||||
static int send_response(struct zoap_packet *request, uint8_t response_code)
|
static int send_response(struct zoap_packet *request, u8_t response_code)
|
||||||
{
|
{
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
uint8_t code, type;
|
u8_t code, type;
|
||||||
uint16_t id;
|
u16_t id;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
code = zoap_header_get_code(request);
|
code = zoap_header_get_code(request);
|
||||||
|
@ -154,8 +154,8 @@ static int piggyback_get(struct zoap_resource *resource,
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
uint8_t *payload, code, type;
|
u8_t *payload, code, type;
|
||||||
uint16_t len, id;
|
u16_t len, id;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
code = zoap_header_get_code(request);
|
code = zoap_header_get_code(request);
|
||||||
|
@ -226,8 +226,8 @@ static int query_get(struct zoap_resource *resource,
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
uint8_t *payload, code, type;
|
u8_t *payload, code, type;
|
||||||
uint16_t len, id;
|
u16_t len, id;
|
||||||
int i, r;
|
int i, r;
|
||||||
|
|
||||||
code = zoap_header_get_code(request);
|
code = zoap_header_get_code(request);
|
||||||
|
@ -337,9 +337,9 @@ static struct zoap_resource resources[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct dtls_timing_context {
|
struct dtls_timing_context {
|
||||||
uint32_t snapshot;
|
u32_t snapshot;
|
||||||
uint32_t int_ms;
|
u32_t int_ms;
|
||||||
uint32_t fin_ms;
|
u32_t fin_ms;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void my_debug(void *ctx, int level,
|
static void my_debug(void *ctx, int level,
|
||||||
|
@ -360,7 +360,7 @@ static void my_debug(void *ctx, int level,
|
||||||
mbedtls_printf("%s:%04d: |%d| %s", basename, line, level, str);
|
mbedtls_printf("%s:%04d: |%d| %s", basename, line, level, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dtls_timing_set_delay(void *data, uint32_t int_ms, uint32_t fin_ms)
|
void dtls_timing_set_delay(void *data, u32_t int_ms, u32_t fin_ms)
|
||||||
{
|
{
|
||||||
struct dtls_timing_context *ctx = (struct dtls_timing_context *)data;
|
struct dtls_timing_context *ctx = (struct dtls_timing_context *)data;
|
||||||
|
|
||||||
|
@ -397,7 +397,7 @@ int dtls_timing_get_delay(void *data)
|
||||||
static int entropy_source(void *data, unsigned char *output, size_t len,
|
static int entropy_source(void *data, unsigned char *output, size_t len,
|
||||||
size_t *olen)
|
size_t *olen)
|
||||||
{
|
{
|
||||||
uint32_t seed;
|
u32_t seed;
|
||||||
|
|
||||||
ARG_UNUSED(data);
|
ARG_UNUSED(data);
|
||||||
|
|
||||||
|
@ -632,7 +632,7 @@ exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
#define STACK_SIZE 4096
|
#define STACK_SIZE 4096
|
||||||
uint8_t stack[STACK_SIZE];
|
u8_t stack[STACK_SIZE];
|
||||||
|
|
||||||
static inline int init_app(void)
|
static inline int init_app(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -53,7 +53,7 @@ int udp_tx(void *context, const unsigned char *buf, size_t size)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = net_pkt_append(send_pkt, size, (uint8_t *) buf, K_FOREVER);
|
rc = net_pkt_append(send_pkt, size, (u8_t *) buf, K_FOREVER);
|
||||||
if (!rc) {
|
if (!rc) {
|
||||||
printk("cannot write buf\n");
|
printk("cannot write buf\n");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
@ -79,8 +79,8 @@ int udp_rx(void *context, unsigned char *buf, size_t size)
|
||||||
struct net_context *net_ctx = ctx->net_ctx;
|
struct net_context *net_ctx = ctx->net_ctx;
|
||||||
struct net_pkt *rx_pkt = NULL;
|
struct net_pkt *rx_pkt = NULL;
|
||||||
struct net_buf *rx_buf;
|
struct net_buf *rx_buf;
|
||||||
uint16_t read_bytes;
|
u16_t read_bytes;
|
||||||
uint8_t *ptr;
|
u8_t *ptr;
|
||||||
int pos;
|
int pos;
|
||||||
int len;
|
int len;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
|
|
||||||
int ieee802154_sample_setup(void)
|
int ieee802154_sample_setup(void)
|
||||||
{
|
{
|
||||||
uint16_t channel = CONFIG_NET_APP_IEEE802154_CHANNEL;
|
u16_t channel = CONFIG_NET_APP_IEEE802154_CHANNEL;
|
||||||
uint16_t pan_id = CONFIG_NET_APP_IEEE802154_PAN_ID;
|
u16_t pan_id = CONFIG_NET_APP_IEEE802154_PAN_ID;
|
||||||
int16_t tx_power = CONFIG_NET_APP_IEEE802154_RADIO_TX_POWER;
|
s16_t tx_power = CONFIG_NET_APP_IEEE802154_RADIO_TX_POWER;
|
||||||
|
|
||||||
#ifdef CONFIG_NET_L2_IEEE802154_SECURITY
|
#ifdef CONFIG_NET_L2_IEEE802154_SECURITY
|
||||||
struct ieee802154_security_params sec_params = {
|
struct ieee802154_security_params sec_params = {
|
||||||
|
@ -43,11 +43,11 @@ int ieee802154_sample_setup(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_mgmt(NET_REQUEST_IEEE802154_SET_PAN_ID,
|
if (net_mgmt(NET_REQUEST_IEEE802154_SET_PAN_ID,
|
||||||
iface, &pan_id, sizeof(uint16_t)) ||
|
iface, &pan_id, sizeof(u16_t)) ||
|
||||||
net_mgmt(NET_REQUEST_IEEE802154_SET_CHANNEL,
|
net_mgmt(NET_REQUEST_IEEE802154_SET_CHANNEL,
|
||||||
iface, &channel, sizeof(uint16_t)) ||
|
iface, &channel, sizeof(u16_t)) ||
|
||||||
net_mgmt(NET_REQUEST_IEEE802154_SET_TX_POWER,
|
net_mgmt(NET_REQUEST_IEEE802154_SET_TX_POWER,
|
||||||
iface, &tx_power, sizeof(int16_t))) {
|
iface, &tx_power, sizeof(s16_t))) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ char __noinit __stack thread_stack[STACKSIZE];
|
||||||
static struct net_mgmt_event_callback mgmt_cb;
|
static struct net_mgmt_event_callback mgmt_cb;
|
||||||
|
|
||||||
static void handler(struct net_mgmt_event_callback *cb,
|
static void handler(struct net_mgmt_event_callback *cb,
|
||||||
uint32_t mgmt_event,
|
u32_t mgmt_event,
|
||||||
struct net_if *iface)
|
struct net_if *iface)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
|
@ -79,7 +79,7 @@ static struct k_delayed_work ipv4_timer;
|
||||||
|
|
||||||
static void do_ipv4_lookup(struct k_work *work)
|
static void do_ipv4_lookup(struct k_work *work)
|
||||||
{
|
{
|
||||||
uint16_t dns_id;
|
u16_t dns_id;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = dns_get_addr_info("www.zephyrproject.org",
|
ret = dns_get_addr_info("www.zephyrproject.org",
|
||||||
|
@ -97,7 +97,7 @@ static void do_ipv4_lookup(struct k_work *work)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
|
static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
|
||||||
uint32_t mgmt_event,
|
u32_t mgmt_event,
|
||||||
struct net_if *iface)
|
struct net_if *iface)
|
||||||
{
|
{
|
||||||
char hr_addr[NET_IPV4_ADDR_LEN];
|
char hr_addr[NET_IPV4_ADDR_LEN];
|
||||||
|
@ -160,7 +160,7 @@ static void setup_ipv4(struct net_if *iface)
|
||||||
{
|
{
|
||||||
char hr_addr[NET_IPV4_ADDR_LEN];
|
char hr_addr[NET_IPV4_ADDR_LEN];
|
||||||
struct in_addr addr;
|
struct in_addr addr;
|
||||||
uint16_t dns_id;
|
u16_t dns_id;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (net_addr_pton(AF_INET, CONFIG_NET_APP_MY_IPV4_ADDR, &addr)) {
|
if (net_addr_pton(AF_INET, CONFIG_NET_APP_MY_IPV4_ADDR, &addr)) {
|
||||||
|
@ -202,7 +202,7 @@ static struct k_delayed_work ipv6_timer;
|
||||||
|
|
||||||
static void do_ipv6_lookup(struct k_work *work)
|
static void do_ipv6_lookup(struct k_work *work)
|
||||||
{
|
{
|
||||||
uint16_t dns_id;
|
u16_t dns_id;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = dns_get_addr_info("www.zephyrproject.org",
|
ret = dns_get_addr_info("www.zephyrproject.org",
|
||||||
|
@ -224,7 +224,7 @@ static void do_ipv6_lookup(struct k_work *work)
|
||||||
* network. So wait for that before continuing.
|
* network. So wait for that before continuing.
|
||||||
*/
|
*/
|
||||||
static void ipv6_router_add_handler(struct net_mgmt_event_callback *cb,
|
static void ipv6_router_add_handler(struct net_mgmt_event_callback *cb,
|
||||||
uint32_t mgmt_event,
|
u32_t mgmt_event,
|
||||||
struct net_if *iface)
|
struct net_if *iface)
|
||||||
{
|
{
|
||||||
if (mgmt_event != NET_EVENT_IPV6_ROUTER_ADD) {
|
if (mgmt_event != NET_EVENT_IPV6_ROUTER_ADD) {
|
||||||
|
|
|
@ -111,9 +111,9 @@ static struct net_buf_pool *data_udp_pool(void)
|
||||||
#define PEER_PORT 4242
|
#define PEER_PORT 4242
|
||||||
|
|
||||||
struct data {
|
struct data {
|
||||||
uint32_t expecting_udp;
|
u32_t expecting_udp;
|
||||||
uint32_t expecting_tcp;
|
u32_t expecting_tcp;
|
||||||
uint32_t received_tcp;
|
u32_t received_tcp;
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
|
@ -455,7 +455,7 @@ static inline void set_dst_addr(sa_family_t family,
|
||||||
#if defined(CONFIG_NET_UDP)
|
#if defined(CONFIG_NET_UDP)
|
||||||
static bool compare_udp_data(struct net_pkt *pkt, int expecting_len)
|
static bool compare_udp_data(struct net_pkt *pkt, int expecting_len)
|
||||||
{
|
{
|
||||||
uint8_t *ptr = net_pkt_appdata(pkt);
|
u8_t *ptr = net_pkt_appdata(pkt);
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
int len;
|
int len;
|
||||||
|
@ -617,7 +617,7 @@ static void send_udp(struct net_context *udp,
|
||||||
static bool compare_tcp_data(struct net_pkt *pkt, int expecting_len,
|
static bool compare_tcp_data(struct net_pkt *pkt, int expecting_len,
|
||||||
int received_len)
|
int received_len)
|
||||||
{
|
{
|
||||||
uint8_t *ptr = net_pkt_appdata(pkt), *start;
|
u8_t *ptr = net_pkt_appdata(pkt), *start;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
int len;
|
int len;
|
||||||
|
@ -714,7 +714,7 @@ static void tcp_sent(struct net_context *context,
|
||||||
void *token,
|
void *token,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
uint32_t len = POINTER_TO_UINT(token);
|
u32_t len = POINTER_TO_UINT(token);
|
||||||
|
|
||||||
if (len) {
|
if (len) {
|
||||||
if (status) {
|
if (status) {
|
||||||
|
@ -854,7 +854,7 @@ static void send_tcp_ipv6(struct net_context *tcp)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void event_iface_up(struct net_mgmt_event_callback *cb,
|
static void event_iface_up(struct net_mgmt_event_callback *cb,
|
||||||
uint32_t mgmt_event, struct net_if *iface)
|
u32_t mgmt_event, struct net_if *iface)
|
||||||
{
|
{
|
||||||
struct net_context *udp_send4 = { 0 };
|
struct net_context *udp_send4 = { 0 };
|
||||||
struct net_context *udp_send6 = { 0 };
|
struct net_context *udp_send6 = { 0 };
|
||||||
|
|
|
@ -24,7 +24,7 @@ int on_url(struct http_parser *parser, const char *at, size_t length)
|
||||||
int on_status(struct http_parser *parser, const char *at, size_t length)
|
int on_status(struct http_parser *parser, const char *at, size_t length)
|
||||||
{
|
{
|
||||||
struct http_client_ctx *ctx;
|
struct http_client_ctx *ctx;
|
||||||
uint16_t len;
|
u16_t len;
|
||||||
|
|
||||||
ARG_UNUSED(parser);
|
ARG_UNUSED(parser);
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ int on_header_field(struct http_parser *parser, const char *at, size_t length)
|
||||||
{
|
{
|
||||||
char *content_len = "Content-Length";
|
char *content_len = "Content-Length";
|
||||||
struct http_client_ctx *ctx;
|
struct http_client_ctx *ctx;
|
||||||
uint16_t len;
|
u16_t len;
|
||||||
|
|
||||||
ctx = CONTAINER_OF(parser, struct http_client_ctx, parser);
|
ctx = CONTAINER_OF(parser, struct http_client_ctx, parser);
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,8 @@ void http_receive_cb(struct tcp_client_ctx *tcp_ctx, struct net_pkt *rx)
|
||||||
{
|
{
|
||||||
struct http_client_ctx *http_ctx;
|
struct http_client_ctx *http_ctx;
|
||||||
struct net_buf *data_buf = NULL;
|
struct net_buf *data_buf = NULL;
|
||||||
uint16_t data_len;
|
u16_t data_len;
|
||||||
uint16_t offset;
|
u16_t offset;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (!rx) {
|
if (!rx) {
|
||||||
|
@ -59,7 +59,7 @@ void http_receive_cb(struct tcp_client_ctx *tcp_ctx, struct net_pkt *rx)
|
||||||
{
|
{
|
||||||
struct http_client_ctx *http_ctx;
|
struct http_client_ctx *http_ctx;
|
||||||
struct net_buf *frag = rx->frags;
|
struct net_buf *frag = rx->frags;
|
||||||
uint16_t offset;
|
u16_t offset;
|
||||||
|
|
||||||
if (!rx) {
|
if (!rx) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -17,8 +17,8 @@ struct http_client_ctx {
|
||||||
|
|
||||||
struct tcp_client_ctx tcp_ctx;
|
struct tcp_client_ctx tcp_ctx;
|
||||||
|
|
||||||
uint32_t content_length;
|
u32_t content_length;
|
||||||
uint32_t processed;
|
u32_t processed;
|
||||||
|
|
||||||
/* https://tools.ietf.org/html/rfc7230#section-3.1.2
|
/* https://tools.ietf.org/html/rfc7230#section-3.1.2
|
||||||
* The status-code element is a 3-digit integer code
|
* The status-code element is a 3-digit integer code
|
||||||
|
@ -30,8 +30,8 @@ struct http_client_ctx {
|
||||||
*/
|
*/
|
||||||
char http_status[HTTP_STATUS_STR_SIZE];
|
char http_status[HTTP_STATUS_STR_SIZE];
|
||||||
|
|
||||||
uint8_t cl_present:1;
|
u8_t cl_present:1;
|
||||||
uint8_t body_found:1;
|
u8_t body_found:1;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -70,7 +70,7 @@ static void send_http_method(enum http_method method, char *url,
|
||||||
char *content_type, char *payload)
|
char *content_type, char *payload)
|
||||||
{
|
{
|
||||||
struct net_context *net_ctx;
|
struct net_context *net_ctx;
|
||||||
int32_t timeout;
|
s32_t timeout;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
print_banner(method);
|
print_banner(method);
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
#include <misc/printk.h>
|
#include <misc/printk.h>
|
||||||
|
|
||||||
static
|
static
|
||||||
int set_addr(struct sockaddr *sock_addr, const char *addr, uint16_t server_port)
|
int set_addr(struct sockaddr *sock_addr, const char *addr, u16_t server_port)
|
||||||
{
|
{
|
||||||
void *ptr = NULL;
|
void *ptr = NULL;
|
||||||
int rc;
|
int rc;
|
||||||
|
@ -104,7 +104,7 @@ lb_exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
int tcp_connect(struct tcp_client_ctx *ctx, const char *server_addr,
|
int tcp_connect(struct tcp_client_ctx *ctx, const char *server_addr,
|
||||||
uint16_t server_port)
|
u16_t server_port)
|
||||||
{
|
{
|
||||||
#if CONFIG_NET_IPV6
|
#if CONFIG_NET_IPV6
|
||||||
socklen_t addr_len = sizeof(struct sockaddr_in6);
|
socklen_t addr_len = sizeof(struct sockaddr_in6);
|
||||||
|
|
|
@ -16,7 +16,7 @@ struct tcp_client_ctx {
|
||||||
/* Local sock address */
|
/* Local sock address */
|
||||||
struct sockaddr local_sock;
|
struct sockaddr local_sock;
|
||||||
/* Network timeout */
|
/* Network timeout */
|
||||||
int32_t timeout;
|
s32_t timeout;
|
||||||
/* User defined call back*/
|
/* User defined call back*/
|
||||||
void (*receive_cb)(struct tcp_client_ctx *ctx, struct net_pkt *rx);
|
void (*receive_cb)(struct tcp_client_ctx *ctx, struct net_pkt *rx);
|
||||||
};
|
};
|
||||||
|
@ -24,7 +24,7 @@ struct tcp_client_ctx {
|
||||||
int tcp_set_local_addr(struct tcp_client_ctx *ctx, const char *local_addr);
|
int tcp_set_local_addr(struct tcp_client_ctx *ctx, const char *local_addr);
|
||||||
|
|
||||||
int tcp_connect(struct tcp_client_ctx *ctx, const char *server_addr,
|
int tcp_connect(struct tcp_client_ctx *ctx, const char *server_addr,
|
||||||
uint16_t server_port);
|
u16_t server_port);
|
||||||
|
|
||||||
int tcp_disconnect(struct tcp_client_ctx *ctx);
|
int tcp_disconnect(struct tcp_client_ctx *ctx);
|
||||||
|
|
||||||
|
|
|
@ -77,8 +77,8 @@ int parser_parse_request(struct http_server_ctx *ctx, struct net_buf *rx);
|
||||||
|
|
||||||
static struct http_root_url *http_url_find(struct http_server_ctx *http_ctx);
|
static struct http_root_url *http_url_find(struct http_server_ctx *http_ctx);
|
||||||
|
|
||||||
static int http_url_cmp(const char *url, uint16_t url_len,
|
static int http_url_cmp(const char *url, u16_t url_len,
|
||||||
const char *root_url, uint16_t root_url_len);
|
const char *root_url, u16_t root_url_len);
|
||||||
|
|
||||||
static void http_tx(struct http_server_ctx *http_ctx);
|
static void http_tx(struct http_server_ctx *http_ctx);
|
||||||
|
|
||||||
|
@ -87,8 +87,8 @@ void http_rx_tx(struct net_context *net_ctx, struct net_pkt *rx, int status,
|
||||||
{
|
{
|
||||||
struct http_server_ctx *http_ctx = NULL;
|
struct http_server_ctx *http_ctx = NULL;
|
||||||
struct net_buf *data = NULL;
|
struct net_buf *data = NULL;
|
||||||
uint16_t rcv_len;
|
u16_t rcv_len;
|
||||||
uint16_t offset;
|
u16_t offset;
|
||||||
int parsed_len;
|
int parsed_len;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -342,7 +342,7 @@ int http_url_default_handler(int (*write_cb)(struct http_server_ctx *))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int http_url_add(const char *url, uint8_t flags,
|
int http_url_add(const char *url, u8_t flags,
|
||||||
int (*write_cb)(struct http_server_ctx *http_ctx))
|
int (*write_cb)(struct http_server_ctx *http_ctx))
|
||||||
{
|
{
|
||||||
struct http_root_url *root = NULL;
|
struct http_root_url *root = NULL;
|
||||||
|
@ -364,8 +364,8 @@ int http_url_add(const char *url, uint8_t flags,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int http_url_cmp(const char *url, uint16_t url_len,
|
static int http_url_cmp(const char *url, u16_t url_len,
|
||||||
const char *root_url, uint16_t root_url_len)
|
const char *root_url, u16_t root_url_len)
|
||||||
{
|
{
|
||||||
if (url_len < root_url_len) {
|
if (url_len < root_url_len) {
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -397,10 +397,10 @@ static int http_url_cmp(const char *url, uint16_t url_len,
|
||||||
|
|
||||||
static struct http_root_url *http_url_find(struct http_server_ctx *http_ctx)
|
static struct http_root_url *http_url_find(struct http_server_ctx *http_ctx)
|
||||||
{
|
{
|
||||||
uint16_t url_len = http_ctx->url_len;
|
u16_t url_len = http_ctx->url_len;
|
||||||
const char *url = http_ctx->url;
|
const char *url = http_ctx->url;
|
||||||
struct http_root_url *root_url;
|
struct http_root_url *root_url;
|
||||||
uint8_t i;
|
u8_t i;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* at some point we must come up with something better */
|
/* at some point we must come up with something better */
|
||||||
|
|
|
@ -49,7 +49,7 @@ int http_ctx_set(struct http_server_ctx *http_ctx, struct net_context *net_ctx);
|
||||||
|
|
||||||
int http_url_default_handler(int (*write_cb)(struct http_server_ctx *));
|
int http_url_default_handler(int (*write_cb)(struct http_server_ctx *));
|
||||||
|
|
||||||
int http_url_add(const char *url, uint8_t flags,
|
int http_url_add(const char *url, u8_t flags,
|
||||||
int (*write_cb)(struct http_server_ctx *http_ctx));
|
int (*write_cb)(struct http_server_ctx *http_ctx));
|
||||||
|
|
||||||
int http_auth(struct http_server_ctx *ctx);
|
int http_auth(struct http_server_ctx *ctx);
|
||||||
|
|
|
@ -28,9 +28,9 @@ enum HTTP_URL_FLAGS {
|
||||||
*/
|
*/
|
||||||
struct http_root_url {
|
struct http_root_url {
|
||||||
const char *root;
|
const char *root;
|
||||||
uint16_t root_len;
|
u16_t root_len;
|
||||||
|
|
||||||
uint8_t flags;
|
u8_t flags;
|
||||||
int (*write_cb)(struct http_server_ctx *http_ctx);
|
int (*write_cb)(struct http_server_ctx *http_ctx);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ struct http_root_url {
|
||||||
*/
|
*/
|
||||||
struct http_url_ctx {
|
struct http_url_ctx {
|
||||||
struct http_root_url urls[HTTP_MAX_NUMBER_URL];
|
struct http_root_url urls[HTTP_MAX_NUMBER_URL];
|
||||||
uint8_t urls_ctr;
|
u8_t urls_ctr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,13 +21,13 @@ void print_ipaddr(const struct sockaddr *ip_addr)
|
||||||
#ifdef CONFIG_NET_IPV6
|
#ifdef CONFIG_NET_IPV6
|
||||||
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)ip_addr;
|
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)ip_addr;
|
||||||
void *raw = (void *)&addr->sin6_addr;
|
void *raw = (void *)&addr->sin6_addr;
|
||||||
uint16_t port = addr->sin6_port;
|
u16_t port = addr->sin6_port;
|
||||||
sa_family_t family = AF_INET6;
|
sa_family_t family = AF_INET6;
|
||||||
char str[STR_IP6_ADDR];
|
char str[STR_IP6_ADDR];
|
||||||
#else
|
#else
|
||||||
struct sockaddr_in *addr = (struct sockaddr_in *)ip_addr;
|
struct sockaddr_in *addr = (struct sockaddr_in *)ip_addr;
|
||||||
void *raw = (void *)&addr->sin_addr;
|
void *raw = (void *)&addr->sin_addr;
|
||||||
uint16_t port = addr->sin_port;
|
u16_t port = addr->sin_port;
|
||||||
sa_family_t family = AF_INET;
|
sa_family_t family = AF_INET;
|
||||||
char str[STR_IP4_ADDR];
|
char str[STR_IP4_ADDR];
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -29,10 +29,10 @@
|
||||||
|
|
||||||
/* Prints the received HTTP header fields as an HTML list */
|
/* Prints the received HTTP header fields as an HTML list */
|
||||||
static void print_http_headers(struct http_server_ctx *ctx,
|
static void print_http_headers(struct http_server_ctx *ctx,
|
||||||
char *str, uint16_t size)
|
char *str, u16_t size)
|
||||||
{
|
{
|
||||||
struct http_parser *parser = &ctx->parser;
|
struct http_parser *parser = &ctx->parser;
|
||||||
uint16_t offset = 0;
|
u16_t offset = 0;
|
||||||
|
|
||||||
offset = snprintf(str, size,
|
offset = snprintf(str, size,
|
||||||
HTML_HEADER
|
HTML_HEADER
|
||||||
|
@ -41,7 +41,7 @@ static void print_http_headers(struct http_server_ctx *ctx,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < ctx->field_values_ctr; i++) {
|
for (u8_t i = 0; i < ctx->field_values_ctr; i++) {
|
||||||
struct http_field_value *kv = &ctx->field_values[i];
|
struct http_field_value *kv = &ctx->field_values[i];
|
||||||
|
|
||||||
offset += snprintf(str + offset, size - offset,
|
offset += snprintf(str + offset, size - offset,
|
||||||
|
|
|
@ -68,7 +68,7 @@ static struct in_addr server_addr;
|
||||||
|
|
||||||
struct parsed_url {
|
struct parsed_url {
|
||||||
const char *url;
|
const char *url;
|
||||||
uint16_t url_len;
|
u16_t url_len;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define HTTP_RESPONSE \
|
#define HTTP_RESPONSE \
|
||||||
|
@ -102,7 +102,7 @@ static void my_debug(void *ctx, int level,
|
||||||
static int entropy_source(void *data, unsigned char *output, size_t len,
|
static int entropy_source(void *data, unsigned char *output, size_t len,
|
||||||
size_t *olen)
|
size_t *olen)
|
||||||
{
|
{
|
||||||
uint32_t seed;
|
u32_t seed;
|
||||||
|
|
||||||
ARG_UNUSED(data);
|
ARG_UNUSED(data);
|
||||||
|
|
||||||
|
@ -366,7 +366,7 @@ exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
#define STACK_SIZE 8192
|
#define STACK_SIZE 8192
|
||||||
uint8_t stack[STACK_SIZE];
|
u8_t stack[STACK_SIZE];
|
||||||
|
|
||||||
static inline int init_app(void)
|
static inline int init_app(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,7 @@
|
||||||
/* Sets the network parameters */
|
/* Sets the network parameters */
|
||||||
static
|
static
|
||||||
int network_setup(struct net_context **net_ctx, net_tcp_accept_cb_t accept_cb,
|
int network_setup(struct net_context **net_ctx, net_tcp_accept_cb_t accept_cb,
|
||||||
const char *addr, uint16_t port);
|
const char *addr, u16_t port);
|
||||||
|
|
||||||
#if defined(CONFIG_MBEDTLS)
|
#if defined(CONFIG_MBEDTLS)
|
||||||
#include "ssl_utils.h"
|
#include "ssl_utils.h"
|
||||||
|
@ -68,7 +68,7 @@ void main(void)
|
||||||
|
|
||||||
static
|
static
|
||||||
int network_setup(struct net_context **net_ctx, net_tcp_accept_cb_t accept_cb,
|
int network_setup(struct net_context **net_ctx, net_tcp_accept_cb_t accept_cb,
|
||||||
const char *addr, uint16_t port)
|
const char *addr, u16_t port)
|
||||||
{
|
{
|
||||||
struct sockaddr local_sock;
|
struct sockaddr local_sock;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
|
|
@ -76,7 +76,7 @@ int ssl_tx(void *context, const unsigned char *buf, size_t size)
|
||||||
return MBEDTLS_ERR_SSL_ALLOC_FAILED;
|
return MBEDTLS_ERR_SSL_ALLOC_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = net_pkt_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
|
rc = net_pkt_append(send_buf, size, (u8_t *) buf, K_FOREVER);
|
||||||
if (!rc) {
|
if (!rc) {
|
||||||
net_pkt_unref(send_buf);
|
net_pkt_unref(send_buf);
|
||||||
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
|
return MBEDTLS_ERR_SSL_INTERNAL_ERROR;
|
||||||
|
@ -98,9 +98,9 @@ int ssl_tx(void *context, const unsigned char *buf, size_t size)
|
||||||
int ssl_rx(void *context, unsigned char *buf, size_t size)
|
int ssl_rx(void *context, unsigned char *buf, size_t size)
|
||||||
{
|
{
|
||||||
struct ssl_context *ctx = context;
|
struct ssl_context *ctx = context;
|
||||||
uint16_t read_bytes;
|
u16_t read_bytes;
|
||||||
struct rx_fifo_block *rx_data;
|
struct rx_fifo_block *rx_data;
|
||||||
uint8_t *ptr;
|
u8_t *ptr;
|
||||||
int pos;
|
int pos;
|
||||||
int len;
|
int len;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
|
@ -29,10 +29,10 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define STACK_SIZE 2048
|
#define STACK_SIZE 2048
|
||||||
uint8_t stack[STACK_SIZE];
|
u8_t stack[STACK_SIZE];
|
||||||
|
|
||||||
#define CMD_BUFFER_SIZE 256
|
#define CMD_BUFFER_SIZE 256
|
||||||
static uint8_t cmd_buf[CMD_BUFFER_SIZE];
|
static u8_t cmd_buf[CMD_BUFFER_SIZE];
|
||||||
|
|
||||||
/* LED */
|
/* LED */
|
||||||
#if defined(LED0_GPIO_PORT)
|
#if defined(LED0_GPIO_PORT)
|
||||||
|
@ -276,9 +276,9 @@ on_context_recv(struct net_context *ctx, struct net_pkt *pkt,
|
||||||
{
|
{
|
||||||
struct zirc *irc = data;
|
struct zirc *irc = data;
|
||||||
struct net_buf *tmp;
|
struct net_buf *tmp;
|
||||||
uint8_t *end_of_line;
|
u8_t *end_of_line;
|
||||||
size_t len;
|
size_t len;
|
||||||
uint16_t pos = 0, cmd_len = 0;
|
u16_t pos = 0, cmd_len = 0;
|
||||||
|
|
||||||
if (!pkt) {
|
if (!pkt) {
|
||||||
/* TODO: notify of disconnection, maybe reconnect? */
|
/* TODO: notify of disconnection, maybe reconnect? */
|
||||||
|
@ -678,7 +678,7 @@ static void
|
||||||
on_cmd_random(struct zirc_chan *chan, const char *nick, const char *msg)
|
on_cmd_random(struct zirc_chan *chan, const char *nick, const char *msg)
|
||||||
{
|
{
|
||||||
char buf[128];
|
char buf[128];
|
||||||
int32_t num = sys_rand32_get();
|
s32_t num = sys_rand32_get();
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
switch (num & 3) {
|
switch (num & 3) {
|
||||||
|
@ -714,7 +714,7 @@ on_cmd_random(struct zirc_chan *chan, const char *nick, const char *msg)
|
||||||
static bool
|
static bool
|
||||||
read_led(void)
|
read_led(void)
|
||||||
{
|
{
|
||||||
uint32_t led = 0;
|
u32_t led = 0;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!led0) {
|
if (!led0) {
|
||||||
|
@ -851,7 +851,7 @@ static struct net_mgmt_event_callback mgmt4_cb;
|
||||||
static struct k_sem dhcpv4_ok = K_SEM_INITIALIZER(dhcpv4_ok, 0, UINT_MAX);
|
static struct k_sem dhcpv4_ok = K_SEM_INITIALIZER(dhcpv4_ok, 0, UINT_MAX);
|
||||||
|
|
||||||
static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
|
static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
|
||||||
uint32_t mgmt_event,
|
u32_t mgmt_event,
|
||||||
struct net_if *iface)
|
struct net_if *iface)
|
||||||
{
|
{
|
||||||
char hr_addr[NET_IPV4_ADDR_LEN];
|
char hr_addr[NET_IPV4_ADDR_LEN];
|
||||||
|
@ -948,7 +948,7 @@ static struct k_sem dad_ok = K_SEM_INITIALIZER(dad_ok, 0, UINT_MAX);
|
||||||
static struct in6_addr laddr;
|
static struct in6_addr laddr;
|
||||||
|
|
||||||
static void ipv6_dad_ok_handler(struct net_mgmt_event_callback *cb,
|
static void ipv6_dad_ok_handler(struct net_mgmt_event_callback *cb,
|
||||||
uint32_t mgmt_event,
|
u32_t mgmt_event,
|
||||||
struct net_if *iface)
|
struct net_if *iface)
|
||||||
{
|
{
|
||||||
struct net_if_addr *ifaddr;
|
struct net_if_addr *ifaddr;
|
||||||
|
|
|
@ -66,7 +66,7 @@ static bool fake_led;
|
||||||
|
|
||||||
static bool read_led(void)
|
static bool read_led(void)
|
||||||
{
|
{
|
||||||
uint32_t led = 0;
|
u32_t led = 0;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!led0) {
|
if (!led0) {
|
||||||
|
@ -99,8 +99,8 @@ static int led_get(struct zoap_resource *resource,
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
const char *str;
|
const char *str;
|
||||||
uint8_t *payload;
|
u8_t *payload;
|
||||||
uint16_t len, id;
|
u16_t len, id;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
id = zoap_header_get_id(request);
|
id = zoap_header_get_id(request);
|
||||||
|
@ -165,9 +165,9 @@ static int led_post(struct zoap_resource *resource,
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
const char *str;
|
const char *str;
|
||||||
uint8_t *payload;
|
u8_t *payload;
|
||||||
uint16_t len, id;
|
u16_t len, id;
|
||||||
uint32_t led;
|
u32_t led;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
payload = zoap_packet_get_payload(request, &len);
|
payload = zoap_packet_get_payload(request, &len);
|
||||||
|
@ -244,9 +244,9 @@ static int led_put(struct zoap_resource *resource,
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
const char *str;
|
const char *str;
|
||||||
uint8_t *payload;
|
u8_t *payload;
|
||||||
uint16_t len, id;
|
u16_t len, id;
|
||||||
uint32_t led;
|
u32_t led;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
payload = zoap_packet_get_payload(request, &len);
|
payload = zoap_packet_get_payload(request, &len);
|
||||||
|
@ -324,8 +324,8 @@ static int dummy_get(struct zoap_resource *resource,
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
uint8_t *payload;
|
u8_t *payload;
|
||||||
uint16_t len, id;
|
u16_t len, id;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
id = zoap_header_get_id(request);
|
id = zoap_header_get_id(request);
|
||||||
|
|
|
@ -77,9 +77,9 @@ enum exit_codes {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct dtls_timing_context {
|
struct dtls_timing_context {
|
||||||
uint32_t snapshot;
|
u32_t snapshot;
|
||||||
uint32_t int_ms;
|
u32_t int_ms;
|
||||||
uint32_t fin_ms;
|
u32_t fin_ms;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void my_debug(void *ctx, int level,
|
static void my_debug(void *ctx, int level,
|
||||||
|
@ -97,7 +97,7 @@ static void my_debug(void *ctx, int level,
|
||||||
mbedtls_printf("%s:%04d: |%d| %s", basename, line, level, str);
|
mbedtls_printf("%s:%04d: |%d| %s", basename, line, level, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dtls_timing_set_delay(void *data, uint32_t int_ms, uint32_t fin_ms)
|
void dtls_timing_set_delay(void *data, u32_t int_ms, u32_t fin_ms)
|
||||||
{
|
{
|
||||||
struct dtls_timing_context *ctx = (struct dtls_timing_context *)data;
|
struct dtls_timing_context *ctx = (struct dtls_timing_context *)data;
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ int dtls_timing_get_delay(void *data)
|
||||||
static int entropy_source(void *data, unsigned char *output, size_t len,
|
static int entropy_source(void *data, unsigned char *output, size_t len,
|
||||||
size_t *olen)
|
size_t *olen)
|
||||||
{
|
{
|
||||||
uint32_t seed;
|
u32_t seed;
|
||||||
|
|
||||||
seed = sys_rand32_get();
|
seed = sys_rand32_get();
|
||||||
if (len > sizeof(seed)) {
|
if (len > sizeof(seed)) {
|
||||||
|
@ -284,7 +284,7 @@ exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
#define STACK_SIZE 8192
|
#define STACK_SIZE 8192
|
||||||
uint8_t stack[STACK_SIZE];
|
u8_t stack[STACK_SIZE];
|
||||||
|
|
||||||
static inline int init_app(void)
|
static inline int init_app(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -86,7 +86,7 @@ int udp_tx(void *context, const unsigned char *buf, size_t size)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = net_pkt_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
|
rc = net_pkt_append(send_buf, size, (u8_t *) buf, K_FOREVER);
|
||||||
if (!rc) {
|
if (!rc) {
|
||||||
printk("cannot write buf\n");
|
printk("cannot write buf\n");
|
||||||
net_pkt_unref(send_buf);
|
net_pkt_unref(send_buf);
|
||||||
|
@ -112,8 +112,8 @@ int udp_rx(void *context, unsigned char *buf, size_t size)
|
||||||
{
|
{
|
||||||
struct udp_context *ctx = context;
|
struct udp_context *ctx = context;
|
||||||
struct net_buf *rx_buf = NULL;
|
struct net_buf *rx_buf = NULL;
|
||||||
uint16_t read_bytes;
|
u16_t read_bytes;
|
||||||
uint8_t *ptr;
|
u8_t *ptr;
|
||||||
int pos;
|
int pos;
|
||||||
int len;
|
int len;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
|
@ -63,9 +63,9 @@ const unsigned char ecjpake_pw[ECJPAKE_PW_SIZE] = "passwd";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct dtls_timing_context {
|
struct dtls_timing_context {
|
||||||
uint32_t snapshot;
|
u32_t snapshot;
|
||||||
uint32_t int_ms;
|
u32_t int_ms;
|
||||||
uint32_t fin_ms;
|
u32_t fin_ms;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void my_debug(void *ctx, int level,
|
static void my_debug(void *ctx, int level,
|
||||||
|
@ -86,7 +86,7 @@ static void my_debug(void *ctx, int level,
|
||||||
mbedtls_printf("%s:%04d: |%d| %s", basename, line, level, str);
|
mbedtls_printf("%s:%04d: |%d| %s", basename, line, level, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dtls_timing_set_delay(void *data, uint32_t int_ms, uint32_t fin_ms)
|
void dtls_timing_set_delay(void *data, u32_t int_ms, u32_t fin_ms)
|
||||||
{
|
{
|
||||||
struct dtls_timing_context *ctx = (struct dtls_timing_context *)data;
|
struct dtls_timing_context *ctx = (struct dtls_timing_context *)data;
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ int dtls_timing_get_delay(void *data)
|
||||||
static int entropy_source(void *data, unsigned char *output, size_t len,
|
static int entropy_source(void *data, unsigned char *output, size_t len,
|
||||||
size_t *olen)
|
size_t *olen)
|
||||||
{
|
{
|
||||||
uint32_t seed;
|
u32_t seed;
|
||||||
|
|
||||||
ARG_UNUSED(data);
|
ARG_UNUSED(data);
|
||||||
|
|
||||||
|
@ -362,7 +362,7 @@ exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
#define STACK_SIZE 8192
|
#define STACK_SIZE 8192
|
||||||
uint8_t stack[STACK_SIZE];
|
u8_t stack[STACK_SIZE];
|
||||||
|
|
||||||
static inline int init_app(void)
|
static inline int init_app(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -66,7 +66,7 @@ int udp_tx(void *context, const unsigned char *buf, size_t size)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = net_pkt_append(send_buf, size, (uint8_t *) buf, K_FOREVER);
|
rc = net_pkt_append(send_buf, size, (u8_t *) buf, K_FOREVER);
|
||||||
if (!rc) {
|
if (!rc) {
|
||||||
printk("cannot write buf\n");
|
printk("cannot write buf\n");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
@ -91,8 +91,8 @@ int udp_rx(void *context, unsigned char *buf, size_t size)
|
||||||
struct udp_context *ctx = context;
|
struct udp_context *ctx = context;
|
||||||
struct net_context *net_ctx = ctx->net_ctx;
|
struct net_context *net_ctx = ctx->net_ctx;
|
||||||
struct net_buf *rx_buf = NULL;
|
struct net_buf *rx_buf = NULL;
|
||||||
uint16_t read_bytes;
|
u16_t read_bytes;
|
||||||
uint8_t *ptr;
|
u8_t *ptr;
|
||||||
int pos;
|
int pos;
|
||||||
int len;
|
int len;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
|
@ -139,7 +139,7 @@ enum exit_codes {
|
||||||
static int entropy_source(void *data, unsigned char *output, size_t len,
|
static int entropy_source(void *data, unsigned char *output, size_t len,
|
||||||
size_t *olen)
|
size_t *olen)
|
||||||
{
|
{
|
||||||
uint32_t seed;
|
u32_t seed;
|
||||||
|
|
||||||
ARG_UNUSED(data);
|
ARG_UNUSED(data);
|
||||||
|
|
||||||
|
@ -315,7 +315,7 @@ exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
#define STACK_SIZE 8192
|
#define STACK_SIZE 8192
|
||||||
uint8_t stack[STACK_SIZE];
|
u8_t stack[STACK_SIZE];
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -55,7 +55,7 @@ int tcp_tx(void *context, const unsigned char *buf, size_t size)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = net_pkt_append(send_pkt, size, (uint8_t *) buf, K_FOREVER);
|
rc = net_pkt_append(send_pkt, size, (u8_t *) buf, K_FOREVER);
|
||||||
if (!rc) {
|
if (!rc) {
|
||||||
printk("cannot write buf\n");
|
printk("cannot write buf\n");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
@ -79,9 +79,9 @@ int tcp_rx(void *context, unsigned char *buf, size_t size)
|
||||||
struct net_buf *data = NULL;
|
struct net_buf *data = NULL;
|
||||||
struct tcp_context *ctx = context;
|
struct tcp_context *ctx = context;
|
||||||
int rc;
|
int rc;
|
||||||
uint8_t *ptr;
|
u8_t *ptr;
|
||||||
int read_bytes;
|
int read_bytes;
|
||||||
uint16_t offset;
|
u16_t offset;
|
||||||
|
|
||||||
rc = net_context_recv(ctx->net_ctx, tcp_received, K_FOREVER, ctx);
|
rc = net_context_recv(ctx->net_ctx, tcp_received, K_FOREVER, ctx);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
|
@ -109,7 +109,7 @@ int tcp_rx(void *context, unsigned char *buf, size_t size)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_addr(struct sockaddr *sock_addr, const char *addr,
|
static int set_addr(struct sockaddr *sock_addr, const char *addr,
|
||||||
uint16_t server_port)
|
u16_t server_port)
|
||||||
{
|
{
|
||||||
void *ptr = NULL;
|
void *ptr = NULL;
|
||||||
int rc;
|
int rc;
|
||||||
|
@ -174,7 +174,7 @@ lb_exit:
|
||||||
}
|
}
|
||||||
|
|
||||||
int tcp_init(struct tcp_context *ctx, const char *server_addr,
|
int tcp_init(struct tcp_context *ctx, const char *server_addr,
|
||||||
uint16_t server_port)
|
u16_t server_port)
|
||||||
{
|
{
|
||||||
struct sockaddr server_sock;
|
struct sockaddr server_sock;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
|
@ -15,11 +15,11 @@ struct tcp_context {
|
||||||
struct net_context *net_ctx;
|
struct net_context *net_ctx;
|
||||||
struct sockaddr local_sock;
|
struct sockaddr local_sock;
|
||||||
struct net_pkt *rx_pkt;
|
struct net_pkt *rx_pkt;
|
||||||
int32_t timeout;
|
s32_t timeout;
|
||||||
};
|
};
|
||||||
|
|
||||||
int tcp_init(struct tcp_context *ctx, const char *server_addr,
|
int tcp_init(struct tcp_context *ctx, const char *server_addr,
|
||||||
uint16_t server_port);
|
u16_t server_port);
|
||||||
|
|
||||||
int tcp_tx(void *ctx, const unsigned char *buf, size_t size);
|
int tcp_tx(void *ctx, const unsigned char *buf, size_t size);
|
||||||
int tcp_rx(void *ctx, unsigned char *buf, size_t size);
|
int tcp_rx(void *ctx, unsigned char *buf, size_t size);
|
||||||
|
|
|
@ -67,7 +67,7 @@ static struct mqtt_client_ctx client_ctx;
|
||||||
|
|
||||||
/* This routine sets some basic properties for the network context variable */
|
/* This routine sets some basic properties for the network context variable */
|
||||||
static int network_setup(struct net_context **net_ctx, const char *local_addr,
|
static int network_setup(struct net_context **net_ctx, const char *local_addr,
|
||||||
const char *server_addr, uint16_t server_port);
|
const char *server_addr, u16_t server_port);
|
||||||
|
|
||||||
/* The signature of this routine must match the connect callback declared at
|
/* The signature of this routine must match the connect callback declared at
|
||||||
* the mqtt.h header.
|
* the mqtt.h header.
|
||||||
|
@ -120,7 +120,7 @@ static void disconnect_cb(struct mqtt_ctx *mqtt_ctx)
|
||||||
* unknown pkt_id, this routine must return an error, for example -EINVAL or
|
* unknown pkt_id, this routine must return an error, for example -EINVAL or
|
||||||
* any negative value.
|
* any negative value.
|
||||||
*/
|
*/
|
||||||
static int publish_cb(struct mqtt_ctx *mqtt_ctx, uint16_t pkt_id,
|
static int publish_cb(struct mqtt_ctx *mqtt_ctx, u16_t pkt_id,
|
||||||
enum mqtt_packet type)
|
enum mqtt_packet type)
|
||||||
{
|
{
|
||||||
struct mqtt_client_ctx *client_ctx;
|
struct mqtt_client_ctx *client_ctx;
|
||||||
|
@ -160,7 +160,7 @@ static int publish_cb(struct mqtt_ctx *mqtt_ctx, uint16_t pkt_id,
|
||||||
* The signature of this routine must match the malformed callback declared at
|
* The signature of this routine must match the malformed callback declared at
|
||||||
* the mqtt.h header.
|
* the mqtt.h header.
|
||||||
*/
|
*/
|
||||||
static void malformed_cb(struct mqtt_ctx *mqtt_ctx, uint16_t pkt_type)
|
static void malformed_cb(struct mqtt_ctx *mqtt_ctx, u16_t pkt_type)
|
||||||
{
|
{
|
||||||
printk("[%s:%d] pkt_type: %u\n", __func__, __LINE__, pkt_type);
|
printk("[%s:%d] pkt_type: %u\n", __func__, __LINE__, pkt_type);
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ static char *get_mqtt_payload(enum mqtt_qos qos)
|
||||||
static char payload[30];
|
static char payload[30];
|
||||||
|
|
||||||
snprintk(payload, sizeof(payload), "{d:{temperature:%d}}",
|
snprintk(payload, sizeof(payload), "{d:{temperature:%d}}",
|
||||||
(uint8_t)sys_rand32_get());
|
(u8_t)sys_rand32_get());
|
||||||
#else
|
#else
|
||||||
static char payload[] = "DOORS:OPEN_QoSx";
|
static char payload[] = "DOORS:OPEN_QoSx";
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ exit_app:
|
||||||
printk("\nBye!\n");
|
printk("\nBye!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_addr(struct sockaddr *sock_addr, const char *addr, uint16_t port)
|
static int set_addr(struct sockaddr *sock_addr, const char *addr, u16_t port)
|
||||||
{
|
{
|
||||||
void *ptr;
|
void *ptr;
|
||||||
int rc;
|
int rc;
|
||||||
|
@ -351,13 +351,13 @@ static int set_addr(struct sockaddr *sock_addr, const char *addr, uint16_t port)
|
||||||
static bool bt_connected;
|
static bool bt_connected;
|
||||||
|
|
||||||
static
|
static
|
||||||
void bt_connect_cb(struct bt_conn *conn, uint8_t err)
|
void bt_connect_cb(struct bt_conn *conn, u8_t err)
|
||||||
{
|
{
|
||||||
bt_connected = true;
|
bt_connected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
void bt_disconnect_cb(struct bt_conn *conn, uint8_t reason)
|
void bt_disconnect_cb(struct bt_conn *conn, u8_t reason)
|
||||||
{
|
{
|
||||||
bt_connected = false;
|
bt_connected = false;
|
||||||
printk("bt disconnected (reason %u)\n", reason);
|
printk("bt disconnected (reason %u)\n", reason);
|
||||||
|
@ -371,7 +371,7 @@ struct bt_conn_cb bt_conn_cb = {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int network_setup(struct net_context **net_ctx, const char *local_addr,
|
static int network_setup(struct net_context **net_ctx, const char *local_addr,
|
||||||
const char *server_addr, uint16_t server_port)
|
const char *server_addr, u16_t server_port)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_NET_IPV6
|
#ifdef CONFIG_NET_IPV6
|
||||||
socklen_t addr_len = sizeof(struct sockaddr_in6);
|
socklen_t addr_len = sizeof(struct sockaddr_in6);
|
||||||
|
|
|
@ -70,7 +70,7 @@ static bool fake_led;
|
||||||
/* Default server */
|
/* Default server */
|
||||||
#define DEFAULT_PORT 4222
|
#define DEFAULT_PORT 4222
|
||||||
|
|
||||||
static uint8_t stack[2048];
|
static u8_t stack[2048];
|
||||||
|
|
||||||
static void panic(const char *msg)
|
static void panic(const char *msg)
|
||||||
{
|
{
|
||||||
|
@ -172,7 +172,7 @@ static void initialize_network(void)
|
||||||
|
|
||||||
static bool read_led(void)
|
static bool read_led(void)
|
||||||
{
|
{
|
||||||
uint32_t led = 0;
|
u32_t led = 0;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (!led0) {
|
if (!led0) {
|
||||||
|
@ -241,7 +241,7 @@ static void initialize_hardware(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int connect(struct nats *nats, uint16_t port)
|
static int connect(struct nats *nats, u16_t port)
|
||||||
{
|
{
|
||||||
#if defined(CONFIG_NET_IPV4) && defined(CONFIG_NET_DHCPV4)
|
#if defined(CONFIG_NET_IPV4) && defined(CONFIG_NET_DHCPV4)
|
||||||
struct net_if *iface;
|
struct net_if *iface;
|
||||||
|
|
|
@ -30,7 +30,7 @@ struct nats_info {
|
||||||
const char *go;
|
const char *go;
|
||||||
const char *host;
|
const char *host;
|
||||||
size_t max_payload;
|
size_t max_payload;
|
||||||
uint16_t port;
|
u16_t port;
|
||||||
bool ssl_required;
|
bool ssl_required;
|
||||||
bool auth_required;
|
bool auth_required;
|
||||||
};
|
};
|
||||||
|
@ -132,7 +132,7 @@ static inline int transmit(struct net_context *conn, const char buffer[],
|
||||||
.type = type_ \
|
.type = type_ \
|
||||||
}
|
}
|
||||||
static int handle_server_info(struct nats *nats, char *payload, size_t len,
|
static int handle_server_info(struct nats *nats, char *payload, size_t len,
|
||||||
struct net_buf *buf, uint16_t offset)
|
struct net_buf *buf, u16_t offset)
|
||||||
{
|
{
|
||||||
static const struct json_obj_descr descr[] = {
|
static const struct json_obj_descr descr[] = {
|
||||||
FIELD(struct nats_info, server_id, JSON_TOK_STRING),
|
FIELD(struct nats_info, server_id, JSON_TOK_STRING),
|
||||||
|
@ -231,11 +231,11 @@ static char *strsep(char *strp, const char *delims)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int copy_pkt_to_buf(struct net_buf *src, uint16_t offset,
|
static int copy_pkt_to_buf(struct net_buf *src, u16_t offset,
|
||||||
char *dst, size_t dst_size, size_t n_bytes)
|
char *dst, size_t dst_size, size_t n_bytes)
|
||||||
{
|
{
|
||||||
uint16_t to_copy;
|
u16_t to_copy;
|
||||||
uint16_t copied;
|
u16_t copied;
|
||||||
|
|
||||||
if (dst_size < n_bytes) {
|
if (dst_size < n_bytes) {
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -264,7 +264,7 @@ static int copy_pkt_to_buf(struct net_buf *src, uint16_t offset,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_server_msg(struct nats *nats, char *payload, size_t len,
|
static int handle_server_msg(struct nats *nats, char *payload, size_t len,
|
||||||
struct net_buf *buf, uint16_t offset)
|
struct net_buf *buf, u16_t offset)
|
||||||
{
|
{
|
||||||
char *subject, *sid, *reply_to, *bytes, *end_ptr;
|
char *subject, *sid, *reply_to, *bytes, *end_ptr;
|
||||||
char prev_end = payload[len];
|
char prev_end = payload[len];
|
||||||
|
@ -320,7 +320,7 @@ static int handle_server_msg(struct nats *nats, char *payload, size_t len,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int handle_server_ping(struct nats *nats, char *payload, size_t len,
|
static int handle_server_ping(struct nats *nats, char *payload, size_t len,
|
||||||
struct net_buf *buf, uint16_t offset)
|
struct net_buf *buf, u16_t offset)
|
||||||
{
|
{
|
||||||
static const char pong[] = "PONG\r\n";
|
static const char pong[] = "PONG\r\n";
|
||||||
|
|
||||||
|
@ -328,7 +328,7 @@ static int handle_server_ping(struct nats *nats, char *payload, size_t len,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ignore(struct nats *nats, char *payload, size_t len,
|
static int ignore(struct nats *nats, char *payload, size_t len,
|
||||||
struct net_buf *buf, uint16_t offset)
|
struct net_buf *buf, u16_t offset)
|
||||||
{
|
{
|
||||||
/* FIXME: Notify user of success/errors. This would require
|
/* FIXME: Notify user of success/errors. This would require
|
||||||
* maintaining information of what was the last sent command in
|
* maintaining information of what was the last sent command in
|
||||||
|
@ -345,13 +345,13 @@ static int ignore(struct nats *nats, char *payload, size_t len,
|
||||||
.handle = handler_ \
|
.handle = handler_ \
|
||||||
}
|
}
|
||||||
static int handle_server_cmd(struct nats *nats, char *cmd, size_t len,
|
static int handle_server_cmd(struct nats *nats, char *cmd, size_t len,
|
||||||
struct net_buf *buf, uint16_t offset)
|
struct net_buf *buf, u16_t offset)
|
||||||
{
|
{
|
||||||
static const struct {
|
static const struct {
|
||||||
const char *op;
|
const char *op;
|
||||||
size_t len;
|
size_t len;
|
||||||
int (*handle)(struct nats *nats, char *payload, size_t len,
|
int (*handle)(struct nats *nats, char *payload, size_t len,
|
||||||
struct net_buf *buf, uint16_t offset);
|
struct net_buf *buf, u16_t offset);
|
||||||
} cmds[] = {
|
} cmds[] = {
|
||||||
CMD("INFO", handle_server_info),
|
CMD("INFO", handle_server_info),
|
||||||
CMD("MSG", handle_server_msg),
|
CMD("MSG", handle_server_msg),
|
||||||
|
@ -537,9 +537,9 @@ static void receive_cb(struct net_context *ctx, struct net_pkt *pkt, int status,
|
||||||
struct nats *nats = user_data;
|
struct nats *nats = user_data;
|
||||||
char cmd_buf[CMD_BUF_LEN];
|
char cmd_buf[CMD_BUF_LEN];
|
||||||
struct net_buf *tmp;
|
struct net_buf *tmp;
|
||||||
uint16_t pos = 0, cmd_len = 0;
|
u16_t pos = 0, cmd_len = 0;
|
||||||
size_t len;
|
size_t len;
|
||||||
uint8_t *end_of_line;
|
u8_t *end_of_line;
|
||||||
|
|
||||||
if (!pkt) {
|
if (!pkt) {
|
||||||
/* FIXME: How to handle disconnection? */
|
/* FIXME: How to handle disconnection? */
|
||||||
|
@ -558,9 +558,9 @@ static void receive_cb(struct net_context *ctx, struct net_pkt *pkt, int status,
|
||||||
while (tmp) {
|
while (tmp) {
|
||||||
len = tmp->len - pos;
|
len = tmp->len - pos;
|
||||||
|
|
||||||
end_of_line = memchr((uint8_t *)tmp->data + pos, '\n', len);
|
end_of_line = memchr((u8_t *)tmp->data + pos, '\n', len);
|
||||||
if (end_of_line) {
|
if (end_of_line) {
|
||||||
len = end_of_line - ((uint8_t *)tmp->data + pos);
|
len = end_of_line - ((u8_t *)tmp->data + pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmd_len + len > sizeof(cmd_buf)) {
|
if (cmd_len + len > sizeof(cmd_buf)) {
|
||||||
|
|
|
@ -26,7 +26,7 @@ char __noinit __stack thread_stack[STACKSIZE];
|
||||||
static struct net_mgmt_event_callback mgmt_cb;
|
static struct net_mgmt_event_callback mgmt_cb;
|
||||||
|
|
||||||
static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
|
static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
|
||||||
uint32_t mgmt_event,
|
u32_t mgmt_event,
|
||||||
struct net_if *iface)
|
struct net_if *iface)
|
||||||
{
|
{
|
||||||
char hr_addr[NET_IPV4_ADDR_LEN];
|
char hr_addr[NET_IPV4_ADDR_LEN];
|
||||||
|
|
|
@ -50,25 +50,25 @@ static struct k_fifo tx_queue;
|
||||||
static char __noinit __stack tx_stack[1024];
|
static char __noinit __stack tx_stack[1024];
|
||||||
|
|
||||||
/* Buffer for SLIP encoded data for the worst case */
|
/* Buffer for SLIP encoded data for the worst case */
|
||||||
static uint8_t slip_buf[1 + 2 * CONFIG_NET_BUF_DATA_SIZE];
|
static u8_t slip_buf[1 + 2 * CONFIG_NET_BUF_DATA_SIZE];
|
||||||
|
|
||||||
/* ieee802.15.4 device */
|
/* ieee802.15.4 device */
|
||||||
static struct ieee802154_radio_api *radio_api;
|
static struct ieee802154_radio_api *radio_api;
|
||||||
static struct device *ieee802154_dev;
|
static struct device *ieee802154_dev;
|
||||||
uint8_t mac_addr[8];
|
u8_t mac_addr[8];
|
||||||
|
|
||||||
/* UART device */
|
/* UART device */
|
||||||
static struct device *uart_dev;
|
static struct device *uart_dev;
|
||||||
|
|
||||||
/* SLIP state machine */
|
/* SLIP state machine */
|
||||||
static uint8_t slip_state = STATE_OK;
|
static u8_t slip_state = STATE_OK;
|
||||||
|
|
||||||
static struct net_pkt *pkt_curr;
|
static struct net_pkt *pkt_curr;
|
||||||
|
|
||||||
/* General helpers */
|
/* General helpers */
|
||||||
|
|
||||||
#ifdef VERBOSE_DEBUG
|
#ifdef VERBOSE_DEBUG
|
||||||
static void hexdump(const char *str, const uint8_t *packet, size_t length)
|
static void hexdump(const char *str, const u8_t *packet, size_t length)
|
||||||
{
|
{
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ static void interrupt_handler(struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Allocate and send data to USB Host */
|
/* Allocate and send data to USB Host */
|
||||||
static void send_data(uint8_t *cfg, uint8_t *data, size_t len)
|
static void send_data(u8_t *cfg, u8_t *data, size_t len)
|
||||||
{
|
{
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *buf;
|
struct net_buf *buf;
|
||||||
|
@ -253,8 +253,8 @@ static void send_data(uint8_t *cfg, uint8_t *data, size_t len)
|
||||||
|
|
||||||
static void get_ieee_addr(void)
|
static void get_ieee_addr(void)
|
||||||
{
|
{
|
||||||
uint8_t cfg[2] = { '!', 'M' };
|
u8_t cfg[2] = { '!', 'M' };
|
||||||
uint8_t mac[8];
|
u8_t mac[8];
|
||||||
|
|
||||||
SYS_LOG_DBG("");
|
SYS_LOG_DBG("");
|
||||||
|
|
||||||
|
@ -266,7 +266,7 @@ static void get_ieee_addr(void)
|
||||||
|
|
||||||
static void process_request(struct net_buf *buf)
|
static void process_request(struct net_buf *buf)
|
||||||
{
|
{
|
||||||
uint8_t cmd = net_buf_pull_u8(buf);
|
u8_t cmd = net_buf_pull_u8(buf);
|
||||||
|
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
|
@ -279,10 +279,10 @@ static void process_request(struct net_buf *buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_pkt_report(uint8_t seq, uint8_t status, uint8_t num_tx)
|
static void send_pkt_report(u8_t seq, u8_t status, u8_t num_tx)
|
||||||
{
|
{
|
||||||
uint8_t cfg[2] = { '!', 'R' };
|
u8_t cfg[2] = { '!', 'R' };
|
||||||
uint8_t report[3];
|
u8_t report[3];
|
||||||
|
|
||||||
report[0] = seq;
|
report[0] = seq;
|
||||||
report[1] = status;
|
report[1] = status;
|
||||||
|
@ -294,7 +294,7 @@ static void send_pkt_report(uint8_t seq, uint8_t status, uint8_t num_tx)
|
||||||
static void process_data(struct net_pkt *pkt)
|
static void process_data(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
struct net_buf *buf = net_buf_frag_last(pkt->frags);
|
struct net_buf *buf = net_buf_frag_last(pkt->frags);
|
||||||
uint8_t seq, num_attr;
|
u8_t seq, num_attr;
|
||||||
int ret, i;
|
int ret, i;
|
||||||
|
|
||||||
seq = net_buf_pull_u8(buf);
|
seq = net_buf_pull_u8(buf);
|
||||||
|
@ -327,7 +327,7 @@ static void process_data(struct net_pkt *pkt)
|
||||||
send_pkt_report(seq, ret, 1);
|
send_pkt_report(seq, ret, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_channel(uint8_t chan)
|
static void set_channel(u8_t chan)
|
||||||
{
|
{
|
||||||
SYS_LOG_DBG("Set channel %c", chan);
|
SYS_LOG_DBG("Set channel %c", chan);
|
||||||
|
|
||||||
|
@ -337,7 +337,7 @@ static void set_channel(uint8_t chan)
|
||||||
static void process_config(struct net_pkt *pkt)
|
static void process_config(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
struct net_buf *buf = net_buf_frag_last(pkt->frags);
|
struct net_buf *buf = net_buf_frag_last(pkt->frags);
|
||||||
uint8_t cmd = net_buf_pull_u8(buf);
|
u8_t cmd = net_buf_pull_u8(buf);
|
||||||
|
|
||||||
SYS_LOG_DBG("Process config %c", cmd);
|
SYS_LOG_DBG("Process config %c", cmd);
|
||||||
|
|
||||||
|
@ -360,7 +360,7 @@ static void rx_thread(void)
|
||||||
while (1) {
|
while (1) {
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *buf;
|
struct net_buf *buf;
|
||||||
uint8_t specifier;
|
u8_t specifier;
|
||||||
|
|
||||||
pkt = k_fifo_get(&rx_queue, K_FOREVER);
|
pkt = k_fifo_get(&rx_queue, K_FOREVER);
|
||||||
buf = net_buf_frag_last(pkt->frags);
|
buf = net_buf_frag_last(pkt->frags);
|
||||||
|
@ -389,10 +389,10 @@ static void rx_thread(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t slip_buffer(uint8_t *sbuf, struct net_buf *buf)
|
static size_t slip_buffer(u8_t *sbuf, struct net_buf *buf)
|
||||||
{
|
{
|
||||||
size_t len = buf->len;
|
size_t len = buf->len;
|
||||||
uint8_t *sbuf_orig = sbuf;
|
u8_t *sbuf_orig = sbuf;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -401,7 +401,7 @@ static size_t slip_buffer(uint8_t *sbuf, struct net_buf *buf)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
uint8_t byte = net_buf_pull_u8(buf);
|
u8_t byte = net_buf_pull_u8(buf);
|
||||||
|
|
||||||
switch (byte) {
|
switch (byte) {
|
||||||
case SLIP_END:
|
case SLIP_END:
|
||||||
|
@ -486,9 +486,9 @@ static void init_tx_queue(void)
|
||||||
/**
|
/**
|
||||||
* FIXME choose correct OUI, or add support in L2
|
* FIXME choose correct OUI, or add support in L2
|
||||||
*/
|
*/
|
||||||
static uint8_t *get_mac(struct device *dev)
|
static u8_t *get_mac(struct device *dev)
|
||||||
{
|
{
|
||||||
uint32_t *ptr = (uint32_t *)mac_addr;
|
u32_t *ptr = (u32_t *)mac_addr;
|
||||||
|
|
||||||
mac_addr[7] = 0x00;
|
mac_addr[7] = 0x00;
|
||||||
mac_addr[6] = 0x12;
|
mac_addr[6] = 0x12;
|
||||||
|
@ -504,7 +504,7 @@ static uint8_t *get_mac(struct device *dev)
|
||||||
|
|
||||||
static bool init_ieee802154(void)
|
static bool init_ieee802154(void)
|
||||||
{
|
{
|
||||||
uint16_t short_addr;
|
u16_t short_addr;
|
||||||
|
|
||||||
SYS_LOG_INF("Initialize ieee802.15.4");
|
SYS_LOG_INF("Initialize ieee802.15.4");
|
||||||
|
|
||||||
|
@ -548,7 +548,7 @@ static bool init_ieee802154(void)
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
uint32_t baudrate, dtr = 0;
|
u32_t baudrate, dtr = 0;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
dev = device_get_binding(CONFIG_CDC_ACM_PORT_NAME);
|
dev = device_get_binding(CONFIG_CDC_ACM_PORT_NAME);
|
||||||
|
|
|
@ -84,14 +84,14 @@ static char __noinit __stack tx_stack[1024];
|
||||||
struct wpanusb_dev_data_t {
|
struct wpanusb_dev_data_t {
|
||||||
/* USB device status code */
|
/* USB device status code */
|
||||||
enum usb_dc_status_code usb_status;
|
enum usb_dc_status_code usb_status;
|
||||||
uint8_t interface_data[WPANUSB_CLASS_MAX_DATA_SIZE];
|
u8_t interface_data[WPANUSB_CLASS_MAX_DATA_SIZE];
|
||||||
uint8_t notification_sent;
|
u8_t notification_sent;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ieee802.15.4 USB descriptors configuration
|
* ieee802.15.4 USB descriptors configuration
|
||||||
*/
|
*/
|
||||||
static const uint8_t wpanusb_desc[] = {
|
static const u8_t wpanusb_desc[] = {
|
||||||
/* Device descriptor */
|
/* Device descriptor */
|
||||||
USB_DEVICE_DESC_SIZE, /* Descriptor size */
|
USB_DEVICE_DESC_SIZE, /* Descriptor size */
|
||||||
USB_DEVICE_DESC, /* Descriptor type */
|
USB_DEVICE_DESC, /* Descriptor type */
|
||||||
|
@ -176,7 +176,7 @@ static const uint8_t wpanusb_desc[] = {
|
||||||
|
|
||||||
#ifdef VERBOSE_DEBUG
|
#ifdef VERBOSE_DEBUG
|
||||||
/* TODO: move to standard utils */
|
/* TODO: move to standard utils */
|
||||||
static void hexdump(const char *str, const uint8_t *packet, size_t length)
|
static void hexdump(const char *str, const u8_t *packet, size_t length)
|
||||||
{
|
{
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ static void hexdump(const char *str, const uint8_t *packet, size_t length)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* EP Bulk IN handler, used to send data to the Host */
|
/* EP Bulk IN handler, used to send data to the Host */
|
||||||
static void wpanusb_bulk_in(uint8_t ep, enum usb_dc_ep_cb_status_code ep_status)
|
static void wpanusb_bulk_in(u8_t ep, enum usb_dc_ep_cb_status_code ep_status)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ static void wpanusb_status_cb(enum usb_dc_status_code status)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int wpanusb_class_handler(struct usb_setup_packet *setup,
|
static int wpanusb_class_handler(struct usb_setup_packet *setup,
|
||||||
int32_t *len, uint8_t **data)
|
s32_t *len, u8_t **data)
|
||||||
{
|
{
|
||||||
SYS_LOG_DBG("len %d", *len);
|
SYS_LOG_DBG("len %d", *len);
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ static int wpanusb_class_handler(struct usb_setup_packet *setup,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int wpanusb_custom_handler(struct usb_setup_packet *setup,
|
static int wpanusb_custom_handler(struct usb_setup_packet *setup,
|
||||||
int32_t *len, uint8_t **data)
|
s32_t *len, u8_t **data)
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* FIXME:
|
* FIXME:
|
||||||
|
@ -281,7 +281,7 @@ static int wpanusb_custom_handler(struct usb_setup_packet *setup,
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int try_write(uint8_t ep, uint8_t *data, uint16_t len)
|
static int try_write(u8_t ep, u8_t *data, u16_t len)
|
||||||
{
|
{
|
||||||
while (1) {
|
while (1) {
|
||||||
int ret = usb_write(ep, data, len, NULL);
|
int ret = usb_write(ep, data, len, NULL);
|
||||||
|
@ -314,7 +314,7 @@ static int set_ieee_addr(void *data, int len)
|
||||||
SYS_LOG_DBG("len %u", len);
|
SYS_LOG_DBG("len %u", len);
|
||||||
|
|
||||||
return radio_api->set_ieee_addr(ieee802154_dev,
|
return radio_api->set_ieee_addr(ieee802154_dev,
|
||||||
(uint8_t *)&req->ieee_addr);
|
(u8_t *)&req->ieee_addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int set_short_addr(void *data, int len)
|
static int set_short_addr(void *data, int len)
|
||||||
|
@ -352,7 +352,7 @@ static int stop(void)
|
||||||
static int tx(struct net_pkt *pkt)
|
static int tx(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
struct net_buf *buf = net_buf_frag_last(pkt->frags);
|
struct net_buf *buf = net_buf_frag_last(pkt->frags);
|
||||||
uint8_t seq = net_buf_pull_u8(buf);
|
u8_t seq = net_buf_pull_u8(buf);
|
||||||
int retries = 3;
|
int retries = 3;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -378,7 +378,7 @@ static int tx(struct net_pkt *pkt)
|
||||||
* later processing
|
* later processing
|
||||||
*/
|
*/
|
||||||
static int wpanusb_vendor_handler(struct usb_setup_packet *setup,
|
static int wpanusb_vendor_handler(struct usb_setup_packet *setup,
|
||||||
int32_t *len, uint8_t **data)
|
s32_t *len, u8_t **data)
|
||||||
{
|
{
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *buf;
|
struct net_buf *buf;
|
||||||
|
@ -417,7 +417,7 @@ static void tx_thread(void)
|
||||||
SYS_LOG_DBG("Tx thread started");
|
SYS_LOG_DBG("Tx thread started");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
uint8_t cmd;
|
u8_t cmd;
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *buf;
|
struct net_buf *buf;
|
||||||
|
|
||||||
|
@ -464,7 +464,7 @@ static void tx_thread(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: FIXME: correct buffer size */
|
/* TODO: FIXME: correct buffer size */
|
||||||
static uint8_t buffer[300];
|
static u8_t buffer[300];
|
||||||
|
|
||||||
static struct usb_cfg_data wpanusb_config = {
|
static struct usb_cfg_data wpanusb_config = {
|
||||||
.usb_device_description = wpanusb_desc,
|
.usb_device_description = wpanusb_desc,
|
||||||
|
|
|
@ -23,18 +23,18 @@ enum wpanusb_requests {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct set_channel {
|
struct set_channel {
|
||||||
uint8_t page;
|
u8_t page;
|
||||||
uint8_t channel;
|
u8_t channel;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct set_short_addr {
|
struct set_short_addr {
|
||||||
uint16_t short_addr;
|
u16_t short_addr;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct set_pan_id {
|
struct set_pan_id {
|
||||||
uint16_t pan_id;
|
u16_t pan_id;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
struct set_ieee_addr {
|
struct set_ieee_addr {
|
||||||
uint64_t ieee_addr;
|
u64_t ieee_addr;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
|
@ -46,7 +46,7 @@ static struct net_mgmt_event_callback cb;
|
||||||
|
|
||||||
static const char * const test_path[] = { "test", NULL };
|
static const char * const test_path[] = { "test", NULL };
|
||||||
|
|
||||||
static void msg_dump(const char *s, uint8_t *data, unsigned len)
|
static void msg_dump(const char *s, u8_t *data, unsigned len)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ static void retransmit_request(struct k_work *work)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void event_iface_up(struct net_mgmt_event_callback *cb,
|
static void event_iface_up(struct net_mgmt_event_callback *cb,
|
||||||
uint32_t mgmt_event, struct net_if *iface)
|
u32_t mgmt_event, struct net_if *iface)
|
||||||
{
|
{
|
||||||
static struct sockaddr_in6 any_addr = { .sin6_addr = IN6ADDR_ANY_INIT,
|
static struct sockaddr_in6 any_addr = { .sin6_addr = IN6ADDR_ANY_INIT,
|
||||||
.sin6_family = AF_INET6 };
|
.sin6_family = AF_INET6 };
|
||||||
|
@ -145,7 +145,7 @@ static void event_iface_up(struct net_mgmt_event_callback *cb,
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
int r;
|
int r;
|
||||||
uint8_t observe = 0;
|
u8_t observe = 0;
|
||||||
|
|
||||||
r = net_context_get(PF_INET6, SOCK_DGRAM, IPPROTO_UDP, &context);
|
r = net_context_get(PF_INET6, SOCK_DGRAM, IPPROTO_UDP, &context);
|
||||||
if (r) {
|
if (r) {
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
|
|
||||||
static struct net_context *context;
|
static struct net_context *context;
|
||||||
|
|
||||||
static const uint8_t plain_text_format;
|
static const u8_t plain_text_format;
|
||||||
|
|
||||||
static struct zoap_observer observers[NUM_OBSERVERS];
|
static struct zoap_observer observers[NUM_OBSERVERS];
|
||||||
|
|
||||||
|
@ -75,9 +75,9 @@ static int test_del(struct zoap_resource *resource,
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
uint8_t tkl, code, type;
|
u8_t tkl, code, type;
|
||||||
const uint8_t *token;
|
const u8_t *token;
|
||||||
uint16_t id;
|
u16_t id;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
code = zoap_header_get_code(request);
|
code = zoap_header_get_code(request);
|
||||||
|
@ -123,9 +123,9 @@ static int test_put(struct zoap_resource *resource,
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
uint8_t *payload, code, type, tkl;
|
u8_t *payload, code, type, tkl;
|
||||||
const uint8_t *token;
|
const u8_t *token;
|
||||||
uint16_t len, id;
|
u16_t len, id;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
payload = zoap_packet_get_payload(request, &len);
|
payload = zoap_packet_get_payload(request, &len);
|
||||||
|
@ -181,9 +181,9 @@ static int test_post(struct zoap_resource *resource,
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
uint8_t *payload, code, type, tkl;
|
u8_t *payload, code, type, tkl;
|
||||||
const uint8_t *token;
|
const u8_t *token;
|
||||||
uint16_t len, id;
|
u16_t len, id;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
payload = zoap_packet_get_payload(request, &len);
|
payload = zoap_packet_get_payload(request, &len);
|
||||||
|
@ -244,9 +244,9 @@ static int location_query_post(struct zoap_resource *resource,
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
uint8_t *payload, code, type, tkl;
|
u8_t *payload, code, type, tkl;
|
||||||
const uint8_t *token;
|
const u8_t *token;
|
||||||
uint16_t len, id;
|
u16_t len, id;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
payload = zoap_packet_get_payload(request, &len);
|
payload = zoap_packet_get_payload(request, &len);
|
||||||
|
@ -303,10 +303,10 @@ static int piggyback_get(struct zoap_resource *resource,
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
const uint8_t *token;
|
const u8_t *token;
|
||||||
uint8_t *payload, code, type;
|
u8_t *payload, code, type;
|
||||||
uint16_t len, id;
|
u16_t len, id;
|
||||||
uint8_t tkl;
|
u8_t tkl;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
code = zoap_header_get_code(request);
|
code = zoap_header_get_code(request);
|
||||||
|
@ -377,9 +377,9 @@ static int query_get(struct zoap_resource *resource,
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
uint8_t *payload, code, type, tkl;
|
u8_t *payload, code, type, tkl;
|
||||||
const uint8_t *token;
|
const u8_t *token;
|
||||||
uint16_t len, id;
|
u16_t len, id;
|
||||||
int i, r;
|
int i, r;
|
||||||
|
|
||||||
code = zoap_header_get_code(request);
|
code = zoap_header_get_code(request);
|
||||||
|
@ -466,9 +466,9 @@ static int separate_get(struct zoap_resource *resource,
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
struct zoap_pending *pending;
|
struct zoap_pending *pending;
|
||||||
uint8_t *payload, code, type, tkl;
|
u8_t *payload, code, type, tkl;
|
||||||
const uint8_t *token;
|
const u8_t *token;
|
||||||
uint16_t len, id;
|
u16_t len, id;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
code = zoap_header_get_code(request);
|
code = zoap_header_get_code(request);
|
||||||
|
@ -583,10 +583,10 @@ static int large_get(struct zoap_resource *resource,
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
const uint8_t *token;
|
const u8_t *token;
|
||||||
uint8_t *payload, code, type;
|
u8_t *payload, code, type;
|
||||||
uint16_t len, id, size;
|
u16_t len, id, size;
|
||||||
uint8_t tkl;
|
u8_t tkl;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (ctx.total_size == 0) {
|
if (ctx.total_size == 0) {
|
||||||
|
@ -673,10 +673,10 @@ static int large_update_put(struct zoap_resource *resource,
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
const uint8_t *token;
|
const u8_t *token;
|
||||||
uint8_t *payload, code, type;
|
u8_t *payload, code, type;
|
||||||
uint16_t len, id;
|
u16_t len, id;
|
||||||
uint8_t tkl;
|
u8_t tkl;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (ctx.total_size == 0) {
|
if (ctx.total_size == 0) {
|
||||||
|
@ -753,10 +753,10 @@ static int large_create_post(struct zoap_resource *resource,
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
const uint8_t *token;
|
const u8_t *token;
|
||||||
uint8_t *payload, code, type;
|
u8_t *payload, code, type;
|
||||||
uint16_t len, id;
|
u16_t len, id;
|
||||||
uint8_t tkl;
|
u8_t tkl;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
if (ctx.total_size == 0) {
|
if (ctx.total_size == 0) {
|
||||||
|
@ -827,17 +827,17 @@ static void update_counter(struct k_work *work)
|
||||||
k_delayed_work_submit(&observer_work, 5 * MSEC_PER_SEC);
|
k_delayed_work_submit(&observer_work, 5 * MSEC_PER_SEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int send_notification_packet(const struct sockaddr *addr, uint16_t age,
|
static int send_notification_packet(const struct sockaddr *addr, u16_t age,
|
||||||
socklen_t addrlen, uint16_t id,
|
socklen_t addrlen, u16_t id,
|
||||||
const uint8_t *token, uint8_t tkl,
|
const u8_t *token, u8_t tkl,
|
||||||
bool is_response)
|
bool is_response)
|
||||||
{
|
{
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
struct zoap_pending *pending;
|
struct zoap_pending *pending;
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
uint8_t *payload, type = ZOAP_TYPE_CON;
|
u8_t *payload, type = ZOAP_TYPE_CON;
|
||||||
uint16_t len;
|
u16_t len;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
pkt = net_pkt_get_tx(context, K_FOREVER);
|
pkt = net_pkt_get_tx(context, K_FOREVER);
|
||||||
|
@ -918,10 +918,10 @@ static int obs_get(struct zoap_resource *resource,
|
||||||
const struct sockaddr *from)
|
const struct sockaddr *from)
|
||||||
{
|
{
|
||||||
struct zoap_observer *observer;
|
struct zoap_observer *observer;
|
||||||
const uint8_t *token;
|
const u8_t *token;
|
||||||
uint8_t code, type;
|
u8_t code, type;
|
||||||
uint16_t id;
|
u16_t id;
|
||||||
uint8_t tkl;
|
u8_t tkl;
|
||||||
bool observe = true;
|
bool observe = true;
|
||||||
|
|
||||||
if (!zoap_request_is_observe(request)) {
|
if (!zoap_request_is_observe(request)) {
|
||||||
|
@ -971,9 +971,9 @@ static int core_get(struct zoap_resource *resource,
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct zoap_packet response;
|
struct zoap_packet response;
|
||||||
uint8_t *payload, tkl;
|
u8_t *payload, tkl;
|
||||||
const uint8_t *token;
|
const u8_t *token;
|
||||||
uint16_t len, id;
|
u16_t len, id;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
id = zoap_header_get_id(request);
|
id = zoap_header_get_id(request);
|
||||||
|
|
|
@ -14,19 +14,19 @@
|
||||||
|
|
||||||
#include "shell_utils.h"
|
#include "shell_utils.h"
|
||||||
|
|
||||||
const uint32_t TIME_US[] = { 60 * 1000 * 1000, 1000 * 1000, 1000, 0 };
|
const u32_t TIME_US[] = { 60 * 1000 * 1000, 1000 * 1000, 1000, 0 };
|
||||||
const char *TIME_US_UNIT[] = { "m", "s", "ms", "us" };
|
const char *TIME_US_UNIT[] = { "m", "s", "ms", "us" };
|
||||||
const uint32_t KBPS[] = { 1024, 0 };
|
const u32_t KBPS[] = { 1024, 0 };
|
||||||
const char *KBPS_UNIT[] = { "Mbps", "Kbps" };
|
const char *KBPS_UNIT[] = { "Mbps", "Kbps" };
|
||||||
const uint32_t K[] = { 1024 * 1024, 1024, 0 };
|
const u32_t K[] = { 1024 * 1024, 1024, 0 };
|
||||||
const char *K_UNIT[] = { "M", "K", "" };
|
const char *K_UNIT[] = { "M", "K", "" };
|
||||||
|
|
||||||
void print_number(uint32_t value, const uint32_t *divisor,
|
void print_number(u32_t value, const u32_t *divisor,
|
||||||
const char **units)
|
const char **units)
|
||||||
{
|
{
|
||||||
const char **unit;
|
const char **unit;
|
||||||
const uint32_t *div;
|
const u32_t *div;
|
||||||
uint32_t dec, radix;
|
u32_t dec, radix;
|
||||||
|
|
||||||
unit = units;
|
unit = units;
|
||||||
div = divisor;
|
div = divisor;
|
||||||
|
@ -45,11 +45,11 @@ void print_number(uint32_t value, const uint32_t *divisor,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long parse_number(const char *string, const uint32_t *divisor,
|
long parse_number(const char *string, const u32_t *divisor,
|
||||||
const char **units)
|
const char **units)
|
||||||
{
|
{
|
||||||
const char **unit;
|
const char **unit;
|
||||||
const uint32_t *div;
|
const u32_t *div;
|
||||||
char *suffix;
|
char *suffix;
|
||||||
long dec;
|
long dec;
|
||||||
int cmp;
|
int cmp;
|
||||||
|
|
|
@ -9,15 +9,15 @@
|
||||||
#define IPV4_STR_LEN_MAX 15
|
#define IPV4_STR_LEN_MAX 15
|
||||||
#define IPV4_STR_LEN_MIN 7
|
#define IPV4_STR_LEN_MIN 7
|
||||||
|
|
||||||
extern const uint32_t TIME_US[];
|
extern const u32_t TIME_US[];
|
||||||
extern const char *TIME_US_UNIT[];
|
extern const char *TIME_US_UNIT[];
|
||||||
extern const uint32_t KBPS[];
|
extern const u32_t KBPS[];
|
||||||
extern const char *KBPS_UNIT[];
|
extern const char *KBPS_UNIT[];
|
||||||
extern const uint32_t K[];
|
extern const u32_t K[];
|
||||||
extern const char *K_UNIT[];
|
extern const char *K_UNIT[];
|
||||||
|
|
||||||
extern void print_number(uint32_t value, const uint32_t *divisor,
|
extern void print_number(u32_t value, const u32_t *divisor,
|
||||||
const char **units);
|
const char **units);
|
||||||
extern long parse_number(const char *string, const uint32_t *divisor,
|
extern long parse_number(const char *string, const u32_t *divisor,
|
||||||
const char **units);
|
const char **units);
|
||||||
#endif /* __SHELL_UTILS_H */
|
#endif /* __SHELL_UTILS_H */
|
||||||
|
|
|
@ -20,16 +20,16 @@
|
||||||
#define CMD_STR_TCP_DOWNLOAD "tcp.download"
|
#define CMD_STR_TCP_DOWNLOAD "tcp.download"
|
||||||
|
|
||||||
struct zperf_results {
|
struct zperf_results {
|
||||||
uint32_t nb_packets_sent;
|
u32_t nb_packets_sent;
|
||||||
uint32_t nb_packets_rcvd;
|
u32_t nb_packets_rcvd;
|
||||||
uint32_t nb_packets_lost;
|
u32_t nb_packets_lost;
|
||||||
uint32_t nb_packets_outorder;
|
u32_t nb_packets_outorder;
|
||||||
uint32_t nb_bytes_sent;
|
u32_t nb_bytes_sent;
|
||||||
uint32_t time_in_us;
|
u32_t time_in_us;
|
||||||
uint32_t jitter_in_us;
|
u32_t jitter_in_us;
|
||||||
uint32_t client_time_in_us;
|
u32_t client_time_in_us;
|
||||||
uint32_t packet_size;
|
u32_t packet_size;
|
||||||
uint32_t nb_packets_errors;
|
u32_t nb_packets_errors;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*zperf_callback)(int status, struct zperf_results *);
|
typedef void (*zperf_callback)(int status, struct zperf_results *);
|
||||||
|
|
|
@ -30,50 +30,50 @@
|
||||||
|
|
||||||
#define HW_CYCLES_TO_USEC(__hw_cycle__) \
|
#define HW_CYCLES_TO_USEC(__hw_cycle__) \
|
||||||
( \
|
( \
|
||||||
((uint64_t)(__hw_cycle__) * (uint64_t)sys_clock_us_per_tick) / \
|
((u64_t)(__hw_cycle__) * (u64_t)sys_clock_us_per_tick) / \
|
||||||
((uint64_t)sys_clock_hw_cycles_per_tick) \
|
((u64_t)sys_clock_hw_cycles_per_tick) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define HW_CYCLES_TO_SEC(__hw_cycle__) \
|
#define HW_CYCLES_TO_SEC(__hw_cycle__) \
|
||||||
( \
|
( \
|
||||||
((uint64_t)(HW_CYCLES_TO_USEC(__hw_cycle__))) / \
|
((u64_t)(HW_CYCLES_TO_USEC(__hw_cycle__))) / \
|
||||||
((uint64_t)USEC_PER_SEC) \
|
((u64_t)USEC_PER_SEC) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define USEC_TO_HW_CYCLES(__usec__) \
|
#define USEC_TO_HW_CYCLES(__usec__) \
|
||||||
( \
|
( \
|
||||||
((uint64_t)(__usec__) * (uint64_t)sys_clock_hw_cycles_per_tick) / \
|
((u64_t)(__usec__) * (u64_t)sys_clock_hw_cycles_per_tick) / \
|
||||||
((uint64_t)sys_clock_us_per_tick) \
|
((u64_t)sys_clock_us_per_tick) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define SEC_TO_HW_CYCLES(__sec__) \
|
#define SEC_TO_HW_CYCLES(__sec__) \
|
||||||
USEC_TO_HW_CYCLES((uint64_t)(__sec__) * \
|
USEC_TO_HW_CYCLES((u64_t)(__sec__) * \
|
||||||
(uint64_t)USEC_PER_SEC)
|
(u64_t)USEC_PER_SEC)
|
||||||
|
|
||||||
#define MSEC_TO_HW_CYCLES(__msec__) \
|
#define MSEC_TO_HW_CYCLES(__msec__) \
|
||||||
USEC_TO_HW_CYCLES((uint64_t)(__msec__) * \
|
USEC_TO_HW_CYCLES((u64_t)(__msec__) * \
|
||||||
(uint64_t)MSEC_PER_SEC)
|
(u64_t)MSEC_PER_SEC)
|
||||||
|
|
||||||
struct zperf_udp_datagram {
|
struct zperf_udp_datagram {
|
||||||
int32_t id;
|
s32_t id;
|
||||||
uint32_t tv_sec;
|
u32_t tv_sec;
|
||||||
uint32_t tv_usec;
|
u32_t tv_usec;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct zperf_server_hdr {
|
struct zperf_server_hdr {
|
||||||
int32_t flags;
|
s32_t flags;
|
||||||
int32_t total_len1;
|
s32_t total_len1;
|
||||||
int32_t total_len2;
|
s32_t total_len2;
|
||||||
int32_t stop_sec;
|
s32_t stop_sec;
|
||||||
int32_t stop_usec;
|
s32_t stop_usec;
|
||||||
int32_t error_cnt;
|
s32_t error_cnt;
|
||||||
int32_t outorder_cnt;
|
s32_t outorder_cnt;
|
||||||
int32_t datagrams;
|
s32_t datagrams;
|
||||||
int32_t jitter1;
|
s32_t jitter1;
|
||||||
int32_t jitter2;
|
s32_t jitter2;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline uint32_t time_delta(uint32_t ts, uint32_t t)
|
static inline u32_t time_delta(u32_t ts, u32_t t)
|
||||||
{
|
{
|
||||||
return (t >= ts) ? (t - ts) : (ULONG_MAX - ts + t);
|
return (t >= ts) ? (t - ts) : (ULONG_MAX - ts + t);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ struct session *get_session(struct net_pkt *pkt, enum session_proto proto)
|
||||||
struct in6_addr ipv6 = { };
|
struct in6_addr ipv6 = { };
|
||||||
struct in_addr ipv4 = { };
|
struct in_addr ipv4 = { };
|
||||||
int i = 0;
|
int i = 0;
|
||||||
uint16_t port;
|
u16_t port;
|
||||||
|
|
||||||
if (!pkt) {
|
if (!pkt) {
|
||||||
printk("Error! null pkt detected.\n");
|
printk("Error! null pkt detected.\n");
|
||||||
|
|
|
@ -35,22 +35,22 @@ enum session_proto {
|
||||||
|
|
||||||
struct session {
|
struct session {
|
||||||
/* Tuple */
|
/* Tuple */
|
||||||
uint16_t port;
|
u16_t port;
|
||||||
|
|
||||||
struct net_addr ip;
|
struct net_addr ip;
|
||||||
|
|
||||||
enum state state;
|
enum state state;
|
||||||
|
|
||||||
/* Stat data */
|
/* Stat data */
|
||||||
uint32_t counter;
|
u32_t counter;
|
||||||
uint32_t next_id;
|
u32_t next_id;
|
||||||
uint32_t outorder;
|
u32_t outorder;
|
||||||
uint32_t error;
|
u32_t error;
|
||||||
uint64_t length;
|
u64_t length;
|
||||||
uint32_t start_time;
|
u32_t start_time;
|
||||||
uint32_t last_time;
|
u32_t last_time;
|
||||||
int32_t jitter;
|
s32_t jitter;
|
||||||
int32_t last_transit_time;
|
s32_t last_transit_time;
|
||||||
|
|
||||||
/* Stats packet*/
|
/* Stats packet*/
|
||||||
struct zperf_server_hdr stat;
|
struct zperf_server_hdr stat;
|
||||||
|
|
|
@ -442,20 +442,20 @@ static void shell_udp_upload_print_stats(struct zperf_results *results)
|
||||||
printk("[%s] Upload completed!\n", CMD_STR_UDP_UPLOAD);
|
printk("[%s] Upload completed!\n", CMD_STR_UDP_UPLOAD);
|
||||||
|
|
||||||
if (results->time_in_us != 0) {
|
if (results->time_in_us != 0) {
|
||||||
rate_in_kbps = (uint32_t)
|
rate_in_kbps = (u32_t)
|
||||||
(((uint64_t)results->nb_bytes_sent *
|
(((u64_t)results->nb_bytes_sent *
|
||||||
(uint64_t)8 * (uint64_t)USEC_PER_SEC) /
|
(u64_t)8 * (u64_t)USEC_PER_SEC) /
|
||||||
((uint64_t)results->time_in_us * 1024));
|
((u64_t)results->time_in_us * 1024));
|
||||||
} else {
|
} else {
|
||||||
rate_in_kbps = 0;
|
rate_in_kbps = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (results->client_time_in_us != 0) {
|
if (results->client_time_in_us != 0) {
|
||||||
client_rate_in_kbps = (uint32_t)
|
client_rate_in_kbps = (u32_t)
|
||||||
(((uint64_t)results->nb_packets_sent *
|
(((u64_t)results->nb_packets_sent *
|
||||||
(uint64_t)results->packet_size * (uint64_t)8 *
|
(u64_t)results->packet_size * (u64_t)8 *
|
||||||
(uint64_t)USEC_PER_SEC) /
|
(u64_t)USEC_PER_SEC) /
|
||||||
((uint64_t)results->client_time_in_us * 1024));
|
((u64_t)results->client_time_in_us * 1024));
|
||||||
} else {
|
} else {
|
||||||
client_rate_in_kbps = 0;
|
client_rate_in_kbps = 0;
|
||||||
}
|
}
|
||||||
|
@ -501,11 +501,11 @@ static void shell_tcp_upload_print_stats(struct zperf_results *results)
|
||||||
printk("[%s] Upload completed!\n", CMD_STR_TCP_UPLOAD);
|
printk("[%s] Upload completed!\n", CMD_STR_TCP_UPLOAD);
|
||||||
|
|
||||||
if (results->client_time_in_us != 0) {
|
if (results->client_time_in_us != 0) {
|
||||||
client_rate_in_kbps = (uint32_t)
|
client_rate_in_kbps = (u32_t)
|
||||||
(((uint64_t)results->nb_packets_sent *
|
(((u64_t)results->nb_packets_sent *
|
||||||
(uint64_t)results->packet_size * (uint64_t)8 *
|
(u64_t)results->packet_size * (u64_t)8 *
|
||||||
(uint64_t)USEC_PER_SEC) /
|
(u64_t)USEC_PER_SEC) /
|
||||||
((uint64_t)results->client_time_in_us * 1024));
|
((u64_t)results->client_time_in_us * 1024));
|
||||||
} else {
|
} else {
|
||||||
client_rate_in_kbps = 0;
|
client_rate_in_kbps = 0;
|
||||||
}
|
}
|
||||||
|
@ -741,7 +741,7 @@ static int shell_cmd_upload(int argc, char *argv[])
|
||||||
struct net_context *context6 = NULL, *context4 = NULL;
|
struct net_context *context6 = NULL, *context4 = NULL;
|
||||||
sa_family_t family = AF_UNSPEC;
|
sa_family_t family = AF_UNSPEC;
|
||||||
unsigned int duration_in_ms, packet_size, rate_in_kbps;
|
unsigned int duration_in_ms, packet_size, rate_in_kbps;
|
||||||
uint16_t port;
|
u16_t port;
|
||||||
bool is_udp;
|
bool is_udp;
|
||||||
int start = 0;
|
int start = 0;
|
||||||
|
|
||||||
|
@ -857,10 +857,10 @@ static int shell_cmd_upload(int argc, char *argv[])
|
||||||
static int shell_cmd_upload2(int argc, char *argv[])
|
static int shell_cmd_upload2(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct net_context *context6 = NULL, *context4 = NULL;
|
struct net_context *context6 = NULL, *context4 = NULL;
|
||||||
uint16_t port = DEF_PORT;
|
u16_t port = DEF_PORT;
|
||||||
unsigned int duration_in_ms, packet_size, rate_in_kbps;
|
unsigned int duration_in_ms, packet_size, rate_in_kbps;
|
||||||
sa_family_t family;
|
sa_family_t family;
|
||||||
uint8_t is_udp;
|
u8_t is_udp;
|
||||||
int start = 0;
|
int start = 0;
|
||||||
|
|
||||||
if (!strcmp(argv[0], "zperf")) {
|
if (!strcmp(argv[0], "zperf")) {
|
||||||
|
|
|
@ -43,7 +43,7 @@ static void tcp_received(struct net_context *context,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
struct session *session;
|
struct session *session;
|
||||||
uint32_t time;
|
u32_t time;
|
||||||
|
|
||||||
if (!pkt) {
|
if (!pkt) {
|
||||||
return;
|
return;
|
||||||
|
@ -73,19 +73,19 @@ static void tcp_received(struct net_context *context,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pkt && status == 0) { /* EOF */
|
if (!pkt && status == 0) { /* EOF */
|
||||||
uint32_t rate_in_kbps;
|
u32_t rate_in_kbps;
|
||||||
uint32_t duration = HW_CYCLES_TO_USEC(
|
u32_t duration = HW_CYCLES_TO_USEC(
|
||||||
time_delta(session->start_time, time));
|
time_delta(session->start_time, time));
|
||||||
|
|
||||||
session->state = STATE_COMPLETED;
|
session->state = STATE_COMPLETED;
|
||||||
|
|
||||||
/* Compute baud rate */
|
/* Compute baud rate */
|
||||||
if (duration != 0) {
|
if (duration != 0) {
|
||||||
rate_in_kbps = (uint32_t)
|
rate_in_kbps = (u32_t)
|
||||||
(((uint64_t)session->length *
|
(((u64_t)session->length *
|
||||||
(uint64_t)8 *
|
(u64_t)8 *
|
||||||
(uint64_t)USEC_PER_SEC) /
|
(u64_t)USEC_PER_SEC) /
|
||||||
((uint64_t)duration * 1024));
|
((u64_t)duration * 1024));
|
||||||
} else {
|
} else {
|
||||||
rate_in_kbps = 0;
|
rate_in_kbps = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,10 +25,10 @@ void zperf_tcp_upload(struct net_context *ctx,
|
||||||
unsigned int packet_size,
|
unsigned int packet_size,
|
||||||
struct zperf_results *results)
|
struct zperf_results *results)
|
||||||
{
|
{
|
||||||
uint32_t duration = MSEC_TO_HW_CYCLES(duration_in_ms);
|
u32_t duration = MSEC_TO_HW_CYCLES(duration_in_ms);
|
||||||
uint32_t nb_packets = 0, nb_errors = 0;
|
u32_t nb_packets = 0, nb_errors = 0;
|
||||||
uint32_t start_time, last_print_time, last_loop_time, end_time;
|
u32_t start_time, last_print_time, last_loop_time, end_time;
|
||||||
uint8_t time_elapsed = 0, finished = 0;
|
u8_t time_elapsed = 0, finished = 0;
|
||||||
|
|
||||||
if (packet_size > PACKET_SIZE_MAX) {
|
if (packet_size > PACKET_SIZE_MAX) {
|
||||||
printk(TAG "WARNING! packet size too large! max size: %u\n",
|
printk(TAG "WARNING! packet size too large! max size: %u\n",
|
||||||
|
@ -48,7 +48,7 @@ void zperf_tcp_upload(struct net_context *ctx,
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
uint32_t loop_time;
|
u32_t loop_time;
|
||||||
bool st;
|
bool st;
|
||||||
|
|
||||||
/* Timestamps */
|
/* Timestamps */
|
||||||
|
|
|
@ -128,10 +128,10 @@ static void udp_received(struct net_context *context,
|
||||||
struct net_buf *frag = pkt->frags;
|
struct net_buf *frag = pkt->frags;
|
||||||
struct zperf_udp_datagram hdr;
|
struct zperf_udp_datagram hdr;
|
||||||
struct session *session;
|
struct session *session;
|
||||||
uint16_t offset, pos;
|
u16_t offset, pos;
|
||||||
int32_t transit_time;
|
s32_t transit_time;
|
||||||
uint32_t time;
|
u32_t time;
|
||||||
int32_t id;
|
s32_t id;
|
||||||
|
|
||||||
if (!pkt) {
|
if (!pkt) {
|
||||||
return;
|
return;
|
||||||
|
@ -152,7 +152,7 @@ static void udp_received(struct net_context *context,
|
||||||
|
|
||||||
offset = net_pkt_appdata(pkt) - net_pkt_ip_data(pkt);
|
offset = net_pkt_appdata(pkt) - net_pkt_ip_data(pkt);
|
||||||
|
|
||||||
frag = net_frag_read_be32(frag, offset, &pos, (uint32_t *)&hdr.id);
|
frag = net_frag_read_be32(frag, offset, &pos, (u32_t *)&hdr.id);
|
||||||
frag = net_frag_read_be32(frag, pos, &pos, &hdr.tv_sec);
|
frag = net_frag_read_be32(frag, pos, &pos, &hdr.tv_sec);
|
||||||
frag = net_frag_read_be32(frag, pos, &pos, &hdr.tv_usec);
|
frag = net_frag_read_be32(frag, pos, &pos, &hdr.tv_usec);
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ static void udp_received(struct net_context *context,
|
||||||
hdr.tv_sec * USEC_PER_SEC +
|
hdr.tv_sec * USEC_PER_SEC +
|
||||||
hdr.tv_usec);
|
hdr.tv_usec);
|
||||||
if (session->last_transit_time != 0) {
|
if (session->last_transit_time != 0) {
|
||||||
int32_t delta_transit = transit_time -
|
s32_t delta_transit = transit_time -
|
||||||
session->last_transit_time;
|
session->last_transit_time;
|
||||||
|
|
||||||
delta_transit =
|
delta_transit =
|
||||||
|
@ -221,8 +221,8 @@ static void udp_received(struct net_context *context,
|
||||||
|
|
||||||
/* If necessary send statistics */
|
/* If necessary send statistics */
|
||||||
if (session->state == STATE_LAST_PACKET_RECEIVED) {
|
if (session->state == STATE_LAST_PACKET_RECEIVED) {
|
||||||
uint32_t rate_in_kbps;
|
u32_t rate_in_kbps;
|
||||||
uint32_t duration = HW_CYCLES_TO_USEC(
|
u32_t duration = HW_CYCLES_TO_USEC(
|
||||||
time_delta(session->start_time, time));
|
time_delta(session->start_time, time));
|
||||||
|
|
||||||
/* Update state machine */
|
/* Update state machine */
|
||||||
|
@ -230,10 +230,10 @@ static void udp_received(struct net_context *context,
|
||||||
|
|
||||||
/* Compute baud rate */
|
/* Compute baud rate */
|
||||||
if (duration != 0) {
|
if (duration != 0) {
|
||||||
rate_in_kbps = (uint32_t)
|
rate_in_kbps = (u32_t)
|
||||||
(((uint64_t)session->length * (uint64_t)8 *
|
(((u64_t)session->length * (u64_t)8 *
|
||||||
(uint64_t)USEC_PER_SEC) /
|
(u64_t)USEC_PER_SEC) /
|
||||||
((uint64_t)duration * 1024));
|
((u64_t)duration * 1024));
|
||||||
} else {
|
} else {
|
||||||
rate_in_kbps = 0;
|
rate_in_kbps = 0;
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@ static inline void zperf_upload_decode_stat(struct net_pkt *pkt,
|
||||||
{
|
{
|
||||||
struct net_buf *frag = pkt->frags;
|
struct net_buf *frag = pkt->frags;
|
||||||
struct zperf_server_hdr hdr;
|
struct zperf_server_hdr hdr;
|
||||||
uint16_t offset;
|
u16_t offset;
|
||||||
uint16_t pos;
|
u16_t pos;
|
||||||
|
|
||||||
offset = net_pkt_udp_data(pkt) - net_pkt_ip_data(pkt);
|
offset = net_pkt_udp_data(pkt) - net_pkt_ip_data(pkt);
|
||||||
offset += sizeof(struct net_udp_hdr) +
|
offset += sizeof(struct net_udp_hdr) +
|
||||||
|
@ -42,17 +42,17 @@ static inline void zperf_upload_decode_stat(struct net_pkt *pkt,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
frag = net_frag_read_be32(frag, offset, &pos, (uint32_t *)&hdr.flags);
|
frag = net_frag_read_be32(frag, offset, &pos, (u32_t *)&hdr.flags);
|
||||||
frag = net_frag_read_be32(frag, pos, &pos, (uint32_t *)&hdr.total_len1);
|
frag = net_frag_read_be32(frag, pos, &pos, (u32_t *)&hdr.total_len1);
|
||||||
frag = net_frag_read_be32(frag, pos, &pos, (uint32_t *)&hdr.total_len2);
|
frag = net_frag_read_be32(frag, pos, &pos, (u32_t *)&hdr.total_len2);
|
||||||
frag = net_frag_read_be32(frag, pos, &pos, (uint32_t *)&hdr.stop_sec);
|
frag = net_frag_read_be32(frag, pos, &pos, (u32_t *)&hdr.stop_sec);
|
||||||
frag = net_frag_read_be32(frag, pos, &pos, (uint32_t *)&hdr.stop_usec);
|
frag = net_frag_read_be32(frag, pos, &pos, (u32_t *)&hdr.stop_usec);
|
||||||
frag = net_frag_read_be32(frag, pos, &pos, (uint32_t *)&hdr.error_cnt);
|
frag = net_frag_read_be32(frag, pos, &pos, (u32_t *)&hdr.error_cnt);
|
||||||
frag = net_frag_read_be32(frag, pos, &pos,
|
frag = net_frag_read_be32(frag, pos, &pos,
|
||||||
(uint32_t *)&hdr.outorder_cnt);
|
(u32_t *)&hdr.outorder_cnt);
|
||||||
frag = net_frag_read_be32(frag, pos, &pos, (uint32_t *)&hdr.datagrams);
|
frag = net_frag_read_be32(frag, pos, &pos, (u32_t *)&hdr.datagrams);
|
||||||
frag = net_frag_read_be32(frag, pos, &pos, (uint32_t *)&hdr.jitter1);
|
frag = net_frag_read_be32(frag, pos, &pos, (u32_t *)&hdr.jitter1);
|
||||||
frag = net_frag_read_be32(frag, pos, &pos, (uint32_t *)&hdr.jitter2);
|
frag = net_frag_read_be32(frag, pos, &pos, (u32_t *)&hdr.jitter2);
|
||||||
|
|
||||||
results->nb_packets_rcvd = hdr.datagrams;
|
results->nb_packets_rcvd = hdr.datagrams;
|
||||||
results->nb_packets_lost = hdr.error_cnt;
|
results->nb_packets_lost = hdr.error_cnt;
|
||||||
|
@ -73,9 +73,9 @@ static void stat_received(struct net_context *context,
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void zperf_upload_fin(struct net_context *context,
|
static inline void zperf_upload_fin(struct net_context *context,
|
||||||
uint32_t nb_packets,
|
u32_t nb_packets,
|
||||||
uint32_t end_time,
|
u32_t end_time,
|
||||||
uint32_t packet_size,
|
u32_t packet_size,
|
||||||
struct zperf_results *results)
|
struct zperf_results *results)
|
||||||
{
|
{
|
||||||
struct net_pkt *stat = NULL;
|
struct net_pkt *stat = NULL;
|
||||||
|
@ -109,7 +109,7 @@ static inline void zperf_upload_fin(struct net_context *context,
|
||||||
USEC_PER_SEC);
|
USEC_PER_SEC);
|
||||||
|
|
||||||
status = net_pkt_append(pkt, sizeof(datagram),
|
status = net_pkt_append(pkt, sizeof(datagram),
|
||||||
(uint8_t *)&datagram, K_FOREVER);
|
(u8_t *)&datagram, K_FOREVER);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
printk(TAG "ERROR! Cannot append datagram data\n");
|
printk(TAG "ERROR! Cannot append datagram data\n");
|
||||||
break;
|
break;
|
||||||
|
@ -119,12 +119,12 @@ static inline void zperf_upload_fin(struct net_context *context,
|
||||||
if (packet_size > sizeof(struct zperf_udp_datagram)) {
|
if (packet_size > sizeof(struct zperf_udp_datagram)) {
|
||||||
int size = packet_size -
|
int size = packet_size -
|
||||||
sizeof(struct zperf_udp_datagram);
|
sizeof(struct zperf_udp_datagram);
|
||||||
uint16_t pos;
|
u16_t pos;
|
||||||
|
|
||||||
frag = net_pkt_write(pkt, net_buf_frag_last(pkt->frags),
|
frag = net_pkt_write(pkt, net_buf_frag_last(pkt->frags),
|
||||||
sizeof(struct zperf_udp_datagram),
|
sizeof(struct zperf_udp_datagram),
|
||||||
&pos, size,
|
&pos, size,
|
||||||
(uint8_t *)sample_packet,
|
(u8_t *)sample_packet,
|
||||||
K_FOREVER);
|
K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,14 +178,14 @@ void zperf_udp_upload(struct net_context *context,
|
||||||
unsigned int rate_in_kbps,
|
unsigned int rate_in_kbps,
|
||||||
struct zperf_results *results)
|
struct zperf_results *results)
|
||||||
{
|
{
|
||||||
uint32_t packet_duration = (uint32_t)(((uint64_t) packet_size *
|
u32_t packet_duration = (u32_t)(((u64_t) packet_size *
|
||||||
SEC_TO_HW_CYCLES(1) * 8) /
|
SEC_TO_HW_CYCLES(1) * 8) /
|
||||||
(uint64_t)(rate_in_kbps * 1024));
|
(u64_t)(rate_in_kbps * 1024));
|
||||||
uint32_t duration = MSEC_TO_HW_CYCLES(duration_in_ms);
|
u32_t duration = MSEC_TO_HW_CYCLES(duration_in_ms);
|
||||||
uint32_t print_interval = SEC_TO_HW_CYCLES(1);
|
u32_t print_interval = SEC_TO_HW_CYCLES(1);
|
||||||
uint32_t delay = packet_duration;
|
u32_t delay = packet_duration;
|
||||||
uint32_t nb_packets = 0;
|
u32_t nb_packets = 0;
|
||||||
uint32_t start_time, last_print_time, last_loop_time, end_time;
|
u32_t start_time, last_print_time, last_loop_time, end_time;
|
||||||
|
|
||||||
if (packet_size > PACKET_SIZE_MAX) {
|
if (packet_size > PACKET_SIZE_MAX) {
|
||||||
printk(TAG "WARNING! packet size too large! max size: %u\n",
|
printk(TAG "WARNING! packet size too large! max size: %u\n",
|
||||||
|
@ -208,8 +208,8 @@ void zperf_udp_upload(struct net_context *context,
|
||||||
struct zperf_udp_datagram datagram;
|
struct zperf_udp_datagram datagram;
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
uint32_t loop_time;
|
u32_t loop_time;
|
||||||
int32_t adjust;
|
s32_t adjust;
|
||||||
bool status;
|
bool status;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -255,7 +255,7 @@ void zperf_udp_upload(struct net_context *context,
|
||||||
htonl(HW_CYCLES_TO_USEC(loop_time) % USEC_PER_SEC);
|
htonl(HW_CYCLES_TO_USEC(loop_time) % USEC_PER_SEC);
|
||||||
|
|
||||||
status = net_pkt_append(pkt, sizeof(datagram),
|
status = net_pkt_append(pkt, sizeof(datagram),
|
||||||
(uint8_t *)&datagram, K_FOREVER);
|
(u8_t *)&datagram, K_FOREVER);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
printk(TAG "ERROR! Cannot append datagram data\n");
|
printk(TAG "ERROR! Cannot append datagram data\n");
|
||||||
break;
|
break;
|
||||||
|
@ -265,7 +265,7 @@ void zperf_udp_upload(struct net_context *context,
|
||||||
if (packet_size > sizeof(struct zperf_udp_datagram)) {
|
if (packet_size > sizeof(struct zperf_udp_datagram)) {
|
||||||
int size = packet_size -
|
int size = packet_size -
|
||||||
sizeof(struct zperf_udp_datagram);
|
sizeof(struct zperf_udp_datagram);
|
||||||
uint16_t pos;
|
u16_t pos;
|
||||||
|
|
||||||
frag = net_pkt_write(pkt, net_buf_frag_last(pkt->frags),
|
frag = net_pkt_write(pkt, net_buf_frag_last(pkt->frags),
|
||||||
sizeof(struct zperf_udp_datagram),
|
sizeof(struct zperf_udp_datagram),
|
||||||
|
|
|
@ -48,11 +48,11 @@
|
||||||
#define BUF_SIZE(pool) (sizeof(struct net_buf) + \
|
#define BUF_SIZE(pool) (sizeof(struct net_buf) + \
|
||||||
ROUND_UP(pool->buf_size, 4) + \
|
ROUND_UP(pool->buf_size, 4) + \
|
||||||
ROUND_UP(pool->user_data_size, 4))
|
ROUND_UP(pool->user_data_size, 4))
|
||||||
#define UNINIT_BUF(pool, n) (struct net_buf *)(((uint8_t *)(pool->__bufs)) + \
|
#define UNINIT_BUF(pool, n) (struct net_buf *)(((u8_t *)(pool->__bufs)) + \
|
||||||
((n) * BUF_SIZE(pool)))
|
((n) * BUF_SIZE(pool)))
|
||||||
|
|
||||||
static inline struct net_buf *pool_get_uninit(struct net_buf_pool *pool,
|
static inline struct net_buf *pool_get_uninit(struct net_buf_pool *pool,
|
||||||
uint16_t uninit_count)
|
u16_t uninit_count)
|
||||||
{
|
{
|
||||||
struct net_buf *buf;
|
struct net_buf *buf;
|
||||||
|
|
||||||
|
@ -74,10 +74,10 @@ void net_buf_reset(struct net_buf *buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NET_BUF_LOG)
|
#if defined(CONFIG_NET_BUF_LOG)
|
||||||
struct net_buf *net_buf_alloc_debug(struct net_buf_pool *pool, int32_t timeout,
|
struct net_buf *net_buf_alloc_debug(struct net_buf_pool *pool, s32_t timeout,
|
||||||
const char *func, int line)
|
const char *func, int line)
|
||||||
#else
|
#else
|
||||||
struct net_buf *net_buf_alloc(struct net_buf_pool *pool, int32_t timeout)
|
struct net_buf *net_buf_alloc(struct net_buf_pool *pool, s32_t timeout)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
struct net_buf *buf;
|
struct net_buf *buf;
|
||||||
|
@ -96,7 +96,7 @@ struct net_buf *net_buf_alloc(struct net_buf_pool *pool, int32_t timeout)
|
||||||
* with the allocation one way or another.
|
* with the allocation one way or another.
|
||||||
*/
|
*/
|
||||||
if (pool->uninit_count) {
|
if (pool->uninit_count) {
|
||||||
uint16_t uninit_count;
|
u16_t uninit_count;
|
||||||
|
|
||||||
/* If this is not the first access to the pool, we can
|
/* If this is not the first access to the pool, we can
|
||||||
* be opportunistic and try to fetch a previously used
|
* be opportunistic and try to fetch a previously used
|
||||||
|
@ -121,7 +121,7 @@ struct net_buf *net_buf_alloc(struct net_buf_pool *pool, int32_t timeout)
|
||||||
|
|
||||||
#if defined(CONFIG_NET_BUF_LOG) && SYS_LOG_LEVEL >= SYS_LOG_LEVEL_WARNING
|
#if defined(CONFIG_NET_BUF_LOG) && SYS_LOG_LEVEL >= SYS_LOG_LEVEL_WARNING
|
||||||
if (timeout == K_FOREVER) {
|
if (timeout == K_FOREVER) {
|
||||||
uint32_t ref = k_uptime_get_32();
|
u32_t ref = k_uptime_get_32();
|
||||||
buf = k_lifo_get(&pool->free, K_NO_WAIT);
|
buf = k_lifo_get(&pool->free, K_NO_WAIT);
|
||||||
while (!buf) {
|
while (!buf) {
|
||||||
#if defined(CONFIG_NET_BUF_POOL_USAGE)
|
#if defined(CONFIG_NET_BUF_POOL_USAGE)
|
||||||
|
@ -170,10 +170,10 @@ success:
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NET_BUF_LOG)
|
#if defined(CONFIG_NET_BUF_LOG)
|
||||||
struct net_buf *net_buf_get_debug(struct k_fifo *fifo, int32_t timeout,
|
struct net_buf *net_buf_get_debug(struct k_fifo *fifo, s32_t timeout,
|
||||||
const char *func, int line)
|
const char *func, int line)
|
||||||
#else
|
#else
|
||||||
struct net_buf *net_buf_get(struct k_fifo *fifo, int32_t timeout)
|
struct net_buf *net_buf_get(struct k_fifo *fifo, s32_t timeout)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
struct net_buf *buf, *frag;
|
struct net_buf *buf, *frag;
|
||||||
|
@ -277,7 +277,7 @@ struct net_buf *net_buf_ref(struct net_buf *buf)
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct net_buf *net_buf_clone(struct net_buf *buf, int32_t timeout)
|
struct net_buf *net_buf_clone(struct net_buf *buf, s32_t timeout)
|
||||||
{
|
{
|
||||||
struct net_buf *clone;
|
struct net_buf *clone;
|
||||||
|
|
||||||
|
@ -379,7 +379,7 @@ struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag)
|
||||||
|
|
||||||
void *net_buf_simple_add(struct net_buf_simple *buf, size_t len)
|
void *net_buf_simple_add(struct net_buf_simple *buf, size_t len)
|
||||||
{
|
{
|
||||||
uint8_t *tail = net_buf_simple_tail(buf);
|
u8_t *tail = net_buf_simple_tail(buf);
|
||||||
|
|
||||||
NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len);
|
NET_BUF_SIMPLE_DBG("buf %p len %zu", buf, len);
|
||||||
|
|
||||||
|
@ -397,9 +397,9 @@ void *net_buf_simple_add_mem(struct net_buf_simple *buf, const void *mem,
|
||||||
return memcpy(net_buf_simple_add(buf, len), mem, len);
|
return memcpy(net_buf_simple_add(buf, len), mem, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t *net_buf_simple_add_u8(struct net_buf_simple *buf, uint8_t val)
|
u8_t *net_buf_simple_add_u8(struct net_buf_simple *buf, u8_t val)
|
||||||
{
|
{
|
||||||
uint8_t *u8;
|
u8_t *u8;
|
||||||
|
|
||||||
NET_BUF_SIMPLE_DBG("buf %p val 0x%02x", buf, val);
|
NET_BUF_SIMPLE_DBG("buf %p val 0x%02x", buf, val);
|
||||||
|
|
||||||
|
@ -409,7 +409,7 @@ uint8_t *net_buf_simple_add_u8(struct net_buf_simple *buf, uint8_t val)
|
||||||
return u8;
|
return u8;
|
||||||
}
|
}
|
||||||
|
|
||||||
void net_buf_simple_add_le16(struct net_buf_simple *buf, uint16_t val)
|
void net_buf_simple_add_le16(struct net_buf_simple *buf, u16_t val)
|
||||||
{
|
{
|
||||||
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
|
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
|
||||||
|
|
||||||
|
@ -417,7 +417,7 @@ void net_buf_simple_add_le16(struct net_buf_simple *buf, uint16_t val)
|
||||||
memcpy(net_buf_simple_add(buf, sizeof(val)), &val, sizeof(val));
|
memcpy(net_buf_simple_add(buf, sizeof(val)), &val, sizeof(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
void net_buf_simple_add_be16(struct net_buf_simple *buf, uint16_t val)
|
void net_buf_simple_add_be16(struct net_buf_simple *buf, u16_t val)
|
||||||
{
|
{
|
||||||
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
|
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
|
||||||
|
|
||||||
|
@ -425,7 +425,7 @@ void net_buf_simple_add_be16(struct net_buf_simple *buf, uint16_t val)
|
||||||
memcpy(net_buf_simple_add(buf, sizeof(val)), &val, sizeof(val));
|
memcpy(net_buf_simple_add(buf, sizeof(val)), &val, sizeof(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
void net_buf_simple_add_le32(struct net_buf_simple *buf, uint32_t val)
|
void net_buf_simple_add_le32(struct net_buf_simple *buf, u32_t val)
|
||||||
{
|
{
|
||||||
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
|
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
|
||||||
|
|
||||||
|
@ -433,7 +433,7 @@ void net_buf_simple_add_le32(struct net_buf_simple *buf, uint32_t val)
|
||||||
memcpy(net_buf_simple_add(buf, sizeof(val)), &val, sizeof(val));
|
memcpy(net_buf_simple_add(buf, sizeof(val)), &val, sizeof(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
void net_buf_simple_add_be32(struct net_buf_simple *buf, uint32_t val)
|
void net_buf_simple_add_be32(struct net_buf_simple *buf, u32_t val)
|
||||||
{
|
{
|
||||||
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
|
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
|
||||||
|
|
||||||
|
@ -452,7 +452,7 @@ void *net_buf_simple_push(struct net_buf_simple *buf, size_t len)
|
||||||
return buf->data;
|
return buf->data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void net_buf_simple_push_le16(struct net_buf_simple *buf, uint16_t val)
|
void net_buf_simple_push_le16(struct net_buf_simple *buf, u16_t val)
|
||||||
{
|
{
|
||||||
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
|
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
|
||||||
|
|
||||||
|
@ -460,7 +460,7 @@ void net_buf_simple_push_le16(struct net_buf_simple *buf, uint16_t val)
|
||||||
memcpy(net_buf_simple_push(buf, sizeof(val)), &val, sizeof(val));
|
memcpy(net_buf_simple_push(buf, sizeof(val)), &val, sizeof(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
void net_buf_simple_push_be16(struct net_buf_simple *buf, uint16_t val)
|
void net_buf_simple_push_be16(struct net_buf_simple *buf, u16_t val)
|
||||||
{
|
{
|
||||||
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
|
NET_BUF_SIMPLE_DBG("buf %p val %u", buf, val);
|
||||||
|
|
||||||
|
@ -468,9 +468,9 @@ void net_buf_simple_push_be16(struct net_buf_simple *buf, uint16_t val)
|
||||||
memcpy(net_buf_simple_push(buf, sizeof(val)), &val, sizeof(val));
|
memcpy(net_buf_simple_push(buf, sizeof(val)), &val, sizeof(val));
|
||||||
}
|
}
|
||||||
|
|
||||||
void net_buf_simple_push_u8(struct net_buf_simple *buf, uint8_t val)
|
void net_buf_simple_push_u8(struct net_buf_simple *buf, u8_t val)
|
||||||
{
|
{
|
||||||
uint8_t *data = net_buf_simple_push(buf, 1);
|
u8_t *data = net_buf_simple_push(buf, 1);
|
||||||
|
|
||||||
*data = val;
|
*data = val;
|
||||||
}
|
}
|
||||||
|
@ -485,9 +485,9 @@ void *net_buf_simple_pull(struct net_buf_simple *buf, size_t len)
|
||||||
return buf->data += len;
|
return buf->data += len;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t net_buf_simple_pull_u8(struct net_buf_simple *buf)
|
u8_t net_buf_simple_pull_u8(struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
uint8_t val;
|
u8_t val;
|
||||||
|
|
||||||
val = buf->data[0];
|
val = buf->data[0];
|
||||||
net_buf_simple_pull(buf, 1);
|
net_buf_simple_pull(buf, 1);
|
||||||
|
@ -495,41 +495,41 @@ uint8_t net_buf_simple_pull_u8(struct net_buf_simple *buf)
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t net_buf_simple_pull_le16(struct net_buf_simple *buf)
|
u16_t net_buf_simple_pull_le16(struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
uint16_t val;
|
u16_t val;
|
||||||
|
|
||||||
val = UNALIGNED_GET((uint16_t *)buf->data);
|
val = UNALIGNED_GET((u16_t *)buf->data);
|
||||||
net_buf_simple_pull(buf, sizeof(val));
|
net_buf_simple_pull(buf, sizeof(val));
|
||||||
|
|
||||||
return sys_le16_to_cpu(val);
|
return sys_le16_to_cpu(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t net_buf_simple_pull_be16(struct net_buf_simple *buf)
|
u16_t net_buf_simple_pull_be16(struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
uint16_t val;
|
u16_t val;
|
||||||
|
|
||||||
val = UNALIGNED_GET((uint16_t *)buf->data);
|
val = UNALIGNED_GET((u16_t *)buf->data);
|
||||||
net_buf_simple_pull(buf, sizeof(val));
|
net_buf_simple_pull(buf, sizeof(val));
|
||||||
|
|
||||||
return sys_be16_to_cpu(val);
|
return sys_be16_to_cpu(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t net_buf_simple_pull_le32(struct net_buf_simple *buf)
|
u32_t net_buf_simple_pull_le32(struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
uint32_t val;
|
u32_t val;
|
||||||
|
|
||||||
val = UNALIGNED_GET((uint32_t *)buf->data);
|
val = UNALIGNED_GET((u32_t *)buf->data);
|
||||||
net_buf_simple_pull(buf, sizeof(val));
|
net_buf_simple_pull(buf, sizeof(val));
|
||||||
|
|
||||||
return sys_le32_to_cpu(val);
|
return sys_le32_to_cpu(val);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t net_buf_simple_pull_be32(struct net_buf_simple *buf)
|
u32_t net_buf_simple_pull_be32(struct net_buf_simple *buf)
|
||||||
{
|
{
|
||||||
uint32_t val;
|
u32_t val;
|
||||||
|
|
||||||
val = UNALIGNED_GET((uint32_t *)buf->data);
|
val = UNALIGNED_GET((u32_t *)buf->data);
|
||||||
net_buf_simple_pull(buf, sizeof(val));
|
net_buf_simple_pull(buf, sizeof(val));
|
||||||
|
|
||||||
return sys_be32_to_cpu(val);
|
return sys_be32_to_cpu(val);
|
||||||
|
|
|
@ -26,19 +26,19 @@
|
||||||
struct net_6lo_context {
|
struct net_6lo_context {
|
||||||
struct in6_addr prefix;
|
struct in6_addr prefix;
|
||||||
struct net_if *iface;
|
struct net_if *iface;
|
||||||
uint16_t lifetime;
|
u16_t lifetime;
|
||||||
uint8_t is_used : 1;
|
u8_t is_used : 1;
|
||||||
uint8_t compress : 1;
|
u8_t compress : 1;
|
||||||
uint8_t cid : 4;
|
u8_t cid : 4;
|
||||||
uint8_t unused : 2;
|
u8_t unused : 2;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
static inline uint8_t get_6co_compress(struct net_icmpv6_nd_opt_6co *opt)
|
static inline u8_t get_6co_compress(struct net_icmpv6_nd_opt_6co *opt)
|
||||||
{
|
{
|
||||||
return (opt->flag & 0x10) >> 4;
|
return (opt->flag & 0x10) >> 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t get_6co_cid(struct net_icmpv6_nd_opt_6co *opt)
|
static inline u8_t get_6co_cid(struct net_icmpv6_nd_opt_6co *opt)
|
||||||
{
|
{
|
||||||
return opt->flag & 0x0F;
|
return opt->flag & 0x0F;
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,7 @@ static inline bool net_6lo_maddr_48_bit_compressible(struct in6_addr *addr)
|
||||||
|
|
||||||
#if defined(CONFIG_NET_6LO_CONTEXT)
|
#if defined(CONFIG_NET_6LO_CONTEXT)
|
||||||
/* RFC 6775, 4.2, 5.4.2, 5.4.3 and 7.2*/
|
/* RFC 6775, 4.2, 5.4.2, 5.4.3 and 7.2*/
|
||||||
static inline void set_6lo_context(struct net_if *iface, uint8_t index,
|
static inline void set_6lo_context(struct net_if *iface, u8_t index,
|
||||||
struct net_icmpv6_nd_opt_6co *context)
|
struct net_icmpv6_nd_opt_6co *context)
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -106,7 +106,7 @@ void net_6lo_set_context(struct net_if *iface,
|
||||||
struct net_icmpv6_nd_opt_6co *context)
|
struct net_icmpv6_nd_opt_6co *context)
|
||||||
{
|
{
|
||||||
int unused = -1;
|
int unused = -1;
|
||||||
uint8_t i;
|
u8_t i;
|
||||||
|
|
||||||
/* If the context information already exists, update or remove
|
/* If the context information already exists, update or remove
|
||||||
* as per data.
|
* as per data.
|
||||||
|
@ -142,9 +142,9 @@ void net_6lo_set_context(struct net_if *iface,
|
||||||
|
|
||||||
/* Get the context by matching cid */
|
/* Get the context by matching cid */
|
||||||
static inline struct net_6lo_context *
|
static inline struct net_6lo_context *
|
||||||
get_6lo_context_by_cid(struct net_if *iface, uint8_t cid)
|
get_6lo_context_by_cid(struct net_if *iface, u8_t cid)
|
||||||
{
|
{
|
||||||
uint8_t i;
|
u8_t i;
|
||||||
|
|
||||||
for (i = 0; i < CONFIG_NET_MAX_6LO_CONTEXTS; i++) {
|
for (i = 0; i < CONFIG_NET_MAX_6LO_CONTEXTS; i++) {
|
||||||
if (!ctx_6co[i].is_used) {
|
if (!ctx_6co[i].is_used) {
|
||||||
|
@ -163,7 +163,7 @@ get_6lo_context_by_cid(struct net_if *iface, uint8_t cid)
|
||||||
static inline struct net_6lo_context *
|
static inline struct net_6lo_context *
|
||||||
get_6lo_context_by_addr(struct net_if *iface, struct in6_addr *addr)
|
get_6lo_context_by_addr(struct net_if *iface, struct in6_addr *addr)
|
||||||
{
|
{
|
||||||
uint8_t i;
|
u8_t i;
|
||||||
|
|
||||||
for (i = 0; i < CONFIG_NET_MAX_6LO_CONTEXTS; i++) {
|
for (i = 0; i < CONFIG_NET_MAX_6LO_CONTEXTS; i++) {
|
||||||
if (!ctx_6co[i].is_used) {
|
if (!ctx_6co[i].is_used) {
|
||||||
|
@ -195,11 +195,11 @@ get_6lo_context_by_addr(struct net_if *iface, struct in6_addr *addr)
|
||||||
* IPv6 traffic class format is DSCP, ECN.
|
* IPv6 traffic class format is DSCP, ECN.
|
||||||
* DSCP(6), ECN(2).
|
* DSCP(6), ECN(2).
|
||||||
*/
|
*/
|
||||||
static inline uint8_t compress_tfl(struct net_ipv6_hdr *ipv6,
|
static inline u8_t compress_tfl(struct net_ipv6_hdr *ipv6,
|
||||||
struct net_buf *frag,
|
struct net_buf *frag,
|
||||||
uint8_t offset)
|
u8_t offset)
|
||||||
{
|
{
|
||||||
uint8_t tcl;
|
u8_t tcl;
|
||||||
|
|
||||||
tcl = ((ipv6->vtc & 0x0F) << 4) | ((ipv6->tcflow & 0xF0) >> 4);
|
tcl = ((ipv6->vtc & 0x0F) << 4) | ((ipv6->tcflow & 0xF0) >> 4);
|
||||||
tcl = (tcl << 6) | (tcl >> 2); /* ECN(2), DSCP(6) */
|
tcl = (tcl << 6) | (tcl >> 2); /* ECN(2), DSCP(6) */
|
||||||
|
@ -246,9 +246,9 @@ static inline uint8_t compress_tfl(struct net_ipv6_hdr *ipv6,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper to compress Hop limit */
|
/* Helper to compress Hop limit */
|
||||||
static inline uint8_t compress_hoplimit(struct net_ipv6_hdr *ipv6,
|
static inline u8_t compress_hoplimit(struct net_ipv6_hdr *ipv6,
|
||||||
struct net_buf *frag,
|
struct net_buf *frag,
|
||||||
uint8_t offset)
|
u8_t offset)
|
||||||
{
|
{
|
||||||
/* Hop Limit */
|
/* Hop Limit */
|
||||||
switch (ipv6->hop_limit) {
|
switch (ipv6->hop_limit) {
|
||||||
|
@ -270,8 +270,8 @@ static inline uint8_t compress_hoplimit(struct net_ipv6_hdr *ipv6,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper to compress Next header */
|
/* Helper to compress Next header */
|
||||||
static inline uint8_t compress_nh(struct net_ipv6_hdr *ipv6,
|
static inline u8_t compress_nh(struct net_ipv6_hdr *ipv6,
|
||||||
struct net_buf *frag, uint8_t offset)
|
struct net_buf *frag, u8_t offset)
|
||||||
{
|
{
|
||||||
/* Next header */
|
/* Next header */
|
||||||
if (ipv6->nexthdr == IPPROTO_UDP) {
|
if (ipv6->nexthdr == IPPROTO_UDP) {
|
||||||
|
@ -284,10 +284,10 @@ static inline uint8_t compress_nh(struct net_ipv6_hdr *ipv6,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helpers to compress Source Address */
|
/* Helpers to compress Source Address */
|
||||||
static inline uint8_t compress_sa(struct net_ipv6_hdr *ipv6,
|
static inline u8_t compress_sa(struct net_ipv6_hdr *ipv6,
|
||||||
struct net_pkt *pkt,
|
struct net_pkt *pkt,
|
||||||
struct net_buf *frag,
|
struct net_buf *frag,
|
||||||
uint8_t offset)
|
u8_t offset)
|
||||||
{
|
{
|
||||||
if (net_is_ipv6_addr_unspecified(&ipv6->src)) {
|
if (net_is_ipv6_addr_unspecified(&ipv6->src)) {
|
||||||
NET_DBG("SAM_00, SAC_1 unspecified src address");
|
NET_DBG("SAM_00, SAC_1 unspecified src address");
|
||||||
|
@ -349,10 +349,10 @@ static inline uint8_t compress_sa(struct net_ipv6_hdr *ipv6,
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NET_6LO_CONTEXT)
|
#if defined(CONFIG_NET_6LO_CONTEXT)
|
||||||
static inline uint8_t compress_sa_ctx(struct net_ipv6_hdr *ipv6,
|
static inline u8_t compress_sa_ctx(struct net_ipv6_hdr *ipv6,
|
||||||
struct net_pkt *pkt,
|
struct net_pkt *pkt,
|
||||||
struct net_buf *frag,
|
struct net_buf *frag,
|
||||||
uint8_t offset,
|
u8_t offset,
|
||||||
struct net_6lo_context *src)
|
struct net_6lo_context *src)
|
||||||
{
|
{
|
||||||
if (!src) {
|
if (!src) {
|
||||||
|
@ -390,10 +390,10 @@ static inline uint8_t compress_sa_ctx(struct net_ipv6_hdr *ipv6,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Helpers to compress Destination Address */
|
/* Helpers to compress Destination Address */
|
||||||
static inline uint8_t compress_da_mcast(struct net_ipv6_hdr *ipv6,
|
static inline u8_t compress_da_mcast(struct net_ipv6_hdr *ipv6,
|
||||||
struct net_pkt *pkt,
|
struct net_pkt *pkt,
|
||||||
struct net_buf *frag,
|
struct net_buf *frag,
|
||||||
uint8_t offset)
|
u8_t offset)
|
||||||
{
|
{
|
||||||
IPHC[1] |= NET_6LO_IPHC_M_1;
|
IPHC[1] |= NET_6LO_IPHC_M_1;
|
||||||
|
|
||||||
|
@ -441,10 +441,10 @@ static inline uint8_t compress_da_mcast(struct net_ipv6_hdr *ipv6,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint8_t compress_da(struct net_ipv6_hdr *ipv6,
|
static inline u8_t compress_da(struct net_ipv6_hdr *ipv6,
|
||||||
struct net_pkt *pkt,
|
struct net_pkt *pkt,
|
||||||
struct net_buf *frag,
|
struct net_buf *frag,
|
||||||
uint8_t offset)
|
u8_t offset)
|
||||||
{
|
{
|
||||||
/* If destination address is multicast */
|
/* If destination address is multicast */
|
||||||
if (net_is_ipv6_addr_mcast(&ipv6->dst)) {
|
if (net_is_ipv6_addr_mcast(&ipv6->dst)) {
|
||||||
|
@ -499,10 +499,10 @@ static inline uint8_t compress_da(struct net_ipv6_hdr *ipv6,
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NET_6LO_CONTEXT)
|
#if defined(CONFIG_NET_6LO_CONTEXT)
|
||||||
static inline uint8_t compress_da_ctx(struct net_ipv6_hdr *ipv6,
|
static inline u8_t compress_da_ctx(struct net_ipv6_hdr *ipv6,
|
||||||
struct net_pkt *pkt,
|
struct net_pkt *pkt,
|
||||||
struct net_buf *frag,
|
struct net_buf *frag,
|
||||||
uint8_t offset,
|
u8_t offset,
|
||||||
struct net_6lo_context *dst)
|
struct net_6lo_context *dst)
|
||||||
{
|
{
|
||||||
if (!dst) {
|
if (!dst) {
|
||||||
|
@ -542,10 +542,10 @@ static inline uint8_t compress_da_ctx(struct net_ipv6_hdr *ipv6,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Helper to compress Next header UDP */
|
/* Helper to compress Next header UDP */
|
||||||
static inline uint8_t compress_nh_udp(struct net_udp_hdr *udp,
|
static inline u8_t compress_nh_udp(struct net_udp_hdr *udp,
|
||||||
struct net_buf *frag, uint8_t offset)
|
struct net_buf *frag, u8_t offset)
|
||||||
{
|
{
|
||||||
uint8_t tmp;
|
u8_t tmp;
|
||||||
|
|
||||||
/* 4.3.3 UDP LOWPAN_NHC Format
|
/* 4.3.3 UDP LOWPAN_NHC Format
|
||||||
* 0 1 2 3 4 5 6 7
|
* 0 1 2 3 4 5 6 7
|
||||||
|
@ -576,10 +576,10 @@ static inline uint8_t compress_nh_udp(struct net_udp_hdr *udp,
|
||||||
IPHC[offset] |= NET_6LO_NHC_UDP_PORT_11;
|
IPHC[offset] |= NET_6LO_NHC_UDP_PORT_11;
|
||||||
offset++;
|
offset++;
|
||||||
|
|
||||||
tmp = (uint8_t)(htons(udp->src_port));
|
tmp = (u8_t)(htons(udp->src_port));
|
||||||
tmp = tmp << 4;
|
tmp = tmp << 4;
|
||||||
|
|
||||||
tmp |= (((uint8_t)(htons(udp->dst_port))) & 0x0F);
|
tmp |= (((u8_t)(htons(udp->dst_port))) & 0x0F);
|
||||||
IPHC[offset++] = tmp;
|
IPHC[offset++] = tmp;
|
||||||
} else if (((htons(udp->dst_port) >> 8) & 0xFF) ==
|
} else if (((htons(udp->dst_port) >> 8) & 0xFF) ==
|
||||||
NET_6LO_NHC_UDP_8_BIT_PORT) {
|
NET_6LO_NHC_UDP_8_BIT_PORT) {
|
||||||
|
@ -594,7 +594,7 @@ static inline uint8_t compress_nh_udp(struct net_udp_hdr *udp,
|
||||||
memcpy(&IPHC[offset], &udp->src_port, 2);
|
memcpy(&IPHC[offset], &udp->src_port, 2);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
|
|
||||||
IPHC[offset++] = (uint8_t)(htons(udp->dst_port));
|
IPHC[offset++] = (u8_t)(htons(udp->dst_port));
|
||||||
} else if (((htons(udp->src_port) >> 8) & 0xFF) ==
|
} else if (((htons(udp->src_port) >> 8) & 0xFF) ==
|
||||||
NET_6LO_NHC_UDP_8_BIT_PORT) {
|
NET_6LO_NHC_UDP_8_BIT_PORT) {
|
||||||
|
|
||||||
|
@ -605,7 +605,7 @@ static inline uint8_t compress_nh_udp(struct net_udp_hdr *udp,
|
||||||
IPHC[offset] |= NET_6LO_NHC_UDP_PORT_10;
|
IPHC[offset] |= NET_6LO_NHC_UDP_PORT_10;
|
||||||
offset++;
|
offset++;
|
||||||
|
|
||||||
IPHC[offset++] = (uint8_t)(htons(udp->src_port));
|
IPHC[offset++] = (u8_t)(htons(udp->src_port));
|
||||||
|
|
||||||
memcpy(&IPHC[offset], &udp->dst_port, 2);
|
memcpy(&IPHC[offset], &udp->dst_port, 2);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
|
@ -683,10 +683,10 @@ static inline bool compress_IPHC_header(struct net_pkt *pkt,
|
||||||
struct net_6lo_context *dst = NULL;
|
struct net_6lo_context *dst = NULL;
|
||||||
#endif
|
#endif
|
||||||
struct net_ipv6_hdr *ipv6 = NET_IPV6_HDR(pkt);
|
struct net_ipv6_hdr *ipv6 = NET_IPV6_HDR(pkt);
|
||||||
uint8_t offset = 0;
|
u8_t offset = 0;
|
||||||
struct net_udp_hdr *udp;
|
struct net_udp_hdr *udp;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
uint8_t compressed;
|
u8_t compressed;
|
||||||
|
|
||||||
if (pkt->frags->len < NET_IPV6H_LEN) {
|
if (pkt->frags->len < NET_IPV6H_LEN) {
|
||||||
NET_ERR("Invalid length %d, min %d",
|
NET_ERR("Invalid length %d, min %d",
|
||||||
|
@ -783,11 +783,11 @@ end:
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper to uncompress Traffic class and Flow label */
|
/* Helper to uncompress Traffic class and Flow label */
|
||||||
static inline uint8_t uncompress_tfl(struct net_pkt *pkt,
|
static inline u8_t uncompress_tfl(struct net_pkt *pkt,
|
||||||
struct net_ipv6_hdr *ipv6,
|
struct net_ipv6_hdr *ipv6,
|
||||||
uint8_t offset)
|
u8_t offset)
|
||||||
{
|
{
|
||||||
uint8_t tcl;
|
u8_t tcl;
|
||||||
|
|
||||||
/* Uncompress tcl and flow label */
|
/* Uncompress tcl and flow label */
|
||||||
switch (CIPHC[0] & NET_6LO_IPHC_TF_11) {
|
switch (CIPHC[0] & NET_6LO_IPHC_TF_11) {
|
||||||
|
@ -835,9 +835,9 @@ static inline uint8_t uncompress_tfl(struct net_pkt *pkt,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper to uncompress Hoplimit */
|
/* Helper to uncompress Hoplimit */
|
||||||
static inline uint8_t uncompress_hoplimit(struct net_pkt *pkt,
|
static inline u8_t uncompress_hoplimit(struct net_pkt *pkt,
|
||||||
struct net_ipv6_hdr *ipv6,
|
struct net_ipv6_hdr *ipv6,
|
||||||
uint8_t offset)
|
u8_t offset)
|
||||||
{
|
{
|
||||||
switch (CIPHC[0] & NET_6LO_IPHC_HLIM255) {
|
switch (CIPHC[0] & NET_6LO_IPHC_HLIM255) {
|
||||||
case NET_6LO_IPHC_HLIM:
|
case NET_6LO_IPHC_HLIM:
|
||||||
|
@ -858,9 +858,9 @@ static inline uint8_t uncompress_hoplimit(struct net_pkt *pkt,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper to uncompress Source Address */
|
/* Helper to uncompress Source Address */
|
||||||
static inline uint8_t uncompress_sa(struct net_pkt *pkt,
|
static inline u8_t uncompress_sa(struct net_pkt *pkt,
|
||||||
struct net_ipv6_hdr *ipv6,
|
struct net_ipv6_hdr *ipv6,
|
||||||
uint8_t offset)
|
u8_t offset)
|
||||||
{
|
{
|
||||||
if (CIPHC[1] & NET_6LO_IPHC_SAC_1) {
|
if (CIPHC[1] & NET_6LO_IPHC_SAC_1) {
|
||||||
NET_DBG("SAC_1");
|
NET_DBG("SAC_1");
|
||||||
|
@ -908,9 +908,9 @@ static inline uint8_t uncompress_sa(struct net_pkt *pkt,
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NET_6LO_CONTEXT)
|
#if defined(CONFIG_NET_6LO_CONTEXT)
|
||||||
static inline uint8_t uncompress_sa_ctx(struct net_pkt *pkt,
|
static inline u8_t uncompress_sa_ctx(struct net_pkt *pkt,
|
||||||
struct net_ipv6_hdr *ipv6,
|
struct net_ipv6_hdr *ipv6,
|
||||||
uint8_t offset,
|
u8_t offset,
|
||||||
struct net_6lo_context *ctx)
|
struct net_6lo_context *ctx)
|
||||||
{
|
{
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
|
@ -965,9 +965,9 @@ static inline uint8_t uncompress_sa_ctx(struct net_pkt *pkt,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Helpers to uncompress Destination Address */
|
/* Helpers to uncompress Destination Address */
|
||||||
static inline uint8_t uncompress_da_mcast(struct net_pkt *pkt,
|
static inline u8_t uncompress_da_mcast(struct net_pkt *pkt,
|
||||||
struct net_ipv6_hdr *ipv6,
|
struct net_ipv6_hdr *ipv6,
|
||||||
uint8_t offset)
|
u8_t offset)
|
||||||
{
|
{
|
||||||
NET_DBG("Dst is multicast");
|
NET_DBG("Dst is multicast");
|
||||||
|
|
||||||
|
@ -1023,9 +1023,9 @@ static inline uint8_t uncompress_da_mcast(struct net_pkt *pkt,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Helper to uncompress Destination Address */
|
/* Helper to uncompress Destination Address */
|
||||||
static inline uint8_t uncompress_da(struct net_pkt *pkt,
|
static inline u8_t uncompress_da(struct net_pkt *pkt,
|
||||||
struct net_ipv6_hdr *ipv6,
|
struct net_ipv6_hdr *ipv6,
|
||||||
uint8_t offset)
|
u8_t offset)
|
||||||
{
|
{
|
||||||
if (CIPHC[1] & NET_6LO_IPHC_M_1) {
|
if (CIPHC[1] & NET_6LO_IPHC_M_1) {
|
||||||
return uncompress_da_mcast(pkt, ipv6, offset);
|
return uncompress_da_mcast(pkt, ipv6, offset);
|
||||||
|
@ -1076,9 +1076,9 @@ static inline uint8_t uncompress_da(struct net_pkt *pkt,
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(CONFIG_NET_6LO_CONTEXT)
|
#if defined(CONFIG_NET_6LO_CONTEXT)
|
||||||
static inline uint8_t uncompress_da_ctx(struct net_pkt *pkt,
|
static inline u8_t uncompress_da_ctx(struct net_pkt *pkt,
|
||||||
struct net_ipv6_hdr *ipv6,
|
struct net_ipv6_hdr *ipv6,
|
||||||
uint8_t offset,
|
u8_t offset,
|
||||||
struct net_6lo_context *ctx)
|
struct net_6lo_context *ctx)
|
||||||
{
|
{
|
||||||
if (!ctx) {
|
if (!ctx) {
|
||||||
|
@ -1145,9 +1145,9 @@ static inline uint8_t uncompress_da_ctx(struct net_pkt *pkt,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Helper to uncompress NH UDP */
|
/* Helper to uncompress NH UDP */
|
||||||
static inline uint8_t uncompress_nh_udp(struct net_pkt *pkt,
|
static inline u8_t uncompress_nh_udp(struct net_pkt *pkt,
|
||||||
struct net_udp_hdr *udp,
|
struct net_udp_hdr *udp,
|
||||||
uint8_t offset)
|
u8_t offset)
|
||||||
{
|
{
|
||||||
/* Port uncompression
|
/* Port uncompression
|
||||||
* 00: All 16 bits for src and dst are inlined
|
* 00: All 16 bits for src and dst are inlined
|
||||||
|
@ -1173,14 +1173,14 @@ static inline uint8_t uncompress_nh_udp(struct net_pkt *pkt,
|
||||||
memcpy(&udp->src_port, &CIPHC[offset], 2);
|
memcpy(&udp->src_port, &CIPHC[offset], 2);
|
||||||
offset += 2;
|
offset += 2;
|
||||||
|
|
||||||
udp->dst_port = htons(((uint16_t)NET_6LO_NHC_UDP_8_BIT_PORT
|
udp->dst_port = htons(((u16_t)NET_6LO_NHC_UDP_8_BIT_PORT
|
||||||
<< 8) | CIPHC[offset]);
|
<< 8) | CIPHC[offset]);
|
||||||
offset++;
|
offset++;
|
||||||
break;
|
break;
|
||||||
case NET_6LO_NHC_UDP_PORT_10:
|
case NET_6LO_NHC_UDP_PORT_10:
|
||||||
NET_DBG("src 8 bits, dst full inlined");
|
NET_DBG("src 8 bits, dst full inlined");
|
||||||
|
|
||||||
udp->src_port = htons(((uint16_t)NET_6LO_NHC_UDP_8_BIT_PORT
|
udp->src_port = htons(((u16_t)NET_6LO_NHC_UDP_8_BIT_PORT
|
||||||
<< 8) | CIPHC[offset]);
|
<< 8) | CIPHC[offset]);
|
||||||
offset++;
|
offset++;
|
||||||
|
|
||||||
|
@ -1208,7 +1208,7 @@ static inline bool uncompress_cid(struct net_pkt *pkt,
|
||||||
struct net_6lo_context **src,
|
struct net_6lo_context **src,
|
||||||
struct net_6lo_context **dst)
|
struct net_6lo_context **dst)
|
||||||
{
|
{
|
||||||
uint8_t cid;
|
u8_t cid;
|
||||||
|
|
||||||
/* Extract source and destination Context Index,
|
/* Extract source and destination Context Index,
|
||||||
* Either src or dest address is context based or both.
|
* Either src or dest address is context based or both.
|
||||||
|
@ -1241,11 +1241,11 @@ static inline bool uncompress_cid(struct net_pkt *pkt,
|
||||||
static inline bool uncompress_IPHC_header(struct net_pkt *pkt)
|
static inline bool uncompress_IPHC_header(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
struct net_udp_hdr *udp = NULL;
|
struct net_udp_hdr *udp = NULL;
|
||||||
uint8_t offset = 2;
|
u8_t offset = 2;
|
||||||
uint8_t chksum = 0;
|
u8_t chksum = 0;
|
||||||
struct net_ipv6_hdr *ipv6;
|
struct net_ipv6_hdr *ipv6;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
uint16_t len;
|
u16_t len;
|
||||||
#if defined(CONFIG_NET_6LO_CONTEXT)
|
#if defined(CONFIG_NET_6LO_CONTEXT)
|
||||||
struct net_6lo_context *src = NULL;
|
struct net_6lo_context *src = NULL;
|
||||||
struct net_6lo_context *dst = NULL;
|
struct net_6lo_context *dst = NULL;
|
||||||
|
@ -1362,7 +1362,7 @@ end:
|
||||||
/* Set IPv6 header and UDP (if next header is) length */
|
/* Set IPv6 header and UDP (if next header is) length */
|
||||||
len = net_pkt_get_len(pkt) - NET_IPV6H_LEN;
|
len = net_pkt_get_len(pkt) - NET_IPV6H_LEN;
|
||||||
ipv6->len[0] = len >> 8;
|
ipv6->len[0] = len >> 8;
|
||||||
ipv6->len[1] = (uint8_t)len;
|
ipv6->len[1] = (u8_t)len;
|
||||||
|
|
||||||
if (ipv6->nexthdr == IPPROTO_UDP && udp) {
|
if (ipv6->nexthdr == IPPROTO_UDP && udp) {
|
||||||
udp->len = htons(len);
|
udp->len = htons(len);
|
||||||
|
|
|
@ -68,12 +68,12 @@ static struct net_conn conns[CONFIG_NET_MAX_CONN];
|
||||||
* 31 protocol
|
* 31 protocol
|
||||||
*/
|
*/
|
||||||
struct conn_hash {
|
struct conn_hash {
|
||||||
uint32_t value;
|
u32_t value;
|
||||||
int32_t idx;
|
s32_t idx;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct conn_hash_neg {
|
struct conn_hash_neg {
|
||||||
uint32_t value;
|
u32_t value;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Connection cache */
|
/** Connection cache */
|
||||||
|
@ -87,8 +87,8 @@ static struct conn_hash_neg conn_cache_neg[CONFIG_NET_MAX_CONN];
|
||||||
#define TAKE_BIT(val, bit, max, used) \
|
#define TAKE_BIT(val, bit, max, used) \
|
||||||
(((val & BIT(bit)) >> bit) << (max - used))
|
(((val & BIT(bit)) >> bit) << (max - used))
|
||||||
|
|
||||||
static inline uint8_t ports_to_hash(uint16_t remote_port,
|
static inline u8_t ports_to_hash(u16_t remote_port,
|
||||||
uint16_t local_port)
|
u16_t local_port)
|
||||||
{
|
{
|
||||||
/* Note that we do not convert port value to network byte order */
|
/* Note that we do not convert port value to network byte order */
|
||||||
return (remote_port & BIT(0)) |
|
return (remote_port & BIT(0)) |
|
||||||
|
@ -101,7 +101,7 @@ static inline uint8_t ports_to_hash(uint16_t remote_port,
|
||||||
((local_port & BIT(15)) >> 12)) << 4);
|
((local_port & BIT(15)) >> 12)) << 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint16_t ipv6_to_hash(struct in6_addr *addr)
|
static inline u16_t ipv6_to_hash(struct in6_addr *addr)
|
||||||
{
|
{
|
||||||
/* There is 11 bits available for IPv6 address */
|
/* There is 11 bits available for IPv6 address */
|
||||||
/* Use more bits from the lower part of address space */
|
/* Use more bits from the lower part of address space */
|
||||||
|
@ -126,7 +126,7 @@ static inline uint16_t ipv6_to_hash(struct in6_addr *addr)
|
||||||
TAKE_BIT(UNALIGNED_GET(&addr->s6_addr32[3]), 0, 11, 11);
|
TAKE_BIT(UNALIGNED_GET(&addr->s6_addr32[3]), 0, 11, 11);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint16_t ipv4_to_hash(struct in_addr *addr)
|
static inline u16_t ipv4_to_hash(struct in_addr *addr)
|
||||||
{
|
{
|
||||||
/* There is 11 bits available for IPv4 address */
|
/* There is 11 bits available for IPv4 address */
|
||||||
/* Use more bits from the lower part of address space */
|
/* Use more bits from the lower part of address space */
|
||||||
|
@ -147,16 +147,16 @@ static inline uint16_t ipv4_to_hash(struct in_addr *addr)
|
||||||
/* Return either the first free position in the cache (idx < 0) or
|
/* Return either the first free position in the cache (idx < 0) or
|
||||||
* the existing cached position (idx >= 0)
|
* the existing cached position (idx >= 0)
|
||||||
*/
|
*/
|
||||||
static int32_t check_hash(enum net_ip_protocol proto,
|
static s32_t check_hash(enum net_ip_protocol proto,
|
||||||
sa_family_t family,
|
sa_family_t family,
|
||||||
void *remote_addr,
|
void *remote_addr,
|
||||||
void *local_addr,
|
void *local_addr,
|
||||||
uint16_t remote_port,
|
u16_t remote_port,
|
||||||
uint16_t local_port,
|
u16_t local_port,
|
||||||
uint32_t *cache_value)
|
u32_t *cache_value)
|
||||||
{
|
{
|
||||||
int i, free_pos = -1;
|
int i, free_pos = -1;
|
||||||
uint32_t value = 0;
|
u32_t value = 0;
|
||||||
|
|
||||||
value = ports_to_hash(remote_port, local_port);
|
value = ports_to_hash(remote_port, local_port);
|
||||||
|
|
||||||
|
@ -208,10 +208,10 @@ static int32_t check_hash(enum net_ip_protocol proto,
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int32_t get_conn(enum net_ip_protocol proto,
|
static inline s32_t get_conn(enum net_ip_protocol proto,
|
||||||
sa_family_t family,
|
sa_family_t family,
|
||||||
struct net_pkt *pkt,
|
struct net_pkt *pkt,
|
||||||
uint32_t *cache_value)
|
u32_t *cache_value)
|
||||||
{
|
{
|
||||||
#if defined(CONFIG_NET_IPV4)
|
#if defined(CONFIG_NET_IPV4)
|
||||||
if (family == AF_INET) {
|
if (family == AF_INET) {
|
||||||
|
@ -238,7 +238,7 @@ static inline int32_t get_conn(enum net_ip_protocol proto,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void cache_add_neg(uint32_t cache_value)
|
static inline void cache_add_neg(u32_t cache_value)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ static inline void cache_add_neg(uint32_t cache_value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool cache_check_neg(uint32_t cache_value)
|
static inline bool cache_check_neg(u32_t cache_value)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -281,8 +281,8 @@ static void cache_clear(void)
|
||||||
|
|
||||||
static inline enum net_verdict cache_check(enum net_ip_protocol proto,
|
static inline enum net_verdict cache_check(enum net_ip_protocol proto,
|
||||||
struct net_pkt *pkt,
|
struct net_pkt *pkt,
|
||||||
uint32_t *cache_value,
|
u32_t *cache_value,
|
||||||
int32_t *pos)
|
s32_t *pos)
|
||||||
{
|
{
|
||||||
*pos = get_conn(proto, net_pkt_family(pkt), pkt, cache_value);
|
*pos = get_conn(proto, net_pkt_family(pkt), pkt, cache_value);
|
||||||
if (*pos >= 0) {
|
if (*pos >= 0) {
|
||||||
|
@ -415,14 +415,14 @@ void prepare_register_debug_print(char *dst, int dst_len,
|
||||||
int net_conn_register(enum net_ip_protocol proto,
|
int net_conn_register(enum net_ip_protocol proto,
|
||||||
const struct sockaddr *remote_addr,
|
const struct sockaddr *remote_addr,
|
||||||
const struct sockaddr *local_addr,
|
const struct sockaddr *local_addr,
|
||||||
uint16_t remote_port,
|
u16_t remote_port,
|
||||||
uint16_t local_port,
|
u16_t local_port,
|
||||||
net_conn_cb_t cb,
|
net_conn_cb_t cb,
|
||||||
void *user_data,
|
void *user_data,
|
||||||
struct net_conn_handle **handle)
|
struct net_conn_handle **handle)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint8_t rank = 0;
|
u8_t rank = 0;
|
||||||
|
|
||||||
for (i = 0; i < CONFIG_NET_MAX_CONN; i++) {
|
for (i = 0; i < CONFIG_NET_MAX_CONN; i++) {
|
||||||
if (conns[i].flags & NET_CONN_IN_USE) {
|
if (conns[i].flags & NET_CONN_IN_USE) {
|
||||||
|
@ -629,12 +629,12 @@ static inline void send_icmp_error(struct net_pkt *pkt)
|
||||||
enum net_verdict net_conn_input(enum net_ip_protocol proto, struct net_pkt *pkt)
|
enum net_verdict net_conn_input(enum net_ip_protocol proto, struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
int i, best_match = -1;
|
int i, best_match = -1;
|
||||||
int16_t best_rank = -1;
|
s16_t best_rank = -1;
|
||||||
|
|
||||||
#if defined(CONFIG_NET_CONN_CACHE)
|
#if defined(CONFIG_NET_CONN_CACHE)
|
||||||
enum net_verdict verdict;
|
enum net_verdict verdict;
|
||||||
uint32_t cache_value = 0;
|
u32_t cache_value = 0;
|
||||||
int32_t pos;
|
s32_t pos;
|
||||||
|
|
||||||
verdict = cache_check(proto, pkt, &cache_value, &pos);
|
verdict = cache_check(proto, pkt, &cache_value, &pos);
|
||||||
if (verdict != NET_CONTINUE) {
|
if (verdict != NET_CONTINUE) {
|
||||||
|
@ -643,7 +643,7 @@ enum net_verdict net_conn_input(enum net_ip_protocol proto, struct net_pkt *pkt)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_NET_DEBUG_CONN)) {
|
if (IS_ENABLED(CONFIG_NET_DEBUG_CONN)) {
|
||||||
uint16_t chksum;
|
u16_t chksum;
|
||||||
|
|
||||||
if (proto == IPPROTO_TCP) {
|
if (proto == IPPROTO_TCP) {
|
||||||
chksum = NET_TCP_HDR(pkt)->chksum;
|
chksum = NET_TCP_HDR(pkt)->chksum;
|
||||||
|
|
|
@ -58,10 +58,10 @@ struct net_conn {
|
||||||
void *user_data;
|
void *user_data;
|
||||||
|
|
||||||
/** Connection protocol */
|
/** Connection protocol */
|
||||||
uint8_t proto;
|
u8_t proto;
|
||||||
|
|
||||||
/** Flags for the connection */
|
/** Flags for the connection */
|
||||||
uint8_t flags;
|
u8_t flags;
|
||||||
|
|
||||||
/** Rank of this connection. Higher rank means more specific
|
/** Rank of this connection. Higher rank means more specific
|
||||||
* connection.
|
* connection.
|
||||||
|
@ -73,7 +73,7 @@ struct net_conn {
|
||||||
* bit 4 local address, bit set if specific address
|
* bit 4 local address, bit set if specific address
|
||||||
* bit 5 remote address, bit set if specific address
|
* bit 5 remote address, bit set if specific address
|
||||||
*/
|
*/
|
||||||
uint8_t rank;
|
u8_t rank;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,8 +94,8 @@ struct net_conn {
|
||||||
int net_conn_register(enum net_ip_protocol proto,
|
int net_conn_register(enum net_ip_protocol proto,
|
||||||
const struct sockaddr *remote_addr,
|
const struct sockaddr *remote_addr,
|
||||||
const struct sockaddr *local_addr,
|
const struct sockaddr *local_addr,
|
||||||
uint16_t remote_port,
|
u16_t remote_port,
|
||||||
uint16_t local_port,
|
u16_t local_port,
|
||||||
net_conn_cb_t cb,
|
net_conn_cb_t cb,
|
||||||
void *user_data,
|
void *user_data,
|
||||||
struct net_conn_handle **handle);
|
struct net_conn_handle **handle);
|
||||||
|
|
|
@ -27,24 +27,24 @@
|
||||||
#include <net/dhcpv4.h>
|
#include <net/dhcpv4.h>
|
||||||
|
|
||||||
struct dhcp_msg {
|
struct dhcp_msg {
|
||||||
uint8_t op; /* Message type, 1:BOOTREQUEST, 2:BOOTREPLY */
|
u8_t op; /* Message type, 1:BOOTREQUEST, 2:BOOTREPLY */
|
||||||
uint8_t htype; /* Hardware Address Type */
|
u8_t htype; /* Hardware Address Type */
|
||||||
uint8_t hlen; /* Hardware Address length */
|
u8_t hlen; /* Hardware Address length */
|
||||||
uint8_t hops; /* used by relay agents when booting via relay
|
u8_t hops; /* used by relay agents when booting via relay
|
||||||
* agent, client sets zero
|
* agent, client sets zero
|
||||||
*/
|
*/
|
||||||
uint32_t xid; /* Transaction ID, random number */
|
u32_t xid; /* Transaction ID, random number */
|
||||||
uint16_t secs; /* Seconds elapsed since client began address
|
u16_t secs; /* Seconds elapsed since client began address
|
||||||
* acquisition or renewal process
|
* acquisition or renewal process
|
||||||
*/
|
*/
|
||||||
uint16_t flags; /* Broadcast or Unicast */
|
u16_t flags; /* Broadcast or Unicast */
|
||||||
uint8_t ciaddr[4]; /* Client IP Address */
|
u8_t ciaddr[4]; /* Client IP Address */
|
||||||
uint8_t yiaddr[4]; /* your (client) IP address */
|
u8_t yiaddr[4]; /* your (client) IP address */
|
||||||
uint8_t siaddr[4]; /* IP address of next server to use in bootstrap
|
u8_t siaddr[4]; /* IP address of next server to use in bootstrap
|
||||||
* returned in DHCPOFFER, DHCPACK by server
|
* returned in DHCPOFFER, DHCPACK by server
|
||||||
*/
|
*/
|
||||||
uint8_t giaddr[4]; /* Relat agent IP address */
|
u8_t giaddr[4]; /* Relat agent IP address */
|
||||||
uint8_t chaddr[16]; /* Client hardware address */
|
u8_t chaddr[16]; /* Client hardware address */
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define SIZE_OF_SNAME 64
|
#define SIZE_OF_SNAME 64
|
||||||
|
@ -113,7 +113,7 @@ enum dhcpv4_msg_type {
|
||||||
#define DHCPV4_INITIAL_DELAY_MAX 10
|
#define DHCPV4_INITIAL_DELAY_MAX 10
|
||||||
|
|
||||||
/* RFC 1497 [17] */
|
/* RFC 1497 [17] */
|
||||||
static const uint8_t magic_cookie[4] = { 0x63, 0x82, 0x53, 0x63 };
|
static const u8_t magic_cookie[4] = { 0x63, 0x82, 0x53, 0x63 };
|
||||||
|
|
||||||
static void dhcpv4_timeout(struct k_work *work);
|
static void dhcpv4_timeout(struct k_work *work);
|
||||||
|
|
||||||
|
@ -162,8 +162,8 @@ static inline bool add_cookie(struct net_pkt *pkt)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add a an option with the form OPTION LENGTH VALUE. */
|
/* Add a an option with the form OPTION LENGTH VALUE. */
|
||||||
static bool add_option_length_value(struct net_pkt *pkt, uint8_t option,
|
static bool add_option_length_value(struct net_pkt *pkt, u8_t option,
|
||||||
uint8_t size, const uint8_t *value)
|
u8_t size, const u8_t *value)
|
||||||
{
|
{
|
||||||
if (!net_pkt_append_u8(pkt, option)) {
|
if (!net_pkt_append_u8(pkt, option)) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -181,7 +181,7 @@ static bool add_option_length_value(struct net_pkt *pkt, uint8_t option,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Add DHCPv4 message type */
|
/* Add DHCPv4 message type */
|
||||||
static bool add_msg_type(struct net_pkt *pkt, uint8_t type)
|
static bool add_msg_type(struct net_pkt *pkt, u8_t type)
|
||||||
{
|
{
|
||||||
return add_option_length_value(pkt, DHCPV4_OPTIONS_MSG_TYPE, 1, &type);
|
return add_option_length_value(pkt, DHCPV4_OPTIONS_MSG_TYPE, 1, &type);
|
||||||
}
|
}
|
||||||
|
@ -191,7 +191,7 @@ static bool add_msg_type(struct net_pkt *pkt, uint8_t type)
|
||||||
*/
|
*/
|
||||||
static bool add_req_options(struct net_pkt *pkt)
|
static bool add_req_options(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
static const uint8_t data[5] = { DHCPV4_OPTIONS_REQ_LIST,
|
static const u8_t data[5] = { DHCPV4_OPTIONS_REQ_LIST,
|
||||||
3, /* Length */
|
3, /* Length */
|
||||||
DHCPV4_OPTIONS_SUBNET_MASK,
|
DHCPV4_OPTIONS_SUBNET_MASK,
|
||||||
DHCPV4_OPTIONS_ROUTER,
|
DHCPV4_OPTIONS_ROUTER,
|
||||||
|
@ -221,7 +221,7 @@ static inline bool add_end(struct net_pkt *pkt)
|
||||||
/* File is empty ATM */
|
/* File is empty ATM */
|
||||||
static inline bool add_file(struct net_pkt *pkt)
|
static inline bool add_file(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
uint8_t len = SIZE_OF_FILE;
|
u8_t len = SIZE_OF_FILE;
|
||||||
|
|
||||||
while (len-- > 0) {
|
while (len-- > 0) {
|
||||||
if (!net_pkt_append_u8(pkt, 0)) {
|
if (!net_pkt_append_u8(pkt, 0)) {
|
||||||
|
@ -235,7 +235,7 @@ static inline bool add_file(struct net_pkt *pkt)
|
||||||
/* SNAME is empty ATM */
|
/* SNAME is empty ATM */
|
||||||
static inline bool add_sname(struct net_pkt *pkt)
|
static inline bool add_sname(struct net_pkt *pkt)
|
||||||
{
|
{
|
||||||
uint8_t len = SIZE_OF_SNAME;
|
u8_t len = SIZE_OF_SNAME;
|
||||||
|
|
||||||
while (len-- > 0) {
|
while (len-- > 0) {
|
||||||
if (!net_pkt_append_u8(pkt, 0)) {
|
if (!net_pkt_append_u8(pkt, 0)) {
|
||||||
|
@ -251,7 +251,7 @@ static void setup_header(struct net_pkt *pkt, const struct in_addr *server_addr)
|
||||||
{
|
{
|
||||||
struct net_ipv4_hdr *ipv4;
|
struct net_ipv4_hdr *ipv4;
|
||||||
struct net_udp_hdr *udp;
|
struct net_udp_hdr *udp;
|
||||||
uint16_t len;
|
u16_t len;
|
||||||
|
|
||||||
ipv4 = NET_IPV4_HDR(pkt);
|
ipv4 = NET_IPV4_HDR(pkt);
|
||||||
udp = NET_UDP_HDR(pkt);
|
udp = NET_UDP_HDR(pkt);
|
||||||
|
@ -265,7 +265,7 @@ static void setup_header(struct net_pkt *pkt, const struct in_addr *server_addr)
|
||||||
ipv4->ttl = 0xFF;
|
ipv4->ttl = 0xFF;
|
||||||
ipv4->proto = IPPROTO_UDP;
|
ipv4->proto = IPPROTO_UDP;
|
||||||
ipv4->len[0] = len >> 8;
|
ipv4->len[0] = len >> 8;
|
||||||
ipv4->len[1] = (uint8_t)len;
|
ipv4->len[1] = (u8_t)len;
|
||||||
ipv4->chksum = ~net_calc_chksum_ipv4(pkt);
|
ipv4->chksum = ~net_calc_chksum_ipv4(pkt);
|
||||||
|
|
||||||
net_ipaddr_copy(&ipv4->dst, server_addr);
|
net_ipaddr_copy(&ipv4->dst, server_addr);
|
||||||
|
@ -280,7 +280,7 @@ static void setup_header(struct net_pkt *pkt, const struct in_addr *server_addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Prepare initial DHCPv4 message and add options as per message type */
|
/* Prepare initial DHCPv4 message and add options as per message type */
|
||||||
static struct net_pkt *prepare_message(struct net_if *iface, uint8_t type,
|
static struct net_pkt *prepare_message(struct net_if *iface, u8_t type,
|
||||||
const struct in_addr *ciaddr)
|
const struct in_addr *ciaddr)
|
||||||
{
|
{
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
|
@ -346,7 +346,7 @@ fail:
|
||||||
static void send_request(struct net_if *iface)
|
static void send_request(struct net_if *iface)
|
||||||
{
|
{
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
uint32_t timeout;
|
u32_t timeout;
|
||||||
const struct in_addr *server_addr = net_ipv4_broadcast_address();
|
const struct in_addr *server_addr = net_ipv4_broadcast_address();
|
||||||
const struct in_addr *ciaddr = NULL;
|
const struct in_addr *ciaddr = NULL;
|
||||||
bool with_server_id = false;
|
bool with_server_id = false;
|
||||||
|
@ -450,7 +450,7 @@ fail:
|
||||||
static void send_discover(struct net_if *iface)
|
static void send_discover(struct net_if *iface)
|
||||||
{
|
{
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
uint32_t timeout;
|
u32_t timeout;
|
||||||
|
|
||||||
iface->dhcpv4.xid++;
|
iface->dhcpv4.xid++;
|
||||||
|
|
||||||
|
@ -576,8 +576,8 @@ static void dhcpv4_t2_timeout(struct k_work *work)
|
||||||
|
|
||||||
static void enter_bound(struct net_if *iface)
|
static void enter_bound(struct net_if *iface)
|
||||||
{
|
{
|
||||||
uint32_t renewal_time;
|
u32_t renewal_time;
|
||||||
uint32_t rebinding_time;
|
u32_t rebinding_time;
|
||||||
|
|
||||||
k_delayed_work_cancel(&iface->dhcpv4.timer);
|
k_delayed_work_cancel(&iface->dhcpv4.timer);
|
||||||
|
|
||||||
|
@ -664,16 +664,16 @@ static void dhcpv4_timeout(struct k_work *work)
|
||||||
*/
|
*/
|
||||||
static enum net_verdict parse_options(struct net_if *iface,
|
static enum net_verdict parse_options(struct net_if *iface,
|
||||||
struct net_buf *frag,
|
struct net_buf *frag,
|
||||||
uint16_t offset,
|
u16_t offset,
|
||||||
enum dhcpv4_msg_type *msg_type)
|
enum dhcpv4_msg_type *msg_type)
|
||||||
{
|
{
|
||||||
uint8_t cookie[4];
|
u8_t cookie[4];
|
||||||
uint8_t length;
|
u8_t length;
|
||||||
uint8_t type;
|
u8_t type;
|
||||||
uint16_t pos;
|
u16_t pos;
|
||||||
|
|
||||||
frag = net_frag_read(frag, offset, &pos, sizeof(magic_cookie),
|
frag = net_frag_read(frag, offset, &pos, sizeof(magic_cookie),
|
||||||
(uint8_t *)cookie);
|
(u8_t *)cookie);
|
||||||
if (!frag || memcmp(magic_cookie, cookie, sizeof(magic_cookie))) {
|
if (!frag || memcmp(magic_cookie, cookie, sizeof(magic_cookie))) {
|
||||||
|
|
||||||
NET_DBG("Incorrect magic cookie");
|
NET_DBG("Incorrect magic cookie");
|
||||||
|
@ -797,7 +797,7 @@ static enum net_verdict parse_options(struct net_if *iface,
|
||||||
net_sprint_ipv4_addr(&iface->dhcpv4.server_id));
|
net_sprint_ipv4_addr(&iface->dhcpv4.server_id));
|
||||||
break;
|
break;
|
||||||
case DHCPV4_OPTIONS_MSG_TYPE: {
|
case DHCPV4_OPTIONS_MSG_TYPE: {
|
||||||
uint8_t v;
|
u8_t v;
|
||||||
|
|
||||||
if (length != 1) {
|
if (length != 1) {
|
||||||
NET_DBG("options_msg_type, bad length");
|
NET_DBG("options_msg_type, bad length");
|
||||||
|
@ -925,8 +925,8 @@ static enum net_verdict net_dhcpv4_input(struct net_conn *conn,
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct net_if *iface;
|
struct net_if *iface;
|
||||||
enum dhcpv4_msg_type msg_type = 0;
|
enum dhcpv4_msg_type msg_type = 0;
|
||||||
uint8_t min;
|
u8_t min;
|
||||||
uint16_t pos;
|
u16_t pos;
|
||||||
|
|
||||||
if (!conn) {
|
if (!conn) {
|
||||||
NET_DBG("Invalid connection");
|
NET_DBG("Invalid connection");
|
||||||
|
@ -1006,8 +1006,8 @@ drop:
|
||||||
|
|
||||||
void net_dhcpv4_start(struct net_if *iface)
|
void net_dhcpv4_start(struct net_if *iface)
|
||||||
{
|
{
|
||||||
uint32_t timeout;
|
u32_t timeout;
|
||||||
uint32_t entropy;
|
u32_t entropy;
|
||||||
|
|
||||||
switch (iface->dhcpv4.state) {
|
switch (iface->dhcpv4.state) {
|
||||||
case NET_DHCPV4_DISABLED:
|
case NET_DHCPV4_DISABLED:
|
||||||
|
|
|
@ -71,9 +71,9 @@ static inline enum net_verdict handle_echo_request(struct net_pkt *pkt)
|
||||||
|
|
||||||
#define NET_ICMPV4_UNUSED_LEN 4
|
#define NET_ICMPV4_UNUSED_LEN 4
|
||||||
|
|
||||||
static inline void setup_ipv4_header(struct net_pkt *pkt, uint8_t extra_len,
|
static inline void setup_ipv4_header(struct net_pkt *pkt, u8_t extra_len,
|
||||||
uint8_t ttl, uint8_t icmp_type,
|
u8_t ttl, u8_t icmp_type,
|
||||||
uint8_t icmp_code)
|
u8_t icmp_code)
|
||||||
{
|
{
|
||||||
NET_IPV4_HDR(pkt)->vhl = 0x45;
|
NET_IPV4_HDR(pkt)->vhl = 0x45;
|
||||||
NET_IPV4_HDR(pkt)->tos = 0x00;
|
NET_IPV4_HDR(pkt)->tos = 0x00;
|
||||||
|
@ -100,8 +100,8 @@ static inline void setup_ipv4_header(struct net_pkt *pkt, uint8_t extra_len,
|
||||||
|
|
||||||
int net_icmpv4_send_echo_request(struct net_if *iface,
|
int net_icmpv4_send_echo_request(struct net_if *iface,
|
||||||
struct in_addr *dst,
|
struct in_addr *dst,
|
||||||
uint16_t identifier,
|
u16_t identifier,
|
||||||
uint16_t sequence)
|
u16_t sequence)
|
||||||
{
|
{
|
||||||
const struct in_addr *src;
|
const struct in_addr *src;
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
|
@ -164,7 +164,7 @@ int net_icmpv4_send_echo_request(struct net_if *iface,
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
int net_icmpv4_send_error(struct net_pkt *orig, uint8_t type, uint8_t code)
|
int net_icmpv4_send_error(struct net_pkt *orig, u8_t type, u8_t code)
|
||||||
{
|
{
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
|
@ -281,7 +281,7 @@ void net_icmpv4_unregister_handler(struct net_icmpv4_handler *handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum net_verdict net_icmpv4_input(struct net_pkt *pkt,
|
enum net_verdict net_icmpv4_input(struct net_pkt *pkt,
|
||||||
uint8_t type, uint8_t code)
|
u8_t type, u8_t code)
|
||||||
{
|
{
|
||||||
struct net_icmpv4_handler *cb;
|
struct net_icmpv4_handler *cb;
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,8 @@
|
||||||
#define NET_ICMPV4_DST_UNREACH_NO_PORT 3 /* Port unreachable */
|
#define NET_ICMPV4_DST_UNREACH_NO_PORT 3 /* Port unreachable */
|
||||||
|
|
||||||
struct net_icmpv4_echo_req {
|
struct net_icmpv4_echo_req {
|
||||||
uint16_t identifier;
|
u16_t identifier;
|
||||||
uint16_t sequence;
|
u16_t sequence;
|
||||||
} __packed;
|
} __packed;
|
||||||
|
|
||||||
#define NET_ICMPV4_ECHO_REQ(pkt) \
|
#define NET_ICMPV4_ECHO_REQ(pkt) \
|
||||||
|
@ -38,8 +38,8 @@ typedef enum net_verdict (*icmpv4_callback_handler_t)(struct net_pkt *pkt);
|
||||||
|
|
||||||
struct net_icmpv4_handler {
|
struct net_icmpv4_handler {
|
||||||
sys_snode_t node;
|
sys_snode_t node;
|
||||||
uint8_t type;
|
u8_t type;
|
||||||
uint8_t code;
|
u8_t code;
|
||||||
icmpv4_callback_handler_t handler;
|
icmpv4_callback_handler_t handler;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ struct net_icmpv4_handler {
|
||||||
* @param code Code of the type of the error message.
|
* @param code Code of the type of the error message.
|
||||||
* @return Return 0 if the sending succeed, <0 otherwise.
|
* @return Return 0 if the sending succeed, <0 otherwise.
|
||||||
*/
|
*/
|
||||||
int net_icmpv4_send_error(struct net_pkt *pkt, uint8_t type, uint8_t code);
|
int net_icmpv4_send_error(struct net_pkt *pkt, u8_t type, u8_t code);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Send ICMPv4 echo request message.
|
* @brief Send ICMPv4 echo request message.
|
||||||
|
@ -66,15 +66,15 @@ int net_icmpv4_send_error(struct net_pkt *pkt, uint8_t type, uint8_t code);
|
||||||
*/
|
*/
|
||||||
int net_icmpv4_send_echo_request(struct net_if *iface,
|
int net_icmpv4_send_echo_request(struct net_if *iface,
|
||||||
struct in_addr *dst,
|
struct in_addr *dst,
|
||||||
uint16_t identifier,
|
u16_t identifier,
|
||||||
uint16_t sequence);
|
u16_t sequence);
|
||||||
|
|
||||||
void net_icmpv4_register_handler(struct net_icmpv4_handler *handler);
|
void net_icmpv4_register_handler(struct net_icmpv4_handler *handler);
|
||||||
|
|
||||||
void net_icmpv4_unregister_handler(struct net_icmpv4_handler *handler);
|
void net_icmpv4_unregister_handler(struct net_icmpv4_handler *handler);
|
||||||
|
|
||||||
enum net_verdict net_icmpv4_input(struct net_pkt *pkt,
|
enum net_verdict net_icmpv4_input(struct net_pkt *pkt,
|
||||||
uint8_t type, uint8_t code);
|
u8_t type, u8_t code);
|
||||||
|
|
||||||
#if defined(CONFIG_NET_IPV4)
|
#if defined(CONFIG_NET_IPV4)
|
||||||
void net_icmpv4_init(void);
|
void net_icmpv4_init(void);
|
||||||
|
|
|
@ -74,9 +74,9 @@ void net_icmpv6_unregister_handler(struct net_icmpv6_handler *handler)
|
||||||
sys_slist_find_and_remove(&handlers, &handler->node);
|
sys_slist_find_and_remove(&handlers, &handler->node);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void setup_ipv6_header(struct net_pkt *pkt, uint16_t extra_len,
|
static inline void setup_ipv6_header(struct net_pkt *pkt, u16_t extra_len,
|
||||||
uint8_t hop_limit, uint8_t icmp_type,
|
u8_t hop_limit, u8_t icmp_type,
|
||||||
uint8_t icmp_code)
|
u8_t icmp_code)
|
||||||
{
|
{
|
||||||
NET_IPV6_HDR(pkt)->vtc = 0x60;
|
NET_IPV6_HDR(pkt)->vtc = 0x60;
|
||||||
NET_IPV6_HDR(pkt)->tcflow = 0;
|
NET_IPV6_HDR(pkt)->tcflow = 0;
|
||||||
|
@ -129,7 +129,7 @@ static enum net_verdict handle_echo_request(struct net_pkt *orig)
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
struct net_if *iface;
|
struct net_if *iface;
|
||||||
uint16_t payload_len;
|
u16_t payload_len;
|
||||||
|
|
||||||
echo_request_debug(orig);
|
echo_request_debug(orig);
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ static enum net_verdict handle_echo_request(struct net_pkt *orig)
|
||||||
|
|
||||||
if (NET_IPV6_HDR(pkt)->nexthdr == NET_IPV6_NEXTHDR_HBHO) {
|
if (NET_IPV6_HDR(pkt)->nexthdr == NET_IPV6_NEXTHDR_HBHO) {
|
||||||
#if defined(CONFIG_NET_RPL)
|
#if defined(CONFIG_NET_RPL)
|
||||||
uint16_t offset = NET_IPV6H_LEN;
|
u16_t offset = NET_IPV6H_LEN;
|
||||||
|
|
||||||
if (net_rpl_revert_header(pkt, offset, &offset) < 0) {
|
if (net_rpl_revert_header(pkt, offset, &offset) < 0) {
|
||||||
/* TODO: Handle error cases */
|
/* TODO: Handle error cases */
|
||||||
|
@ -229,8 +229,8 @@ drop_no_pkt:
|
||||||
return NET_DROP;
|
return NET_DROP;
|
||||||
}
|
}
|
||||||
|
|
||||||
int net_icmpv6_send_error(struct net_pkt *orig, uint8_t type, uint8_t code,
|
int net_icmpv6_send_error(struct net_pkt *orig, u8_t type, u8_t code,
|
||||||
uint32_t param)
|
u32_t param)
|
||||||
{
|
{
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
|
@ -354,8 +354,8 @@ drop_no_pkt:
|
||||||
|
|
||||||
int net_icmpv6_send_echo_request(struct net_if *iface,
|
int net_icmpv6_send_echo_request(struct net_if *iface,
|
||||||
struct in6_addr *dst,
|
struct in6_addr *dst,
|
||||||
uint16_t identifier,
|
u16_t identifier,
|
||||||
uint16_t sequence)
|
u16_t sequence)
|
||||||
{
|
{
|
||||||
const struct in6_addr *src;
|
const struct in6_addr *src;
|
||||||
struct net_pkt *pkt;
|
struct net_pkt *pkt;
|
||||||
|
@ -411,7 +411,7 @@ drop:
|
||||||
}
|
}
|
||||||
|
|
||||||
enum net_verdict net_icmpv6_input(struct net_pkt *pkt,
|
enum net_verdict net_icmpv6_input(struct net_pkt *pkt,
|
||||||
uint8_t type, uint8_t code)
|
u8_t type, u8_t code)
|
||||||
{
|
{
|
||||||
struct net_icmpv6_handler *cb;
|
struct net_icmpv6_handler *cb;
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue