Lines Matching +full:enter +full:- +full:4 +full:byte +full:- +full:addr

1 /* ieee802154_nrf5.c - nRF5 802.15.4 driver */
4 * Copyright (c) 2017-2023 Nordic Semiconductor ASA
6 * SPDX-License-Identifier: Apache-2.0
77 #error "NRF_UICR->OTP is not supported to read from non-secure"
79 #define EUI64_ADDR (NRF_UICR->OTP)
82 #define EUI64_ADDR (NRF_UICR->CUSTOMER)
96 ((struct nrf5_802154_data * const)(dev)->data)
99 ((const struct nrf5_802154_config * const)(dev)->config)
124 /* Set the MAC Address Block Larger (MA-L) formerly called OUI. */ in nrf5_get_eui64()
130 /* Can't access SICR with device id on a radio core. Use BLE.ADDR. */ in nrf5_get_eui64()
131 deviceid[0] = NRF_FICR->BLE.ADDR[0]; in nrf5_get_eui64()
132 deviceid[1] = NRF_FICR->BLE.ADDR[1]; in nrf5_get_eui64()
147 memcpy(mac + index, &factoryAddress, sizeof(factoryAddress) - index); in nrf5_get_eui64()
167 rx_frame = k_fifo_get(&nrf5_radio->rx_fifo, K_FOREVER); in nrf5_rx_thread()
169 __ASSERT_NO_MSG(rx_frame->psdu); in nrf5_rx_thread()
176 pkt_len = rx_frame->psdu[0]; in nrf5_rx_thread()
178 pkt_len = rx_frame->psdu[0] - IEEE802154_FCS_LENGTH; in nrf5_rx_thread()
193 pkt = net_pkt_rx_alloc_with_buffer(nrf5_radio->iface, pkt_len, in nrf5_rx_thread()
196 if (net_pkt_write(pkt, rx_frame->psdu + 1, pkt_len)) { in nrf5_rx_thread()
200 net_pkt_set_ieee802154_lqi(pkt, rx_frame->lqi); in nrf5_rx_thread()
201 net_pkt_set_ieee802154_rssi_dbm(pkt, rx_frame->rssi); in nrf5_rx_thread()
202 net_pkt_set_ieee802154_ack_fpb(pkt, rx_frame->ack_fpb); in nrf5_rx_thread()
205 net_pkt_set_timestamp_ns(pkt, rx_frame->time * NSEC_PER_USEC); in nrf5_rx_thread()
209 net_pkt_set_ieee802154_ack_seb(pkt, rx_frame->ack_seb); in nrf5_rx_thread()
213 pkt_len, rx_frame->lqi); in nrf5_rx_thread()
215 if (net_recv_data(nrf5_radio->iface, pkt) < 0) { in nrf5_rx_thread()
220 psdu = rx_frame->psdu; in nrf5_rx_thread()
221 rx_frame->psdu = NULL; in nrf5_rx_thread()
225 log_stack_usage(&nrf5_radio->rx_thread); in nrf5_rx_thread()
231 psdu = rx_frame->psdu; in nrf5_rx_thread()
232 rx_frame->psdu = NULL; in nrf5_rx_thread()
281 return -EBUSY; in nrf5_cca()
287 k_sem_take(&nrf5_radio->cca_wait, K_FOREVER); in nrf5_cca()
289 LOG_DBG("Channel free? %d", nrf5_radio->channel_free); in nrf5_cca()
291 return nrf5_radio->channel_free ? 0 : -EBUSY; in nrf5_cca()
301 return channel < 11 ? -ENOTSUP : -EINVAL; in nrf5_set_channel()
322 err = -EBUSY; in nrf5_energy_scan_start()
325 err = -EALREADY; in nrf5_energy_scan_start()
365 ieee_addr[7], ieee_addr[6], ieee_addr[5], ieee_addr[4], in nrf5_set_ieee_addr()
380 return -ENOTSUP; in nrf5_filter()
384 return nrf5_set_ieee_addr(dev, filter->ieee_addr); in nrf5_filter()
386 return nrf5_set_short_addr(dev, filter->short_addr); in nrf5_filter()
388 return nrf5_set_pan_id(dev, filter->pan_id); in nrf5_filter()
391 return -ENOTSUP; in nrf5_filter()
412 if (nrf5_radio->ack_frame.time == NRF_802154_NO_TIMESTAMP) { in handle_ack()
417 err = -ENOMSG; in handle_ack()
423 ack_len = nrf5_radio->ack_frame.psdu[0]; in handle_ack()
425 ack_len = nrf5_radio->ack_frame.psdu[0] - IEEE802154_FCS_LENGTH; in handle_ack()
428 ack_pkt = net_pkt_rx_alloc_with_buffer(nrf5_radio->iface, ack_len, in handle_ack()
432 err = -ENOMEM; in handle_ack()
437 * PHY header (1 byte). in handle_ack()
439 if (net_pkt_write(ack_pkt, nrf5_radio->ack_frame.psdu + 1, in handle_ack()
442 err = -ENOMEM; in handle_ack()
446 net_pkt_set_ieee802154_lqi(ack_pkt, nrf5_radio->ack_frame.lqi); in handle_ack()
447 net_pkt_set_ieee802154_rssi_dbm(ack_pkt, nrf5_radio->ack_frame.rssi); in handle_ack()
450 net_pkt_set_timestamp_ns(ack_pkt, nrf5_radio->ack_frame.time * NSEC_PER_USEC); in handle_ack()
455 if (ieee802154_handle_ack(nrf5_radio->iface, ack_pkt) != NET_OK) { in handle_ack()
456 LOG_INF("ACK packet not handled - releasing."); in handle_ack()
463 nrf_802154_buffer_free_raw(nrf5_radio->ack_frame.psdu); in handle_ack()
464 nrf5_radio->ack_frame.psdu = NULL; in handle_ack()
579 uint8_t payload_len = frag->len; in nrf5_tx()
580 uint8_t *payload = frag->data; in nrf5_tx()
585 return -EMSGSIZE; in nrf5_tx()
590 nrf5_radio->tx_psdu[0] = payload_len + IEEE802154_FCS_LENGTH; in nrf5_tx()
591 memcpy(nrf5_radio->tx_psdu + 1, payload, payload_len); in nrf5_tx()
594 k_sem_reset(&nrf5_radio->tx_wait); in nrf5_tx()
599 ret = nrf5_tx_immediate(pkt, nrf5_radio->tx_psdu, in nrf5_tx()
604 ret = nrf5_tx_csma_ca(pkt, nrf5_radio->tx_psdu); in nrf5_tx()
614 ret = nrf5_tx_at(nrf5_radio, pkt, nrf5_radio->tx_psdu, mode); in nrf5_tx()
619 return -ENOTSUP; in nrf5_tx()
624 return -EIO; in nrf5_tx()
633 k_sem_take(&nrf5_radio->tx_wait, K_FOREVER); in nrf5_tx()
648 memcpy(payload, nrf5_radio->tx_psdu + 1, payload_len); in nrf5_tx()
650 net_pkt_set_ieee802154_frame_secured(pkt, nrf5_radio->tx_frame_is_secured); in nrf5_tx()
651 net_pkt_set_ieee802154_mac_hdr_rdy(pkt, nrf5_radio->tx_frame_mac_hdr_rdy); in nrf5_tx()
653 switch (nrf5_radio->tx_result) { in nrf5_tx()
655 if (nrf5_radio->ack_frame.psdu == NULL) { in nrf5_tx()
662 return -ENOBUFS; in nrf5_tx()
664 return -EBUSY; in nrf5_tx()
667 return -ENOMSG; in nrf5_tx()
672 return -EIO; in nrf5_tx()
697 LOG_ERR("Failed to enter receive state"); in nrf5_start()
698 return -EIO; in nrf5_start()
724 return -EIO; in nrf5_stop()
741 LOG_ERR("Failed to enter continuous carrier state"); in nrf5_continuous_carrier()
742 return -EIO; in nrf5_continuous_carrier()
758 LOG_ERR("Failed to enter modulated carrier state"); in nrf_modulated_carrier()
759 return -EIO; in nrf_modulated_carrier()
796 k_fifo_init(&nrf5_radio->rx_fifo); in nrf5_init()
797 k_sem_init(&nrf5_radio->tx_wait, 0, 1); in nrf5_init()
798 k_sem_init(&nrf5_radio->cca_wait, 0, 1); in nrf5_init()
804 nrf5_radio->rx_on_when_idle = true; in nrf5_init()
805 nrf5_radio_cfg->irq_config_func(dev); in nrf5_init()
807 k_thread_create(&nrf5_radio->rx_thread, nrf5_radio->rx_stack, in nrf5_init()
812 k_thread_name_set(&nrf5_radio->rx_thread, "nrf5_rx"); in nrf5_init()
824 nrf5_get_eui64(nrf5_radio->mac); in nrf5_iface_init()
825 net_if_set_link_addr(iface, nrf5_radio->mac, sizeof(nrf5_radio->mac), in nrf5_iface_init()
828 nrf5_radio->iface = iface; in nrf5_iface_init()
838 for (uint8_t i = 0; mac_keys->key_value in nrf5_config_mac_keys()
841 .value.p_cleartext_key = mac_keys->key_value, in nrf5_config_mac_keys()
842 .id.mode = mac_keys->key_id_mode, in nrf5_config_mac_keys()
843 .id.p_key_id = mac_keys->key_id, in nrf5_config_mac_keys()
846 .use_global_frame_counter = !(mac_keys->frame_counter_per_key), in nrf5_config_mac_keys()
866 if (config->auto_ack_fpb.enabled) { in nrf5_configure()
867 switch (config->auto_ack_fpb.mode) { in nrf5_configure()
879 return -EINVAL; in nrf5_configure()
883 nrf_802154_auto_pending_bit_set(config->auto_ack_fpb.enabled); in nrf5_configure()
887 if (config->ack_fpb.enabled) { in nrf5_configure()
889 config->ack_fpb.addr, in nrf5_configure()
890 config->ack_fpb.extended)) { in nrf5_configure()
891 return -ENOMEM; in nrf5_configure()
897 if (config->ack_fpb.addr != NULL) { in nrf5_configure()
899 config->ack_fpb.addr, in nrf5_configure()
900 config->ack_fpb.extended)) { in nrf5_configure()
901 return -ENOENT; in nrf5_configure()
905 config->ack_fpb.extended); in nrf5_configure()
911 nrf_802154_pan_coord_set(config->pan_coordinator); in nrf5_configure()
915 nrf_802154_promiscuous_set(config->promiscuous); in nrf5_configure()
919 nrf5_data.event_handler = config->event_handler; in nrf5_configure()
924 nrf5_config_mac_keys(config->mac_keys); in nrf5_configure()
928 nrf_802154_security_global_frame_counter_set(config->frame_counter); in nrf5_configure()
932 nrf_802154_security_global_frame_counter_set_if_larger(config->frame_counter); in nrf5_configure()
942 if (config->ack_ie.purge_ie) { in nrf5_configure()
948 if (config->ack_ie.short_addr == IEEE802154_BROADCAST_ADDRESS || in nrf5_configure()
949 config->ack_ie.ext_addr == NULL) { in nrf5_configure()
950 return -ENOTSUP; in nrf5_configure()
953 sys_put_le16(config->ack_ie.short_addr, short_addr_le); in nrf5_configure()
954 sys_memcpy_swap(ext_addr_le, config->ack_ie.ext_addr, EXTENDED_ADDRESS_SIZE); in nrf5_configure()
956 if (config->ack_ie.header_ie == NULL || config->ack_ie.header_ie->length == 0) { in nrf5_configure()
957 if (config->ack_ie.short_addr != IEEE802154_NO_SHORT_ADDRESS_ASSIGNED) { in nrf5_configure()
963 element_id = ieee802154_header_ie_get_element_id(config->ack_ie.header_ie); in nrf5_configure()
970 memcmp(config->ack_ie.header_ie->content.vendor_specific.vendor_oui, in nrf5_configure()
978 return -ENOTSUP; in nrf5_configure()
981 if (config->ack_ie.short_addr != IEEE802154_NO_SHORT_ADDRESS_ASSIGNED) { in nrf5_configure()
983 short_addr_le, false, config->ack_ie.header_ie, in nrf5_configure()
984 config->ack_ie.header_ie->length + in nrf5_configure()
988 nrf_802154_ack_data_set(ext_addr_le, true, config->ack_ie.header_ie, in nrf5_configure()
989 config->ack_ie.header_ie->length + in nrf5_configure()
1000 bool changed = (config->expected_rx_time - nrf5_data.csl_rx_time) % period_ns; in nrf5_configure()
1002 nrf5_data.csl_rx_time = config->expected_rx_time; in nrf5_configure()
1008 nrf_802154_timestamp_phr_to_mhr_convert(config->expected_rx_time / in nrf5_configure()
1021 nrf_802154_receive_at(config->rx_slot.start / NSEC_PER_USEC, in nrf5_configure()
1022 config->rx_slot.duration / NSEC_PER_USEC, in nrf5_configure()
1023 config->rx_slot.channel, DRX_SLOT_RX); in nrf5_configure()
1027 nrf_802154_csl_writer_period_set(config->csl_period); in nrf5_configure()
1029 nrf5_data.csl_period = config->csl_period; in nrf5_configure()
1038 ->max_extra_cca_attempts; in nrf5_configure()
1043 nrf_802154_rx_on_when_idle_set(config->rx_on_when_idle); in nrf5_configure()
1044 nrf5_data.rx_on_when_idle = config->rx_on_when_idle; in nrf5_configure()
1046 if (config->rx_on_when_idle == false) { in nrf5_configure()
1053 nrf_802154_cst_writer_period_set(config->cst_period); in nrf5_configure()
1058 config->expected_tx_time / NSEC_PER_USEC)); in nrf5_configure()
1063 return -EINVAL; in nrf5_configure()
1069 /* driver-allocated attribute memory - constant across all driver instances */
1087 * nRF 802.15.4 Radio Driver. in nrf5_attr_get()
1090 ((struct ieee802154_openthread_attr_value *)value)->t_recca = 0; in nrf5_attr_get()
1093 ((struct ieee802154_openthread_attr_value *)value)->t_ccatx = 20; in nrf5_attr_get()
1097 return -ENOENT; in nrf5_attr_get()
1197 nrf5_data.tx_frame_is_secured = metadata->frame_props.is_secured; in nrf_802154_transmitted_raw()
1198 nrf5_data.tx_frame_mac_hdr_rdy = metadata->frame_props.dynamic_data_is_set; in nrf_802154_transmitted_raw()
1199 nrf5_data.ack_frame.psdu = metadata->data.transmitted.p_ack; in nrf_802154_transmitted_raw()
1202 nrf5_data.ack_frame.rssi = metadata->data.transmitted.power; in nrf_802154_transmitted_raw()
1203 nrf5_data.ack_frame.lqi = metadata->data.transmitted.lqi; in nrf_802154_transmitted_raw()
1206 if (metadata->data.transmitted.time == NRF_802154_NO_TIMESTAMP) { in nrf_802154_transmitted_raw()
1212 metadata->data.transmitted.time, nrf5_data.ack_frame.psdu[0]); in nrf_802154_transmitted_raw()
1227 nrf5_data.tx_frame_is_secured = metadata->frame_props.is_secured; in nrf_802154_transmit_failed()
1228 nrf5_data.tx_frame_mac_hdr_rdy = metadata->frame_props.dynamic_data_is_set; in nrf_802154_transmit_failed()
1255 callback(nrf5_get_device(), result->ed_dbm); in nrf_802154_energy_detected()
1272 __ASSERT(false, "802.15.4 serialization error: %d", err->reason); in nrf_802154_serialization_error()