57#define LOG_MODULE "TSCH Pkt"
58#define LOG_LEVEL LOG_LEVEL_MAC
71static struct packetbuf_attr eackbuf_attrs[PACKETBUF_NUM_ATTRS];
74#define IEEE802154_FRAME_PENDING_BIT_OFFSET 4
80 eackbuf_attrs[type].val = val;
88 return eackbuf_attrs[type].val;
94 const linkaddr_t *dest_addr, uint8_t seqno,
95 int16_t drift,
int nack)
98 struct ieee802154_ies ies;
111 memset(¶ms, 0,
sizeof(params));
112 memset(eackbuf_attrs, 0,
sizeof(eackbuf_attrs));
119#if TSCH_PACKET_EACK_WITH_DEST_ADDR
120 if(dest_addr != NULL) {
127#if TSCH_PACKET_EACK_WITH_SRC_ADDR
132#if LLSEC802154_ENABLED
139 memset(buf, 0, buf_len);
142 memset(&ies, 0,
sizeof(ies));
143 ies.ie_time_correction = drift;
144 ies.ie_is_nack = nack;
148 buf_len - hdr_len, &ies);
162 uint8_t seqno,
frame802154_t *frame,
struct ieee802154_ies *ies, uint8_t *hdr_len)
164 uint8_t curr_len = 0;
168 if(frame == NULL || buf_size < 0) {
175 if(hdr_len != NULL) {
181 if(seqno != frame->
seq) {
186 if(frame802154_check_dest_panid(frame) == 0) {
191 if(frame802154_extract_linkaddr(frame, NULL, &dest) == 0 ||
198 memset(ies, 0,
sizeof(
struct ieee802154_ies));
203#if LLSEC802154_ENABLED
206 if(buf_size < curr_len + mic_len) {
211 if((ret = frame802154e_parse_information_elements(buf + curr_len, buf_size - curr_len - mic_len, ies)) == -1) {
217 if(hdr_len != NULL) {
218 *hdr_len += ies->ie_payload_ie_offset;
228 struct ieee802154_ies ies;
231 const uint16_t payload_ie_hdr_len = 2;
236 memset(&ies, 0,
sizeof(ies));
239#if TSCH_PACKET_EB_WITH_TIMESLOT_TIMING
242 ies.ie_tsch_timeslot_id = 1;
243 for(i = 0; i < tsch_ts_elements_count; i++) {
244 ies.ie_tsch_timeslot[i] = RTIMERTICKS_TO_US(tsch_timing[i]);
250#if TSCH_PACKET_EB_WITH_HOPPING_SEQUENCE
251 if(tsch_hopping_sequence_length.val <=
sizeof(ies.ie_hopping_sequence_list)) {
252 ies.ie_channel_hopping_sequence_id = 1;
253 ies.ie_hopping_sequence_len = tsch_hopping_sequence_length.val;
254 memcpy(ies.ie_hopping_sequence_list, tsch_hopping_sequence,
255 ies.ie_hopping_sequence_len);
260#if TSCH_PACKET_EB_WITH_SLOTFRAME_AND_LINK
266 ies.ie_tsch_slotframe_and_link.num_slotframes = 1;
267 ies.ie_tsch_slotframe_and_link.slotframe_handle = sf0->handle;
268 ies.ie_tsch_slotframe_and_link.slotframe_size = sf0->size.val;
269 ies.ie_tsch_slotframe_and_link.num_links = 1;
270 ies.ie_tsch_slotframe_and_link.links[0].timeslot = link0->timeslot;
271 ies.ie_tsch_slotframe_and_link.links[0].channel_offset =
272 link0->channel_offset;
273 ies.ie_tsch_slotframe_and_link.links[0].link_options =
281 ie_len = frame80215e_create_ie_tsch_synchronization(p,
290 ie_len = frame80215e_create_ie_tsch_timeslot(p,
299 ie_len = frame80215e_create_ie_tsch_channel_hopping_sequence(p,
308 ie_len = frame80215e_create_ie_tsch_slotframe_and_link(p,
319 ie_len = frame80215e_create_ie_payload_list_termination(p,
344 ie_len = frame80215e_create_ie_header_list_termination_1(
packetbuf_hdrptr(),
351 packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, FRAME802154_BEACONFRAME);
352 packetbuf_set_attr(PACKETBUF_ATTR_MAC_METADATA, 1);
355 packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &tsch_eb_address);
357#if LLSEC802154_ENABLED
361 if(NETSTACK_FRAMER.create() < 0) {
365 if(hdr_len != NULL) {
374 if(tsch_sync_ie_offset != NULL) {
385 struct ieee802154_ies ies;
386 ies.ie_asn = tsch_current_asn;
387 ies.ie_join_priority = tsch_join_priority;
388 return frame80215e_create_ie_tsch_synchronization(buf+tsch_sync_ie_offset, buf_size-tsch_sync_ie_offset, &ies) != -1;
394 frame802154_t *frame,
struct ieee802154_ies *ies, uint8_t *hdr_len,
int frame_without_mic)
396 uint8_t curr_len = 0;
399 if(frame == NULL || buf_size < 0) {
405 LOG_ERR(
"! parse_eb: failed to parse frame\n");
411 LOG_INFO(
"! parse_eb: frame is not a TSCH beacon." \
412 " Frame version %u, type %u, FCF %02x %02x\n",
414 LOG_INFO(
"! parse_eb: frame was from 0x%x/", frame->
src_pid);
415 LOG_INFO_LLADDR((
const linkaddr_t *)&frame->
src_addr);
416 LOG_INFO_(
" to 0x%x/", frame->
dest_pid);
417 LOG_INFO_LLADDR((
const linkaddr_t *)&frame->
dest_addr);
422 if(hdr_len != NULL) {
428 memset(ies, 0,
sizeof(
struct ieee802154_ies));
429 ies->ie_join_priority = 0xff;
434#if LLSEC802154_ENABLED
435 if(!frame_without_mic) {
437 if(buf_size < curr_len + mic_len) {
444 if((ret = frame802154e_parse_information_elements(buf + curr_len, buf_size - curr_len - mic_len, ies)) == -1) {
445 LOG_ERR(
"! parse_eb: failed to parse IEs\n");
451 if(hdr_len != NULL) {
452 *hdr_len += ies->ie_payload_ie_offset;
462 buf[0] |= (1 << IEEE802154_FRAME_PENDING_BIT_OFFSET);
469 return (buf[0] >> IEEE802154_FRAME_PENDING_BIT_OFFSET) & 1;
802.15.4 frame creation and parsing functions
int frame80215e_create_ie_header_ack_nack_time_correction(uint8_t *buf, int len, const struct ieee802154_ies *ies)
Insert various Information Elements.
A MAC framer for IEEE 802.15.4.
int frame802154_parse(uint8_t *data, int len, frame802154_t *pf)
Parses an input frame.
int frame802154_create(frame802154_t *p, uint8_t *buf)
Creates a frame for transmission over the air.
int frame802154_hdrlen(frame802154_t *p)
Calculates the length of the frame header.
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a link-layer address.
bool linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two link-layer addresses.
const linkaddr_t linkaddr_null
The null link-layer address.
void packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
uint16_t packetbuf_totlen(void)
Get the total length of the header and data in the packetbuf.
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
uint8_t packetbuf_hdrlen(void)
Get the length of the header in the packetbuf.
void * packetbuf_hdrptr(void)
Get a pointer to the header in the packetbuf, for outbound packets.
void packetbuf_clear(void)
Clear and reset the packetbuf.
int packetbuf_hdralloc(int size)
Extend the header of the packetbuf, for outbound packets.
uint16_t packetbuf_remaininglen(void)
Get the total length of the remaining space in the packetbuf.
int tsch_packet_update_eb(uint8_t *buf, int buf_size, uint8_t tsch_sync_ie_offset)
Update ASN in EB packet.
struct tsch_slotframe * tsch_schedule_get_slotframe_by_handle(uint16_t handle)
Looks up a slotframe by handle.
int tsch_packet_parse_eb(const uint8_t *buf, int buf_size, frame802154_t *frame, struct ieee802154_ies *ies, uint8_t *hdr_len, int frame_without_mic)
Parse EB.
void tsch_security_set_packetbuf_attr(uint8_t frame_type)
Set packetbuf (or eackbuf) attributes depending on a given frame type.
int tsch_packet_parse_eack(const uint8_t *buf, int buf_size, uint8_t seqno, frame802154_t *frame, struct ieee802154_ies *ies, uint8_t *hdr_len)
Parse enhanced ACK packet.
int tsch_packet_create_eack(uint8_t *buf, uint16_t buf_len, const linkaddr_t *dest_addr, uint8_t seqno, int16_t drift, int nack)
Construct Enhanced ACK packet.
packetbuf_attr_t tsch_packet_eackbuf_attr(uint8_t type)
Return the value of a specified attribute.
int tsch_packet_get_frame_pending(uint8_t *buf, int buf_size)
Get frame pending bit from a packet.
unsigned int tsch_security_mic_len(const frame802154_t *frame)
Return MIC length.
struct tsch_link * tsch_schedule_get_link_by_offsets(struct tsch_slotframe *slotframe, uint16_t timeslot, uint16_t channel_offset)
Looks within a slotframe for a link with a given timeslot and channel offset.
int tsch_packet_create_eb(uint8_t *hdr_len, uint8_t *tsch_sync_ie_offset)
Create an EB packet directly in packetbuf.
void tsch_packet_eackbuf_set_attr(uint8_t type, const packetbuf_attr_t val)
Set a packet attribute for the current eack.
void tsch_packet_set_frame_pending(uint8_t *buf, int buf_size)
Set frame pending bit in a packet (whose header was already build).
Header file for the logging system.
Include file for the Contiki low-layer network stack (NETSTACK).
Header file for the Packet buffer (packetbuf) management.
uint8_t frame_version
2 bit.
uint8_t ie_list_present
1 bit.
Parameters used by the frame802154_create() function.
uint8_t seq
Sequence number.
uint8_t dest_addr[8]
Destination address.
uint8_t src_addr[8]
Source address.
uint16_t src_pid
Source PAN ID.
frame802154_fcf_t fcf
Frame control field.
uint16_t dest_pid
Destination PAN ID.
An IEEE 802.15.4-2015 TSCH link (also called cell or slot).
802.15.4e slotframe (contains links)
Main API declarations for TSCH.