2023-03-20 06:25:10 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "esp_ieee802154.h"
|
|
|
|
#include "esp_phy_init.h"
|
|
|
|
#include "esp_ieee802154_ack.h"
|
|
|
|
#include "esp_ieee802154_dev.h"
|
|
|
|
#include "esp_ieee802154_frame.h"
|
|
|
|
#include "esp_ieee802154_pib.h"
|
|
|
|
#include "esp_ieee802154_sec.h"
|
|
|
|
#include "esp_ieee802154_util.h"
|
|
|
|
#include "esp_log.h"
|
|
|
|
#include "esp_coex_i154.h"
|
|
|
|
#include "hal/ieee802154_ll.h"
|
2023-06-09 05:12:10 -04:00
|
|
|
#include "hal/ieee802154_common_ll.h"
|
2023-03-20 06:25:10 -04:00
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_enable(void)
|
|
|
|
{
|
|
|
|
ieee802154_enable();
|
|
|
|
esp_phy_enable();
|
|
|
|
esp_btbb_enable();
|
|
|
|
return ieee802154_mac_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_disable(void)
|
|
|
|
{
|
|
|
|
ieee802154_disable();
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t esp_ieee802154_get_channel(void)
|
|
|
|
{
|
|
|
|
return ieee802154_pib_get_channel();
|
|
|
|
}
|
|
|
|
|
2023-05-15 08:52:31 -04:00
|
|
|
esp_err_t esp_ieee802154_set_channel(uint8_t channel)
|
2023-03-20 06:25:10 -04:00
|
|
|
{
|
|
|
|
ieee802154_pib_set_channel(channel);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int8_t esp_ieee802154_get_txpower(void)
|
|
|
|
{
|
|
|
|
return ieee802154_pib_get_power();
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_txpower(int8_t power)
|
|
|
|
{
|
|
|
|
ieee802154_pib_set_power(power);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool esp_ieee802154_get_promiscuous(void)
|
|
|
|
{
|
|
|
|
return ieee802154_pib_get_promiscuous();
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_promiscuous(bool enable)
|
|
|
|
{
|
|
|
|
ieee802154_pib_set_promiscuous(enable);
|
|
|
|
ieee802154_pib_set_auto_ack_rx(!enable);
|
|
|
|
ieee802154_pib_set_auto_ack_tx(!enable);
|
|
|
|
ieee802154_pib_set_enhance_ack_tx(!enable);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int8_t esp_ieee802154_get_cca_threshold(void)
|
|
|
|
{
|
|
|
|
return ieee802154_pib_get_cca_threshold();
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_cca_threshold(int8_t cca_threshold)
|
|
|
|
{
|
|
|
|
ieee802154_pib_set_cca_threshold(cca_threshold);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_ieee802154_cca_mode_t esp_ieee802154_get_cca_mode(void)
|
|
|
|
{
|
|
|
|
return ieee802154_pib_get_cca_mode();
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_cca_mode(esp_ieee802154_cca_mode_t cca_mode)
|
|
|
|
{
|
|
|
|
ieee802154_pib_set_cca_mode(cca_mode);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool esp_ieee802154_get_auto_ack_tx(void)
|
|
|
|
{
|
|
|
|
return ieee802154_pib_get_auto_ack_tx();
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_auto_ack_tx(bool enable)
|
|
|
|
{
|
|
|
|
ieee802154_pib_set_auto_ack_tx(enable);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool esp_ieee802154_get_auto_ack_rx(void)
|
|
|
|
{
|
|
|
|
return ieee802154_pib_get_auto_ack_rx();
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_auto_ack_rx(bool enable)
|
|
|
|
{
|
|
|
|
ieee802154_pib_set_auto_ack_rx(enable);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool esp_ieee802154_get_coordinator(void)
|
|
|
|
{
|
|
|
|
return ieee802154_pib_get_coordinator();
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_coordinator(bool enable)
|
|
|
|
{
|
|
|
|
ieee802154_pib_set_coordinator(enable);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if CONFIG_IEEE802154_MULTI_PAN_ENABLE
|
|
|
|
|
|
|
|
uint16_t esp_ieee802154_get_multipan_panid(esp_ieee802154_multipan_index_t index)
|
|
|
|
{
|
|
|
|
assert(index < ESP_IEEE802154_MULTIPAN_MAX);
|
|
|
|
return ieee802154_ll_get_multipan_panid(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_multipan_panid(esp_ieee802154_multipan_index_t index, uint16_t panid)
|
|
|
|
{
|
|
|
|
assert(index < ESP_IEEE802154_MULTIPAN_MAX);
|
|
|
|
ieee802154_ll_set_multipan_panid(index, panid);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t esp_ieee802154_get_multipan_short_address(esp_ieee802154_multipan_index_t index)
|
|
|
|
{
|
|
|
|
assert(index < ESP_IEEE802154_MULTIPAN_MAX);
|
|
|
|
return ieee802154_ll_get_multipan_short_addr(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_multipan_short_address(esp_ieee802154_multipan_index_t index, uint16_t short_address)
|
|
|
|
{
|
|
|
|
assert(index < ESP_IEEE802154_MULTIPAN_MAX);
|
|
|
|
ieee802154_ll_set_multipan_short_addr(index, short_address);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_get_multipan_extended_address(esp_ieee802154_multipan_index_t index, uint8_t *ext_addr)
|
|
|
|
{
|
|
|
|
assert(index < ESP_IEEE802154_MULTIPAN_MAX);
|
|
|
|
ieee802154_ll_get_multipan_ext_addr(index, ext_addr);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_multipan_extended_address(esp_ieee802154_multipan_index_t index, const uint8_t *ext_addr)
|
|
|
|
{
|
|
|
|
assert(index < ESP_IEEE802154_MULTIPAN_MAX);
|
|
|
|
ieee802154_ll_set_multipan_ext_addr(index, ext_addr);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t esp_ieee802154_get_multipan_enable(void)
|
|
|
|
{
|
2023-06-09 05:12:10 -04:00
|
|
|
return ieee802154_ll_get_multipan_enable_mask();
|
2023-03-20 06:25:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_multipan_enable(uint8_t mask)
|
|
|
|
{
|
2023-06-09 05:12:10 -04:00
|
|
|
assert(mask < (1 << ESP_IEEE802154_MULTIPAN_MAX));
|
|
|
|
ieee802154_ll_set_multipan_enable_mask(mask);
|
2023-03-20 06:25:10 -04:00
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
uint16_t esp_ieee802154_get_panid(void)
|
|
|
|
{
|
|
|
|
return ieee802154_ll_get_multipan_panid(ESP_IEEE802154_MULTIPAN_0);
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_panid(uint16_t panid)
|
|
|
|
{
|
|
|
|
ieee802154_ll_set_multipan_panid(ESP_IEEE802154_MULTIPAN_0, panid);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t esp_ieee802154_get_short_address(void)
|
|
|
|
{
|
|
|
|
return ieee802154_ll_get_multipan_short_addr(ESP_IEEE802154_MULTIPAN_0);
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_short_address(uint16_t short_address)
|
|
|
|
{
|
|
|
|
ieee802154_ll_set_multipan_short_addr(ESP_IEEE802154_MULTIPAN_0, short_address);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_get_extended_address(uint8_t *ext_addr)
|
|
|
|
{
|
|
|
|
ieee802154_ll_get_multipan_ext_addr(ESP_IEEE802154_MULTIPAN_0, ext_addr);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_extended_address(const uint8_t *ext_addr)
|
|
|
|
{
|
|
|
|
ieee802154_ll_set_multipan_ext_addr(ESP_IEEE802154_MULTIPAN_0, ext_addr);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // CONFIG_IEEE802154_MULTI_PAN_ENABLE
|
|
|
|
|
|
|
|
esp_ieee802154_pending_mode_t esp_ieee802154_get_pending_mode(void)
|
|
|
|
{
|
|
|
|
return ieee802154_pib_get_pending_mode();
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_pending_mode(esp_ieee802154_pending_mode_t pending_mode)
|
|
|
|
{
|
|
|
|
ieee802154_pib_set_pending_mode(pending_mode);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_rx_when_idle(bool enable)
|
|
|
|
{
|
|
|
|
ieee802154_pib_set_rx_when_idle(enable);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool esp_ieee802154_get_rx_when_idle(void)
|
|
|
|
{
|
|
|
|
return ieee802154_pib_get_rx_when_idle();
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_transmit(const uint8_t *frame, bool cca)
|
|
|
|
{
|
|
|
|
return ieee802154_transmit(frame, cca);
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_transmit_at(const uint8_t *frame, bool cca, uint32_t time)
|
|
|
|
{
|
|
|
|
return ieee802154_transmit_at(frame, cca, time);
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_sleep(void)
|
|
|
|
{
|
|
|
|
return ieee802154_sleep();
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_receive(void)
|
|
|
|
{
|
|
|
|
return ieee802154_receive();
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_receive_at(uint32_t time)
|
|
|
|
{
|
|
|
|
return ieee802154_receive_at(time);
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_energy_detect(uint32_t duration)
|
|
|
|
{
|
|
|
|
return ieee802154_energy_detect(duration);
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_cca(void)
|
|
|
|
{
|
|
|
|
return ieee802154_cca();
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_ieee802154_state_t esp_ieee802154_get_state(void)
|
|
|
|
{
|
|
|
|
switch (ieee802154_get_state()) {
|
|
|
|
case IEEE802154_STATE_DISABLE:
|
|
|
|
return ESP_IEEE802154_RADIO_DISABLE;
|
|
|
|
|
|
|
|
case IEEE802154_STATE_IDLE:
|
2023-06-01 02:31:03 -04:00
|
|
|
return ESP_IEEE802154_RADIO_IDLE;
|
|
|
|
|
|
|
|
case IEEE802154_STATE_SLEEP:
|
2023-03-20 06:25:10 -04:00
|
|
|
return ESP_IEEE802154_RADIO_SLEEP;
|
|
|
|
|
|
|
|
case IEEE802154_STATE_RX:
|
|
|
|
case IEEE802154_STATE_TX_ACK:
|
|
|
|
case IEEE802154_STATE_ED:
|
|
|
|
return ESP_IEEE802154_RADIO_RECEIVE;
|
|
|
|
|
|
|
|
case IEEE802154_STATE_TX_CCA:
|
|
|
|
case IEEE802154_STATE_CCA:
|
|
|
|
case IEEE802154_STATE_TX:
|
|
|
|
case IEEE802154_STATE_RX_ACK:
|
|
|
|
return ESP_IEEE802154_RADIO_TRANSMIT;
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
return ESP_IEEE802154_RADIO_DISABLE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_set_transmit_security(uint8_t *frame, uint8_t *key, uint8_t *addr)
|
|
|
|
{
|
|
|
|
ieee802154_transmit_security_config(frame, key, addr);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_add_pending_addr(const uint8_t *addr, bool is_short)
|
|
|
|
{
|
|
|
|
return ieee802154_add_pending_addr(addr, is_short);
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_clear_pending_addr(const uint8_t *addr, bool is_short)
|
|
|
|
{
|
|
|
|
return ieee802154_clear_pending_addr(addr, is_short);
|
|
|
|
}
|
|
|
|
|
|
|
|
esp_err_t esp_ieee802154_reset_pending_table(bool is_short)
|
|
|
|
{
|
|
|
|
ieee802154_reset_pending_table(is_short);
|
|
|
|
return ESP_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int8_t esp_ieee802154_get_recent_rssi(void)
|
|
|
|
{
|
|
|
|
return ieee802154_get_recent_rssi();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t esp_ieee802154_get_recent_lqi(void)
|
|
|
|
{
|
|
|
|
return ieee802154_get_recent_lqi();
|
|
|
|
}
|
|
|
|
|
2023-06-01 02:31:03 -04:00
|
|
|
void esp_ieee802154_enter_sleep(void)
|
2023-05-25 06:18:03 -04:00
|
|
|
{
|
2023-06-01 02:31:03 -04:00
|
|
|
ieee802154_enter_sleep();
|
2023-05-25 06:18:03 -04:00
|
|
|
}
|
|
|
|
|
2023-06-01 02:31:03 -04:00
|
|
|
void esp_ieee802154_wakeup(void)
|
2023-05-25 06:18:03 -04:00
|
|
|
{
|
2023-06-01 02:31:03 -04:00
|
|
|
ieee802154_wakeup();
|
2023-05-25 06:18:03 -04:00
|
|
|
}
|
|
|
|
|
2023-03-20 06:25:10 -04:00
|
|
|
__attribute__((weak)) void esp_ieee802154_receive_done(uint8_t *data, esp_ieee802154_frame_info_t *frame_info)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((weak)) void esp_ieee802154_receive_sfd_done(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((weak)) void esp_ieee802154_receive_failed(uint16_t error)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((weak)) void esp_ieee802154_transmit_done(const uint8_t *frame, const uint8_t *ack, esp_ieee802154_frame_info_t *ack_frame_info)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((weak)) void esp_ieee802154_transmit_failed(const uint8_t *frame, esp_ieee802154_tx_error_t error)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((weak)) void esp_ieee802154_transmit_sfd_done(uint8_t *frame)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((weak)) void esp_ieee802154_cca_done(bool channel_free)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((weak)) void esp_ieee802154_energy_detect_done(int8_t power)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((weak)) void esp_ieee802154_ed_failed(uint16_t error)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
__attribute__((weak)) esp_err_t esp_ieee802154_enh_ack_generator(uint8_t *frame, esp_ieee802154_frame_info_t *frame_info, uint8_t* enhack_frame)
|
|
|
|
{
|
|
|
|
return ESP_OK;
|
|
|
|
}
|