57 #define LOG_MODULE "TSCH Pkt" 58 #define LOG_LEVEL LOG_LEVEL_MAC 71 static 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;
106 memset(eackbuf_attrs, 0,
sizeof(eackbuf_attrs));
113 #if TSCH_PACKET_EACK_WITH_DEST_ADDR 114 if(dest_addr != NULL) {
121 #if TSCH_PACKET_EACK_WITH_SRC_ADDR 126 #if LLSEC802154_ENABLED 133 memset(buf, 0, buf_len);
136 memset(&ies, 0,
sizeof(ies));
137 ies.ie_time_correction = drift;
138 ies.ie_is_nack = nack;
142 buf_len - hdr_len, &ies);
156 uint8_t seqno,
frame802154_t *frame,
struct ieee802154_ies *ies, uint8_t *hdr_len)
158 uint8_t curr_len = 0;
162 if(frame == NULL || buf_size < 0) {
169 if(hdr_len != NULL) {
175 if(seqno != frame->
seq) {
180 if(frame802154_check_dest_panid(frame) == 0) {
185 if(frame802154_extract_linkaddr(frame, NULL, &dest) == 0 ||
192 memset(ies, 0,
sizeof(
struct ieee802154_ies));
197 #if LLSEC802154_ENABLED 200 if(buf_size < curr_len + mic_len) {
205 if((ret = frame802154e_parse_information_elements(buf + curr_len, buf_size - curr_len - mic_len, ies)) == -1) {
211 if(hdr_len != NULL) {
212 *hdr_len += ies->ie_payload_ie_offset;
222 struct ieee802154_ies ies;
225 const uint16_t payload_ie_hdr_len = 2;
230 memset(&ies, 0,
sizeof(ies));
233 #if TSCH_PACKET_EB_WITH_TIMESLOT_TIMING 236 ies.ie_tsch_timeslot_id = 1;
237 for(i = 0; i < tsch_ts_elements_count; i++) {
238 ies.ie_tsch_timeslot[i] = RTIMERTICKS_TO_US(tsch_timing[i]);
244 #if TSCH_PACKET_EB_WITH_HOPPING_SEQUENCE 245 if(tsch_hopping_sequence_length.val <=
sizeof(ies.ie_hopping_sequence_list)) {
246 ies.ie_channel_hopping_sequence_id = 1;
247 ies.ie_hopping_sequence_len = tsch_hopping_sequence_length.val;
248 memcpy(ies.ie_hopping_sequence_list, tsch_hopping_sequence,
249 ies.ie_hopping_sequence_len);
254 #if TSCH_PACKET_EB_WITH_SLOTFRAME_AND_LINK 260 ies.ie_tsch_slotframe_and_link.num_slotframes = 1;
261 ies.ie_tsch_slotframe_and_link.slotframe_handle = sf0->handle;
262 ies.ie_tsch_slotframe_and_link.slotframe_size = sf0->size.val;
263 ies.ie_tsch_slotframe_and_link.num_links = 1;
264 ies.ie_tsch_slotframe_and_link.links[0].timeslot = link0->timeslot;
265 ies.ie_tsch_slotframe_and_link.links[0].channel_offset =
266 link0->channel_offset;
267 ies.ie_tsch_slotframe_and_link.links[0].link_options =
275 ie_len = frame80215e_create_ie_tsch_synchronization(p,
284 ie_len = frame80215e_create_ie_tsch_timeslot(p,
293 ie_len = frame80215e_create_ie_tsch_channel_hopping_sequence(p,
302 ie_len = frame80215e_create_ie_tsch_slotframe_and_link(p,
313 ie_len = frame80215e_create_ie_payload_list_termination(p,
338 ie_len = frame80215e_create_ie_header_list_termination_1(
packetbuf_hdrptr(),
345 packetbuf_set_attr(PACKETBUF_ATTR_FRAME_TYPE, FRAME802154_BEACONFRAME);
346 packetbuf_set_attr(PACKETBUF_ATTR_MAC_METADATA, 1);
349 packetbuf_set_addr(PACKETBUF_ADDR_RECEIVER, &tsch_eb_address);
351 #if LLSEC802154_ENABLED 355 if(NETSTACK_FRAMER.create() < 0) {
359 if(hdr_len != NULL) {
368 if(tsch_sync_ie_offset != NULL) {
379 struct ieee802154_ies ies;
380 ies.ie_asn = tsch_current_asn;
381 ies.ie_join_priority = tsch_join_priority;
382 return frame80215e_create_ie_tsch_synchronization(buf+tsch_sync_ie_offset, buf_size-tsch_sync_ie_offset, &ies) != -1;
388 frame802154_t *frame,
struct ieee802154_ies *ies, uint8_t *hdr_len,
int frame_without_mic)
390 uint8_t curr_len = 0;
393 if(frame == NULL || buf_size < 0) {
399 LOG_ERR(
"! parse_eb: failed to parse frame\n");
405 LOG_INFO(
"! parse_eb: frame is not a TSCH beacon." \
406 " Frame version %u, type %u, FCF %02x %02x\n",
408 LOG_INFO(
"! parse_eb: frame was from 0x%x/", frame->
src_pid);
409 LOG_INFO_LLADDR((
const linkaddr_t *)&frame->
src_addr);
410 LOG_INFO_(
" to 0x%x/", frame->
dest_pid);
411 LOG_INFO_LLADDR((
const linkaddr_t *)&frame->
dest_addr);
416 if(hdr_len != NULL) {
422 memset(ies, 0,
sizeof(
struct ieee802154_ies));
423 ies->ie_join_priority = 0xff;
428 #if LLSEC802154_ENABLED 429 if(!frame_without_mic) {
431 if(buf_size < curr_len + mic_len) {
438 if((ret = frame802154e_parse_information_elements(buf + curr_len, buf_size - curr_len - mic_len, ies)) == -1) {
439 LOG_ERR(
"! parse_eb: failed to parse IEs\n");
445 if(hdr_len != NULL) {
446 *hdr_len += ies->ie_payload_ie_offset;
456 buf[0] |= (1 << IEEE802154_FRAME_PENDING_BIT_OFFSET);
463 return (buf[0] >> IEEE802154_FRAME_PENDING_BIT_OFFSET) & 1;
uint16_t src_pid
Source PAN ID.
void * packetbuf_dataptr(void)
Get a pointer to the data in the packetbuf.
int tsch_packet_create_eb(uint8_t *hdr_len, uint8_t *tsch_sync_ie_offset)
Create an EB packet directly in packetbuf.
frame802154_fcf_t fcf
Frame control field.
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 frame802154_parse(uint8_t *data, int len, frame802154_t *pf)
Parses an input frame.
802.15.4e slotframe (contains links)
uint8_t packetbuf_hdrlen(void)
Get the length of the header in the packetbuf.
uint8_t src_addr[8]
Source address.
int frame802154_hdrlen(frame802154_t *p)
Calculates the length of the frame header.
A MAC framer for IEEE 802.15.4
const linkaddr_t linkaddr_null
The null link-layer address.
int tsch_packet_update_eb(uint8_t *buf, int buf_size, uint8_t tsch_sync_ie_offset)
Update ASN in EB packet.
uint16_t packetbuf_datalen(void)
Get the length of the data in the packetbuf.
linkaddr_t linkaddr_node_addr
The link-layer address of the node.
struct tsch_slotframe * tsch_schedule_get_slotframe_by_handle(uint16_t handle)
Looks up a slotframe by handle.
unsigned int tsch_security_mic_len(const frame802154_t *frame)
Return MIC length.
uint8_t frame_version
2 bit.
uint16_t packetbuf_totlen(void)
Get the total length of the header and data in the packetbuf.
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.
Main API declarations for TSCH.
void tsch_packet_eackbuf_set_attr(uint8_t type, const packetbuf_attr_t val)
Set a packet attribute for the current eack.
802.15.4 frame creation and parsing functions
void tsch_security_set_packetbuf_attr(uint8_t frame_type)
Set packetbuf (or eackbuf) attributes depending on a given frame type.
uint16_t dest_pid
Destination PAN ID.
Parameters used by the frame802154_create() function.
void linkaddr_copy(linkaddr_t *dest, const linkaddr_t *src)
Copy a link-layer address.
void tsch_packet_set_frame_pending(uint8_t *buf, int buf_size)
Set frame pending bit in a packet (whose header was already build)
int linkaddr_cmp(const linkaddr_t *addr1, const linkaddr_t *addr2)
Compare two link-layer addresses.
void * packetbuf_hdrptr(void)
Get a pointer to the header in the packetbuf, for outbound packets.
struct tsch_link * tsch_schedule_get_link_by_timeslot(struct tsch_slotframe *slotframe, uint16_t timeslot, uint16_t channel_offset)
Looks within a slotframe for a link with a given timeslot.
uint8_t ie_list_present
1 bit.
uint8_t seq
Sequence number.
int tsch_packet_get_frame_pending(uint8_t *buf, int buf_size)
Get frame pending bit from a packet.
An IEEE 802.15.4-2015 TSCH link (also called cell or slot)
Header file for the Packet buffer (packetbuf) management
Include file for the Contiki low-layer network stack (NETSTACK)
uint8_t dest_addr[8]
Destination address.
Header file for the logging system
packetbuf_attr_t tsch_packet_eackbuf_attr(uint8_t type)
Return the value of a specified attribute.
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 packetbuf_set_datalen(uint16_t len)
Set the length of the data in the packetbuf.
int frame80215e_create_ie_header_ack_nack_time_correction(uint8_t *buf, int len, struct ieee802154_ies *ies)
Insert various Information Elements.
int frame802154_create(frame802154_t *p, uint8_t *buf)
Creates a frame for transmission over the air.
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.